Add greeks to mview
This commit is contained in:
1 parent
f8276adaa7
commit
dfa18c632e
8 files changed
+146
-23
No files matched your search
@@ -0,0 +1,61 @@
|
||||
namespace mbts.analytics {
|
||||
using System;
|
||||
|
||||
readonly struct GreeksTuple : IEquatable<GreeksTuple> {
|
||||
public GreeksTuple(double theo, double delta, double gamma, double vega, double theta, double rho) {
|
||||
this.theo = theo;
|
||||
this.delta = delta;
|
||||
this.gamma = gamma;
|
||||
this.vega = vega;
|
||||
this.theta = theta;
|
||||
this.rho = rho;
|
||||
}
|
||||
|
||||
public static GreeksTuple empty => new(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN);
|
||||
|
||||
public double theo { get; }
|
||||
public double delta { get; }
|
||||
public double gamma { get; }
|
||||
public double vega { get; }
|
||||
public double theta { get; }
|
||||
public double rho { get; }
|
||||
|
||||
public bool Equals(GreeksTuple other) =>
|
||||
theo.Equals(other.theo) &&
|
||||
delta.Equals(other.delta) &&
|
||||
gamma.Equals(other.gamma) &&
|
||||
vega.Equals(other.vega) &&
|
||||
theta.Equals(other.theta) &&
|
||||
rho.Equals(other.rho);
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
obj is GreeksTuple gt && Equals(gt);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
HashCode.Combine(theo, delta, gamma, vega, theta, rho);
|
||||
|
||||
public override string ToString() =>
|
||||
$"theo: {theo}; delta: {delta}; gamma: {gamma}; vega: {vega}; theta: {theta}; rho: {rho}";
|
||||
|
||||
public static bool operator ==(GreeksTuple a, GreeksTuple b) => a.Equals(b);
|
||||
public static bool operator !=(GreeksTuple a, GreeksTuple b) => !a.Equals(b);
|
||||
}
|
||||
|
||||
static class GreeksTupleExtensions {
|
||||
public static GreeksTuple with(
|
||||
this GreeksTuple greeks_tuple,
|
||||
double theo = double.NaN,
|
||||
double delta = double.NaN,
|
||||
double gamma = double.NaN,
|
||||
double vega = double.NaN,
|
||||
double theta = double.NaN,
|
||||
double rho = double.NaN) =>
|
||||
new(
|
||||
theo.if_nan(greeks_tuple.theo),
|
||||
delta.if_nan(greeks_tuple.delta),
|
||||
gamma.if_nan(greeks_tuple.gamma),
|
||||
vega.if_nan(greeks_tuple.vega),
|
||||
theta.if_nan(greeks_tuple.theta),
|
||||
rho.if_nan(greeks_tuple.rho));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,27 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.collections;
|
||||
using bts.utils;
|
||||
namespace mbts.spark {
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.collections;
|
||||
using bts.utils;
|
||||
|
||||
using mbts.co2;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using mbts.analytics;
|
||||
using mbts.co2;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class MarketViewVM {
|
||||
public class Row : DisposableViewModelBase, ISecurityMDRow, IEquatable<Row>, DIYGrid.IRowVM, DIYGrid.IActionableRowVM {
|
||||
readonly IBus _bus;
|
||||
@@ -49,6 +50,7 @@ namespace mbts.spark {
|
||||
ulong _bbo_ref, _last_ref;
|
||||
uint? _display_qty_divisor_backing;
|
||||
bool _is_visible;
|
||||
GreeksTuple _greeks = GreeksTuple.empty;
|
||||
|
||||
public Row(IBus bus, SecurityMD smd, OrdersModel orders_model) {
|
||||
_bus = bus;
|
||||
@@ -215,6 +217,20 @@ namespace mbts.spark {
|
||||
public string hub_alias => security.hub_alias();
|
||||
public string strip_name => security.strip_name();
|
||||
public string mic_code => security.mic_code();
|
||||
|
||||
// greeks
|
||||
public GreeksTuple greeks {
|
||||
get => _greeks;
|
||||
set => Set(ref _greeks, value, nameof(greeks),
|
||||
nameof(theo), nameof(delta), nameof(gamma), nameof(vega), nameof(theta), nameof(rho));
|
||||
}
|
||||
public double theo => _greeks.theo;
|
||||
public double delta => _greeks.delta;
|
||||
public double gamma => _greeks.gamma;
|
||||
public double vega => _greeks.vega;
|
||||
public double theta => _greeks.theta;
|
||||
public double rho => _greeks.rho;
|
||||
|
||||
// animations
|
||||
public IList<ui.spark.CellAnimation> animations => _animation.get_animations().ToList();
|
||||
public ObservableCollection<RowAnimation> row_animations { get; } = new ObservableCollection<RowAnimation>();
|
||||
|
||||
@@ -158,6 +158,14 @@ namespace mbts.spark {
|
||||
add_col(Columns.StripName, "Strip Name", r => r.security.strip_name(), nameof(Row.strip_name), DefaultColumnWidths.SecurityKey, strip_name_filter, DataGridFilterKnownTemplates.Regex);
|
||||
add_col(Columns.MicCode, "Mic Code", r => r.security.mic_code(), nameof(Row.mic_code), DefaultColumnWidths.SecurityKey, mic_code_filter, DataGridFilterKnownTemplates.Regex);
|
||||
|
||||
// greeks
|
||||
add_col(Columns.Theo, "Theo", r => r.theo.is_nan() ? string.Empty : r.theo.ToString("0.00"), nameof(Row.theo), DefaultColumnWidths.Greeks, theo_filter, DataGridFilterKnownTemplates.DoubleMinMax);
|
||||
add_col(Columns.Delta, "Delta", r => r.delta.is_nan() ? string.Empty : r.delta.ToString("0.00"), nameof(Row.delta), DefaultColumnWidths.Greeks, delta_filter, DataGridFilterKnownTemplates.DoubleMinMax);
|
||||
add_col(Columns.Gamma, "Gamma", r => r.gamma.is_nan() ? string.Empty : r.gamma.ToString("0.00"), nameof(Row.gamma), DefaultColumnWidths.Greeks, gamma_filter, DataGridFilterKnownTemplates.DoubleMinMax);
|
||||
add_col(Columns.Vega, "Vega", r => r.vega.is_nan() ? string.Empty : r.vega.ToString("0.00"), nameof(Row.vega), DefaultColumnWidths.Greeks, vega_filter, DataGridFilterKnownTemplates.DoubleMinMax);
|
||||
add_col(Columns.Theta, "Theta", r => r.theta.is_nan() ? string.Empty : r.theta.ToString("0.00"), nameof(Row.theta), DefaultColumnWidths.Greeks, theta_filter, DataGridFilterKnownTemplates.DoubleMinMax);
|
||||
add_col(Columns.Rho, "Rho", r => r.rho.is_nan() ? string.Empty : r.rho.ToString("0.00"), nameof(Row.rho), DefaultColumnWidths.Greeks, rho_filter, DataGridFilterKnownTemplates.DoubleMinMax);
|
||||
|
||||
// row vm filter
|
||||
// Althoguh securities are filtered at the row 'model' level (SecurityMD), the column base filters have to be applied at the row vm level,
|
||||
// because they access market data, which is polled periodically and cached in the row vm.
|
||||
@@ -180,6 +188,13 @@ namespace mbts.spark {
|
||||
}),
|
||||
security_mds_source.Subscribe(_on_securities),
|
||||
ObservableAutoWrapper.connect_item_hooks(_rows, r => r, true),
|
||||
bus.subscribe(SparkTags.Greeks).OnDispatcher().Subscribe(greeks => {
|
||||
foreach (var r in rows) {
|
||||
if (greeks.TryGetValue(r.security_key, out var g)) {
|
||||
r.greeks = g;
|
||||
}
|
||||
}
|
||||
}),
|
||||
WorkLoop.Start("MarketView", _refresh));
|
||||
|
||||
// local functions
|
||||
@@ -368,7 +383,7 @@ namespace mbts.spark {
|
||||
public IDataGridColumnPersistentFilter<Row, IntMinMaxState> working_ask_volume_filter { get; } = new IntMinMax<Row>(r => r.working_ask_volume, nameof(Row.working_ask_volume));
|
||||
public IDataGridColumnPersistentFilter<Row, ULongMinMaxState> volume_filter { get; } = new ULongMinMax<Row>(r => r.volume, nameof(Row.volume));
|
||||
public IDataGridColumnPersistentFilter<Row, string> security_key_filter { get; } = new RegexFilterVM<Row>(r => r.security_key.ToString(), nameof(Row.security_key));
|
||||
|
||||
|
||||
public IDataGridColumnPersistentFilter<Row, string> market_description_filter { get; } = new RegexFilterVM<Row>(r => r.security.HasIce ? r.security.Ice.MarketDescription : "", nameof(Row.market_description));
|
||||
public IDataGridColumnPersistentFilter<Row, string> cleared_alias_filter { get; } = new RegexFilterVM<Row>(r => r.security.HasIce ? r.security.Ice.ClearedAlias : "", nameof(Row.cleared_alias));
|
||||
public IDataGridColumnPersistentFilter<Row, string> product_description_filter { get; } = new RegexFilterVM<Row>(r => r.security.HasIce ? r.security.Ice.ProductName : "", nameof(Row.product_description));
|
||||
@@ -376,6 +391,13 @@ namespace mbts.spark {
|
||||
public IDataGridColumnPersistentFilter<Row, string> strip_name_filter { get; } = new RegexFilterVM<Row>(r => r.security.HasIce ? r.security.Ice.StripName : "", nameof(Row.strip_name));
|
||||
public IDataGridColumnPersistentFilter<Row, string> mic_code_filter { get; } = new RegexFilterVM<Row>(r => r.security.HasIce ? r.security.Ice.MicCode : "", nameof(Row.mic_code));
|
||||
|
||||
public IDataGridColumnPersistentFilter<Row, DoubleMinMaxState> theo_filter { get; } = new DoubleMinMax<Row>(r => r.theo, nameof(Row.theo));
|
||||
public IDataGridColumnPersistentFilter<Row, DoubleMinMaxState> delta_filter { get; } = new DoubleMinMax<Row>(r => r.delta, nameof(Row.delta));
|
||||
public IDataGridColumnPersistentFilter<Row, DoubleMinMaxState> vega_filter { get; } = new DoubleMinMax<Row>(r => r.vega, nameof(Row.vega));
|
||||
public IDataGridColumnPersistentFilter<Row, DoubleMinMaxState> gamma_filter { get; } = new DoubleMinMax<Row>(r => r.gamma, nameof(Row.gamma));
|
||||
public IDataGridColumnPersistentFilter<Row, DoubleMinMaxState> theta_filter { get; } = new DoubleMinMax<Row>(r => r.theta, nameof(Row.theta));
|
||||
public IDataGridColumnPersistentFilter<Row, DoubleMinMaxState> rho_filter { get; } = new DoubleMinMax<Row>(r => r.rho, nameof(Row.rho));
|
||||
|
||||
IEnumerable<IDataGridColumnFilter<Row>> _all_filters =>
|
||||
_filter_getters.Select(g => g(this));
|
||||
|
||||
|
||||
@@ -61,7 +61,13 @@ namespace mbts.ui.spark {
|
||||
ProductDescription,
|
||||
HubAlias,
|
||||
StripName,
|
||||
MicCode
|
||||
MicCode,
|
||||
Theo,
|
||||
Delta,
|
||||
Gamma,
|
||||
Vega,
|
||||
Theta,
|
||||
Rho
|
||||
}
|
||||
|
||||
public static ExecutedRoutedEventHandler
|
||||
|
||||
@@ -147,7 +147,12 @@ namespace bts.shell {
|
||||
public static GridColumnSettings strip_name => new GridColumnSettings(col_id(Columns.StripName), DefaultColumnHeaders.StripName, is_visible: false, width: DefaultColumnWidths.SecurityKey);
|
||||
public static GridColumnSettings mic_code => new GridColumnSettings(col_id(Columns.MicCode), DefaultColumnHeaders.MicCode, is_visible: false, width: DefaultColumnWidths.SecurityKey);
|
||||
|
||||
|
||||
public static GridColumnSettings theo => new(col_id(Columns.Theo), "Theo", is_visible: false, width: DefaultColumnWidths.Greeks);
|
||||
public static GridColumnSettings delta => new(col_id(Columns.Delta), "Delta", is_visible: false, width: DefaultColumnWidths.Greeks);
|
||||
public static GridColumnSettings gamma => new(col_id(Columns.Gamma), "Gamma", is_visible: false, width: DefaultColumnWidths.Greeks);
|
||||
public static GridColumnSettings vega => new(col_id(Columns.Vega), "Vega", is_visible: false, width: DefaultColumnWidths.Greeks);
|
||||
public static GridColumnSettings theta => new(col_id(Columns.Theta), "Theta", is_visible: false, width: DefaultColumnWidths.Greeks);
|
||||
public static GridColumnSettings rho => new(col_id(Columns.Rho), "Rho", is_visible: false, width: DefaultColumnWidths.Greeks);
|
||||
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criterion {
|
||||
get {
|
||||
@@ -185,6 +190,12 @@ namespace bts.shell {
|
||||
yield return hub_alias;
|
||||
yield return strip_name;
|
||||
yield return mic_code;
|
||||
yield return theo;
|
||||
yield return delta;
|
||||
yield return gamma;
|
||||
yield return vega;
|
||||
yield return theta;
|
||||
yield return rho;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -306,6 +306,9 @@ namespace mbts.spark {
|
||||
|
||||
public static ITag<AnalyticsExpirationParametersSettings> show_analytics_exp_params { get; } =
|
||||
new SparkTag<AnalyticsExpirationParametersSettings>("Show Analytics Exp Params");
|
||||
|
||||
public static ITag<IReadOnlyDictionary<uint, GreeksTuple>> Greeks { get; } =
|
||||
new SparkTag<IReadOnlyDictionary<uint, GreeksTuple>>("Greeks");
|
||||
#endregion
|
||||
|
||||
public static ITag<IImmutableSet<uint>> SyntheticDeleteTag { get; } = new SparkTag<IImmutableSet<uint>>(nameof(SyntheticDeleteTag));
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace mbts.ui.controls {
|
||||
AveragePrice = 76,
|
||||
LastPrice = 78,
|
||||
Settlement = 82,
|
||||
Greeks = 56,
|
||||
Security = 80,
|
||||
SecurityKey = 90,
|
||||
SecurityType = 96,
|
||||
|
||||
@@ -18,6 +18,9 @@ namespace mbts {
|
||||
public static bool is_nan(this double value) =>
|
||||
double.IsNaN(value);
|
||||
|
||||
public static double if_nan(this double d, double if_nan) =>
|
||||
d.is_nan() ? if_nan : d;
|
||||
|
||||
/// <summary>
|
||||
/// If the specified value is a <see cref="double"/>, <see cref="int"/>, or <see cref="uint"/>, returns the equivalent <see cref="double"/>; otherwise, returns <see cref="double.NaN"/>.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user