Add venue to VolSurface(DisplayGrid)Expiration
So we can handle symbol/exp date conflicts for securities that differ only by venue (exchange)
This commit is contained in:
1 parent
583ae65fb2
commit
7044355547
17 files changed
+108
-52
No files matched your search
@@ -133,10 +133,10 @@
|
||||
vs_output.aux_data_map != null &&
|
||||
sel_exp != null && sel_exp.Item1 != null) {
|
||||
var impliedvol_side = _get_market_impliedvol_side(_bb, _vs_id);
|
||||
VolSurfaceExpiration orig_exp = new VolSurfaceExpiration() {
|
||||
symbol = sel_exp.Item1.symbol,
|
||||
expiration = sel_exp.Item1.expiration
|
||||
};
|
||||
var orig_exp = VolSurfaceExpiration.Default.with(
|
||||
symbol: sel_exp.Item1.symbol,
|
||||
expiration: sel_exp.Item1.expiration,
|
||||
venue: sel_exp.Item1.venue);
|
||||
var timer = Stopwatch.StartNew();
|
||||
VolSurfaceExpiration md_exp;
|
||||
VolCurveMarketImpliedVolData exp_impl_vol_map =
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
namespace mbts.spark {
|
||||
using bts.api;
|
||||
using bts.utils;
|
||||
|
||||
using System;
|
||||
|
||||
public class VolSurfaceDisplayGridExpiration : IComparable<VolSurfaceDisplayGridExpiration>, IEquatable<VolSurfaceDisplayGridExpiration> {
|
||||
public VolSurfaceDisplayGridExpiration(string symbol, DateTime expiration, analytics.VolSurfaceEnums.VolSurfaceExpirationCalculationMethod calc_mode) {
|
||||
public VolSurfaceDisplayGridExpiration(string symbol, DateTime expiration, Venue venue, analytics.VolSurfaceEnums.VolSurfaceExpirationCalculationMethod calc_mode) {
|
||||
this.symbol = symbol;
|
||||
this.expiration = expiration;
|
||||
this.venue = venue;
|
||||
this.calc_mode = calc_mode;
|
||||
}
|
||||
|
||||
public string symbol { get; }
|
||||
public DateTime expiration { get; }
|
||||
public Venue venue { get; }
|
||||
public analytics.VolSurfaceEnums.VolSurfaceExpirationCalculationMethod calc_mode { get; }
|
||||
|
||||
/// Slave exps are drawn differently and selecting them does not activate
|
||||
@@ -24,16 +25,22 @@
|
||||
other != null &&
|
||||
expiration == other.expiration &&
|
||||
symbol == other.symbol &&
|
||||
venue == other.venue &&
|
||||
calc_mode == other.calc_mode;
|
||||
|
||||
public override int GetHashCode() =>
|
||||
EqualityComparer.auto_phase(symbol.GetHashCode(), expiration.GetHashCode());
|
||||
HashCode.Combine(symbol.GetHashCode(), expiration.GetHashCode(), venue.GetHashCode());
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
Equals(obj as VolSurfaceDisplayGridExpiration);
|
||||
|
||||
public override string ToString() =>
|
||||
SecurityFormatter.format_future(symbol, expiration);
|
||||
public override string ToString() {
|
||||
var rv = SecurityFormatter.format_future(symbol, expiration);
|
||||
if (venue != Venue.Unset) {
|
||||
rv = $"{rv} ({venue})";
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static bool operator ==(VolSurfaceDisplayGridExpiration x, VolSurfaceDisplayGridExpiration y) =>
|
||||
x is null ? y is null : x.Equals(y);
|
||||
|
||||
@@ -165,8 +165,8 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
internal Tuple<SecurityExpiration, IDictionary<double, Tuple<VolSurfaceMDUnit, VolSurfaceMDUnit>>> get_option_bbo_vsexp(VolSurfaceExpiration exp) {
|
||||
// this is a workaround for VSExp not having an exchange
|
||||
foreach (Venue v in System.Enum.GetValues(typeof(Venue))) {
|
||||
// Prefer bbo from the same venue as the exp, but fallback to another venue if necessary.
|
||||
foreach (Venue v in Enum.GetValues<Venue>().Except(exp.venue).Prepend(exp.venue)) {
|
||||
var sec_exp =
|
||||
new SecurityExpiration(v, SecurityType.Option, exp.symbol, exp.expiration);
|
||||
var rv = get_option_bbo(sec_exp);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
namespace mbts.ui.controls {
|
||||
using bts.api;
|
||||
|
||||
using mbts.analytics;
|
||||
using mbts.spark;
|
||||
using mbts.user.settings;
|
||||
@@ -56,7 +58,11 @@ namespace mbts.ui.controls {
|
||||
{
|
||||
foreach (VolSurfaceDisplayGridExpiration disp_exp in exp_disp_grid.get_ordered_expirations())
|
||||
{
|
||||
VolSurfaceExpiration exp = new VolSurfaceExpiration() { symbol = disp_exp.symbol, expiration = disp_exp.expiration };
|
||||
var exp = VolSurfaceExpiration.Default.with(
|
||||
symbol: disp_exp.symbol,
|
||||
expiration: disp_exp.expiration,
|
||||
venue: disp_exp.venue,
|
||||
security_type: SecurityType.Option);
|
||||
VolCurveParameters curve_parameter = VolSurfaceDataFunctions.get_curve_parameters(vs_input, exp);
|
||||
curve_parameter.core_parameters.ref_forward = VolSurfaceDisplayUtilities.parse_double(exp_disp_grid.get_grid_data(disp_exp, _ref_fwd_col, Double.NaN));
|
||||
curve_parameter.core_parameters.driver_override = VolSurfaceDisplayUtilities.parse_double(exp_disp_grid.get_grid_data(disp_exp, _driver_override_col, Double.NaN));
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
namespace mbts.ui.controls {
|
||||
using mbts.analytics;
|
||||
using bts.api;
|
||||
|
||||
using mbts.analytics;
|
||||
using mbts.spark;
|
||||
using mbts.user.settings;
|
||||
|
||||
@@ -40,7 +42,11 @@ using System.Collections.Generic;
|
||||
/// just for the input values, which in this case are all
|
||||
foreach (VolSurfaceDisplayGridExpiration disp_exp in exp_disp_grid.get_ordered_expirations())
|
||||
{
|
||||
VolSurfaceExpiration exp = new VolSurfaceExpiration() { symbol = disp_exp.symbol, expiration = disp_exp.expiration };
|
||||
var exp = VolSurfaceExpiration.Default.with(
|
||||
symbol: disp_exp.symbol,
|
||||
expiration: disp_exp.expiration,
|
||||
venue: disp_exp.venue,
|
||||
security_type: SecurityType.Option);
|
||||
VolCurveParameters curve_parameter = VolSurfaceDataFunctions.get_curve_parameters(vs_input, exp);
|
||||
curve_parameter.core_parameters.put_wing_parameters.simple_slope_wing_parameters.max_vol = VolSurfaceDisplayUtilities.parse_double(exp_disp_grid.get_grid_data(disp_exp, _p_wing_max, Double.NaN));
|
||||
curve_parameter.core_parameters.call_wing_parameters.simple_slope_wing_parameters.max_vol = VolSurfaceDisplayUtilities.parse_double(exp_disp_grid.get_grid_data(disp_exp, _c_wing_max, Double.NaN));
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace mbts.ui.controls {
|
||||
using bts.api;
|
||||
|
||||
using mbts.analytics;
|
||||
using mbts.spark;
|
||||
using mbts.user.settings;
|
||||
@@ -111,7 +113,11 @@
|
||||
{
|
||||
foreach (VolSurfaceDisplayGridExpiration disp_exp in exp_disp_grid.get_ordered_expirations())
|
||||
{
|
||||
VolSurfaceExpiration exp = new VolSurfaceExpiration() { symbol = disp_exp.symbol, expiration = disp_exp.expiration };
|
||||
var exp = VolSurfaceExpiration.Default.with(
|
||||
symbol: disp_exp.symbol,
|
||||
expiration: disp_exp.expiration,
|
||||
venue: disp_exp.venue,
|
||||
security_type: SecurityType.Option);
|
||||
SplineModelVolCurveParameters input_spline_parameters = VolSurfaceDataFunctions.get_spline_curve_parameters(vs_input, exp);
|
||||
VolCurveParameters input_general_parameters = VolSurfaceDataFunctions.get_curve_parameters(vs_input, exp);
|
||||
for (uint p_point_no = 0; p_point_no < _put_cols.Count(); p_point_no++)
|
||||
|
||||
@@ -8,6 +8,7 @@ using mbts.analytics;
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using bts;
|
||||
using bts.api;
|
||||
|
||||
namespace mbts.ui.controls {
|
||||
class VolSurfaceUIAdapter {
|
||||
@@ -91,7 +92,7 @@ namespace mbts.ui.controls {
|
||||
IDictionary<VolSurfaceDisplayGridExpiration, IDictionary<VolSurfaceDisplayGridColumn, object>> exp_display_map = new Dictionary<VolSurfaceDisplayGridExpiration, IDictionary<VolSurfaceDisplayGridColumn, object>>();
|
||||
foreach (KeyValuePair<VolSurfaceExpiration, IDictionary<VolSurfaceDisplayGridColumn, object>> p in exp_map) {
|
||||
VolCurveOutput vc_out = vs_output.exp_output_map.TryGetValue(p.Key, out vc_out) ? vc_out : null;
|
||||
VolSurfaceDisplayGridExpiration disp_exp = new VolSurfaceDisplayGridExpiration(p.Key.symbol, p.Key.expiration, vc_out != null ? vc_out.calc_method : VolSurfaceEnums.VolSurfaceExpirationCalculationMethod.Master);
|
||||
VolSurfaceDisplayGridExpiration disp_exp = new VolSurfaceDisplayGridExpiration(p.Key.symbol, p.Key.expiration, p.Key.venue, vc_out != null ? vc_out.calc_method : VolSurfaceEnums.VolSurfaceExpirationCalculationMethod.Master);
|
||||
exp_display_map.Add(disp_exp, p.Value);
|
||||
}
|
||||
exp_grid = new VolSurfaceDisplayGrid(exp_display_map.Keys.OrderBy(t => t), ordered_cols, exp_display_map);
|
||||
@@ -103,7 +104,8 @@ namespace mbts.ui.controls {
|
||||
public static VolSurfaceInput copy_ui_to_input(VolSurfaceDisplayGrid exp_disp_grid, VolSurfaceSettings settings, VolSurfaceMacroGridSettings grid_settings) {
|
||||
// HighPerformanceTimer timer = new HighPerformanceTimer();
|
||||
// timer.start();
|
||||
VolSurfaceInput rv = VolSurfaceDataFunctions.get_default_vs_input(settings, exp_disp_grid.get_ordered_expirations().Select(exp => new VolSurfaceExpiration() { expiration = exp.expiration, symbol = exp.symbol }));
|
||||
var rv = VolSurfaceDataFunctions.get_default_vs_input(settings, exp_disp_grid.get_ordered_expirations()
|
||||
.Select(exp => new VolSurfaceExpiration(SecurityType.Option, exp.symbol, exp.expiration, exp.venue)));
|
||||
IEnumerable<IReadWriteGridAdapter> grid_adapters = _get_grid_adapters(settings, grid_settings);
|
||||
foreach (IReadWriteGridAdapter g in grid_adapters)
|
||||
g.copy_grid_to_data(exp_disp_grid, settings, ref rv);
|
||||
@@ -117,7 +119,7 @@ namespace mbts.ui.controls {
|
||||
out IDictionary<VolSurfaceDisplayGridExpiration, VolCurveDisplayGraph> exp_graph_map) {
|
||||
exp_graph_map = new Dictionary<VolSurfaceDisplayGridExpiration, VolCurveDisplayGraph>();
|
||||
foreach (KeyValuePair<VolSurfaceExpiration, VolCurveOutput> p in vs_output.exp_output_map) {
|
||||
VolSurfaceDisplayGridExpiration exp = new VolSurfaceDisplayGridExpiration(p.Key.symbol, p.Key.expiration, p.Value.calc_method);
|
||||
var exp = new VolSurfaceDisplayGridExpiration(p.Key.symbol, p.Key.expiration, p.Key.venue, p.Value.calc_method);
|
||||
VolCurveOutput curve_output = p.Value;
|
||||
IEnumerable<Tuple<double, double>> exp_graph_series = curve_output.strike_vol_map.Select(kvp => Tuple.Create(kvp.Key, kvp.Value)).OrderBy(t => t.Item1);
|
||||
exp_graph_map[exp] = new VolCurveDisplayGraph(exp_graph_series.OrderBy(t => t.Item1),
|
||||
|
||||
@@ -323,7 +323,7 @@ namespace mbts.spark {
|
||||
if (show_implied_vol && _md_exp != null && _md_exp.symbol != _expiration.symbol) {
|
||||
var suffix = _md_exp.expiration == _expiration.expiration ? _md_exp.symbol :
|
||||
new VolSurfaceDisplayGridExpiration(
|
||||
_md_exp.symbol, _md_exp.expiration, VolSurfaceEnums.VolSurfaceExpirationCalculationMethod.Master)
|
||||
_md_exp.symbol, _md_exp.expiration, _md_exp.venue, VolSurfaceEnums.VolSurfaceExpirationCalculationMethod.Master)
|
||||
.ToString();
|
||||
return $"{_expiration} ({suffix})";
|
||||
}
|
||||
|
||||
@@ -250,7 +250,11 @@
|
||||
|
||||
public IEnumerable<Tuple<double, double>> get_committed_volpath(VolSurfaceDisplayGridExpiration exp) {
|
||||
if (_committed_data != null && _committed_data.vs_output != null) {
|
||||
VolCurveOutput exp_out = _committed_data.vs_output[new VolSurfaceExpiration(SecurityType.Option, exp.symbol, exp.expiration)];
|
||||
VolCurveOutput exp_out = _committed_data.vs_output[VolSurfaceExpiration.Default.with(
|
||||
security_type: SecurityType.Option,
|
||||
symbol: exp.symbol,
|
||||
expiration: exp.expiration,
|
||||
venue: exp.venue)];
|
||||
return VolSurfaceUtilityFunctions.get_vol_path_points(exp_out);
|
||||
} else
|
||||
return Enumerable.Empty<Tuple<double, double>>();
|
||||
@@ -258,7 +262,11 @@
|
||||
|
||||
public IEnumerable<Tuple<double, double>> get_candidate_volpath(VolSurfaceDisplayGridExpiration exp) {
|
||||
if (is_dirty && _candidate_data != null && _candidate_data.vs_output != null) {
|
||||
VolCurveOutput exp_out = _candidate_data.vs_output[new VolSurfaceExpiration(SecurityType.Option, exp.symbol, exp.expiration)];
|
||||
VolCurveOutput exp_out = _candidate_data.vs_output[VolSurfaceExpiration.Default.with(
|
||||
security_type: SecurityType.Option,
|
||||
symbol: exp.symbol,
|
||||
expiration: exp.expiration,
|
||||
venue: exp.venue)];
|
||||
return VolSurfaceUtilityFunctions.get_vol_path_points(exp_out);
|
||||
} else
|
||||
return Enumerable.Empty<Tuple<double, double>>();
|
||||
@@ -374,7 +382,11 @@
|
||||
string[] data_items = line.Split(',').Select(cn => cn.Trim()).ToArray();
|
||||
if (data_items.Length != col_names.Length)
|
||||
throw new ApplicationException("Data is not well formed");
|
||||
VolSurfaceDisplayGridExpiration grid_exp = new VolSurfaceDisplayGridExpiration(data_items[0], DateTime.Parse(data_items[1]), VolSurfaceEnums.VolSurfaceExpirationCalculationMethod.Master);
|
||||
VolSurfaceDisplayGridExpiration grid_exp = new(
|
||||
data_items[0],
|
||||
DateTime.Parse(data_items[1]),
|
||||
Enum.Parse<Venue>(data_items[2]),
|
||||
VolSurfaceEnums.VolSurfaceExpirationCalculationMethod.Master);
|
||||
for (int i = 2; i < col_names.Length; i++) {
|
||||
string col_name = file_col_map[i];
|
||||
string data_text = data_items[i];
|
||||
|
||||
@@ -142,7 +142,12 @@ namespace mbts.spark {
|
||||
};
|
||||
|
||||
public static VolSurfaceExpiration to_vs_exp(this SecurityExpiration sec_exp) =>
|
||||
new() { security_type = sec_exp.security_type, symbol = sec_exp.symbol, expiration = sec_exp.expiration };
|
||||
new() {
|
||||
security_type = sec_exp.security_type,
|
||||
symbol = sec_exp.symbol,
|
||||
expiration = sec_exp.expiration,
|
||||
venue = sec_exp.exchange,
|
||||
};
|
||||
|
||||
public static DriverCalculationType to_driver_calc_type(
|
||||
this ExpirationDriver.ModeOneofCase driver_mode) =>
|
||||
@@ -218,7 +223,7 @@ namespace mbts.spark {
|
||||
new(to_api_sec_exp(sec_exp));
|
||||
|
||||
public static SecurityExpiration to_security_expiration(this VolSurfaceExpiration vs_exp) =>
|
||||
new(Venue.Unset, vs_exp.security_type, vs_exp.symbol, vs_exp.expiration);
|
||||
new(vs_exp.venue, vs_exp.security_type, vs_exp.symbol, vs_exp.expiration);
|
||||
|
||||
static IEnumerable<(double x, double y)> _select_real_points(IEnumerable<Tuple<double, double>> points) =>
|
||||
points.Where(pt => pt.Item1.is_real() && pt.Item2.is_real()).Select(t => (t.Item1, t.Item2));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using bts.api;
|
||||
|
||||
using mbts.utils;
|
||||
@@ -22,25 +22,28 @@ public class VolSurfaceExpiration : IEquatable<VolSurfaceExpiration>, IComparabl
|
||||
x => x.expiration,
|
||||
x => x.symbol,
|
||||
x => x.security_type,
|
||||
x => x.venue,
|
||||
};
|
||||
|
||||
public VolSurfaceExpiration()
|
||||
: this(SecurityType.Unset, string.Empty, default) { }
|
||||
: this(SecurityType.Unset, string.Empty, default, Venue.Unset) { }
|
||||
|
||||
public VolSurfaceExpiration(SecurityType security_type, string symbol, DateTime expiration) {
|
||||
public VolSurfaceExpiration(SecurityType security_type, string symbol, DateTime expiration, Venue venue) {
|
||||
this.security_type = security_type;
|
||||
this.symbol = symbol;
|
||||
this.expiration = expiration;
|
||||
this.venue = venue;
|
||||
}
|
||||
|
||||
public VolSurfaceExpiration(SecurityExpiration exp) {
|
||||
symbol = exp.symbol;
|
||||
expiration = exp.expiration;
|
||||
security_type = exp.security_type;
|
||||
venue = exp.exchange;
|
||||
}
|
||||
|
||||
public static VolSurfaceExpiration Default =>
|
||||
new(SecurityType.Unset, string.Empty, default);
|
||||
new(SecurityType.Unset, string.Empty, default, Venue.Unset);
|
||||
|
||||
[ProtoMember(10)]
|
||||
public string symbol { get; set; }
|
||||
@@ -51,28 +54,42 @@ public class VolSurfaceExpiration : IEquatable<VolSurfaceExpiration>, IComparabl
|
||||
[ProtoMember(30)]
|
||||
public SecurityType security_type { get; set; }
|
||||
|
||||
[ProtoMember(40)]
|
||||
public Venue venue { get; set; }
|
||||
|
||||
public VolSurfaceExpiration with(
|
||||
string? symbol = null,
|
||||
DateTime? expiration = null,
|
||||
SecurityType? security_type = null
|
||||
SecurityType? security_type = null,
|
||||
Venue? venue = null
|
||||
) =>
|
||||
new(security_type ?? this.security_type, symbol ?? this.symbol, expiration ?? this.expiration);
|
||||
new(
|
||||
security_type ?? this.security_type,
|
||||
symbol ?? this.symbol,
|
||||
expiration ?? this.expiration,
|
||||
venue ?? this.venue);
|
||||
|
||||
public bool Equals(VolSurfaceExpiration? other) =>
|
||||
other is not null
|
||||
&& symbol == other.symbol
|
||||
&& expiration == other.expiration
|
||||
&& security_type == other.security_type;
|
||||
&& security_type == other.security_type
|
||||
&& venue == other.venue;
|
||||
|
||||
public int CompareTo(VolSurfaceExpiration? other) =>
|
||||
_comparer.Compare(this, other);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
HashCode.Combine(security_type, symbol, expiration);
|
||||
HashCode.Combine(security_type, symbol, expiration, venue);
|
||||
|
||||
public override bool Equals(object? obj) =>
|
||||
Equals(obj as VolSurfaceExpiration);
|
||||
|
||||
public override string ToString() =>
|
||||
$"{char.ToUpper(security_type.ToString()[0])} {symbol} {expiration.ToShortDateString()}";
|
||||
public override string ToString() {
|
||||
var rv = $"{char.ToUpper(security_type.ToString()[0])} {symbol} {expiration.ToShortDateString()}";
|
||||
if (venue != Venue.Unset) {
|
||||
rv += " " + venue.ToString();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,12 @@ namespace mbts.analytics {
|
||||
|
||||
foreach (var kv in exp_date_data) {
|
||||
_cell_cache.AddOrUpdate(
|
||||
new VolSurfaceExpiration(SecurityType.Option, string.Empty, kv.Key),
|
||||
VolSurfaceExpiration.Default.with(security_type: SecurityType.Option, expiration: kv.Key),
|
||||
c => c.update(kv.Value.aggregate),
|
||||
() => new ComboReportFutureExpirationCell(kv.Value.aggregate));
|
||||
foreach (var sym_kv in kv.Value.symbol_data) {
|
||||
_cell_cache.AddOrUpdate(
|
||||
new VolSurfaceExpiration(SecurityType.Option, sym_kv.Key, kv.Key),
|
||||
VolSurfaceExpiration.Default.with(security_type: SecurityType.Option, symbol: sym_kv.Key, expiration: kv.Key),
|
||||
c => c.update(sym_kv.Value),
|
||||
() => new ComboReportFutureSymbolCell(sym_kv.Value));
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace mbts.analytics {
|
||||
var exp_agg_cols = data.future_expirations
|
||||
.Select(vse => vse.expiration)
|
||||
.Distinct()
|
||||
.Select(exp_date => new VolSurfaceExpiration(SecurityType.Option, string.Empty, exp_date));
|
||||
.Select(exp_date => VolSurfaceExpiration.Default.with(security_type: SecurityType.Option, expiration: exp_date));
|
||||
_expirations.sync_with(exp_agg_cols.Ordered(), allow_duplicates: false);
|
||||
_row.update(data.get_future_exp_date_map());
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ namespace mbts.analytics {
|
||||
}
|
||||
foreach (var kv in exp_date_data) {
|
||||
_cell_cache.AddOrUpdate(
|
||||
new VolSurfaceExpiration(SecurityType.Option, string.Empty, kv.Key),
|
||||
VolSurfaceExpiration.Default.with(security_type: SecurityType.Option, expiration: kv.Key),
|
||||
c => c.update(kv.Value.aggregate),
|
||||
() => new ComboReportOptionExpirationCell(kv.Value.aggregate));
|
||||
foreach (var sym_kv in kv.Value.symbol_data) {
|
||||
_cell_cache.AddOrUpdate(
|
||||
new VolSurfaceExpiration(SecurityType.Option, sym_kv.Key, kv.Key),
|
||||
VolSurfaceExpiration.Default.with(security_type: SecurityType.Option, symbol: sym_kv.Key, expiration: kv.Key),
|
||||
c => c.update(sym_kv.Value),
|
||||
() => new ComboReportOptionSymbolCell(sym_kv.Value));
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace mbts.analytics {
|
||||
var exp_agg_cols = data.option_expirations
|
||||
.Select(vse => vse.expiration)
|
||||
.Distinct()
|
||||
.Select(exp_date => new VolSurfaceExpiration(SecurityType.Option, string.Empty, exp_date));
|
||||
.Select(exp_date => VolSurfaceExpiration.Default.with(security_type: SecurityType.Option, expiration: exp_date));
|
||||
_expirations.sync_with(
|
||||
data.option_expirations.Concat(exp_agg_cols).Ordered(_exp_comparer));
|
||||
foreach (var r in rows) {
|
||||
|
||||
@@ -293,7 +293,8 @@ namespace mbts.analytics {
|
||||
/// because of aggregation
|
||||
var exp_data = new Dictionary<VolSurfaceExpiration, IEnumerable<SlideGreekUnit>>(option_exp_data);
|
||||
foreach (var kv in future_exp_data) {
|
||||
exp_data.Add(new VolSurfaceExpiration(SecurityType.Future, kv.Key.symbol, kv.Key.expiration), kv.Value);
|
||||
Log.assert(kv.Key.security_type == SecurityType.Future);
|
||||
exp_data.Add(kv.Key, kv.Value);
|
||||
}
|
||||
// foreach (var kv in option_exp_data) {
|
||||
// VolSurfaceExpiration formatted_exp = new VolSurfaceExpiration(kv.Key.symbol, mbts.ui.utility.ExpirationFormatter.convert_real_to_mapped(SecurityType.Option, kv.Key.symbol, kv.Key.expiration));
|
||||
|
||||
@@ -7,6 +7,7 @@ using bts.api.analytics;
|
||||
|
||||
using bts.api;
|
||||
using bts.utils;
|
||||
using mbts.spark;
|
||||
|
||||
namespace mbts.analytics {
|
||||
public class VolSurfaceSlideCalculator {
|
||||
@@ -63,10 +64,10 @@ namespace mbts.analytics {
|
||||
}
|
||||
}
|
||||
option_pos_map = option_pos_map_aux.ToDictionary(
|
||||
kv => new VolSurfaceExpiration(SecurityType.Option, kv.Key.symbol, kv.Key.expiration),
|
||||
kv => kv.Key.with(security_type: SecurityType.Option).to_vs_exp(),
|
||||
kv => kv.Value.ToDictionaryDupes(i => i.Key, i => Tuple.Create(i.Value[0], i.Value[1])));
|
||||
future_pos_map = future_pos_map_aux.ToDictionary(
|
||||
kv => new VolSurfaceExpiration(bts.api.SecurityType.Future, kv.Key.symbol, kv.Key.expiration),
|
||||
kv => kv.Key.with(security_type: SecurityType.Future).to_vs_exp(),
|
||||
kv => kv.Value);
|
||||
}
|
||||
|
||||
@@ -422,7 +423,7 @@ namespace mbts.analytics {
|
||||
double cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Future, exp.symbol, Venue.Unset), out cpp) ? cpp : Double.NaN;
|
||||
IEnumerable<Tuple<double, double, double>> exp_handle_theos = _compute_future_slide_theos(perc_handles, exp_theo.theo, exp_theo.delta, exp_theo.roll);
|
||||
SlideContractUnit exp_val = new SlideContractUnit(n_greeks, exp_handle_theos.Select(t => t.Item3));
|
||||
slide_expiration_map.Add(VolSurfaceSlideCalculator._to_sec_exp(exp, false), exp_val);
|
||||
slide_expiration_map.Add(exp.with(security_type: SecurityType.Future).to_security_expiration(), exp_val);
|
||||
int handle_index = 0;
|
||||
foreach (var t in exp_handle_theos) {
|
||||
double handle_theo = t.Item1, handle_driver = t.Item3;
|
||||
@@ -460,7 +461,7 @@ namespace mbts.analytics {
|
||||
IDictionary<mbts.SecurityStrike, List<Theos>> exp_k_theo_map = VolSurfaceSlideCalculator._convert_exp_theos_to_strike_theos(theo_map);
|
||||
/* expiration */
|
||||
foreach (var kv_exp in pos_map) {
|
||||
SecurityExpiration exp = _to_sec_exp(kv_exp.Key, true);
|
||||
SecurityExpiration exp = kv_exp.Key.with(security_type: SecurityType.Option).to_security_expiration();
|
||||
IDictionary<double, Tuple<double, double>> exp_pos_map = kv_exp.Value;
|
||||
double cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Option, exp.symbol, Venue.Unset), out cpp) ? cpp : Double.NaN;
|
||||
/* strike */
|
||||
@@ -500,13 +501,6 @@ namespace mbts.analytics {
|
||||
|
||||
#region Conversions
|
||||
|
||||
internal static VolSurfaceExpiration _to_vs_exp(SecurityExpiration exp) =>
|
||||
new(SecurityType.Option, exp.symbol, exp.expiration);
|
||||
|
||||
internal static mbts.SecurityExpiration _to_sec_exp(VolSurfaceExpiration exp, bool is_option) {
|
||||
return new SecurityExpiration(Venue.Unset, is_option ? SecurityType.Option : SecurityType.Future, exp.symbol, exp.expiration);
|
||||
}
|
||||
|
||||
internal static IDictionary<SecurityStrike, T> _to_strike_map<T>(IDictionary<SecurityExpiration, IDictionary<double, T>> exp_map) {
|
||||
IDictionary<SecurityStrike, T> rv = new Dictionary<SecurityStrike, T>();
|
||||
foreach (var kv_exp in exp_map)
|
||||
|
||||
Reference in new issue
Block a user