refactor: Index vol and theos data by symbol/venue tuple

Rather than just symbol, to avoid conflicts when the same symbol exists
at multiple exchanges
This commit is contained in:
John Colvin committed 2024-09-13 10:50:23 -04:00
1 parent 39ef30c1e3
commit 5baec19aff
45 files changed
+449 -295

No files matched your search

@@ -104,8 +104,7 @@ namespace mbts.spark {
if (param_map == null || sc_data == null) {
return;
}
IDictionary<mbts.SecurityExpiration, mbts.SecurityExpiration> driver_map =
param_map.get_option_to_driver_map(_sec_tup.security_name);
var driver_map = param_map.get_option_to_driver_map(_sec_tup.security_name, _sec_tup.security_exchange);
// look up the market data
IDictionary<SecurityExpiration, DriverMD> res =
new Dictionary<SecurityExpiration, DriverMD>();
@@ -137,7 +136,7 @@ namespace mbts.spark {
// bts.Log.Gen.info("SingleOptionDriverPricePublisher._compute_and_fire \n" +
// $"map:{to_fire.log_string()}");
_logger.stop_default_timer();
_bb.post(SparkTags.OptionDriverBBOTag(_sec_tup.security_name),
_bb.post(SparkTags.OptionDriverBBOTag((_sec_tup.security_name, _sec_tup.security_exchange)),
new OptionDriverPriceMap(_sec_tup.security_name, res));
}
}
@@ -24,15 +24,15 @@ namespace mbts.spark {
private readonly SymbolListType _list_type;
private readonly int _vs_id;
private readonly ThreadedBlackboard _bb;
private readonly Func<IEnumerable<string>, IDisposable> _create_func;
private readonly Func<IEnumerable<(string, Venue)>, IDisposable> _create_func;
private readonly ITag<VolSurfaceInput> _in_bb_committed_data_tag;
private readonly ITag<VolSurfaceCalculationRequest> _in_bb_calc_req_tag;
private HashSet<string> _option_symbols = new HashSet<string>();
private HashSet<(string, Venue)> _option_symbols = new();
private IDisposable _source = null;
public SingleVolSurfaceDataSource(SymbolListType list_type, int vs_id, ThreadedBlackboard threaded_bb,
Func<IEnumerable<string>, IDisposable> create_func) {
Func<IEnumerable<(string, Venue)>, IDisposable> create_func) {
Log.Gen.info(String.Format("SingleVolSurfaceDataSource constructed vs_id {0}", vs_id));
_list_type = list_type;
_vs_id = vs_id;
@@ -56,33 +56,33 @@ namespace mbts.spark {
VolSurfaceInput vs_comm_inp = _bb.read_state(_in_bb_committed_data_tag);
if (_list_type == SymbolListType.Candidate) {
if (vs_calc_req != null && vs_calc_req.volsurface_input != null) {
HashSet<string> new_sym_map = new HashSet<string>(VolSurfaceDataFunctions.get_symbols(vs_calc_req.volsurface_input));
var new_sym_map = VolSurfaceDataFunctions.get_symbols(vs_calc_req.volsurface_input).ToHashSet();
_create_if_needed(new_sym_map);
}
} else if (_list_type == SymbolListType.Committed) {
if (vs_comm_inp != null) {
HashSet<string> new_sym_map = new HashSet<string>(VolSurfaceDataFunctions.get_symbols(vs_comm_inp));
var new_sym_map = VolSurfaceDataFunctions.get_symbols(vs_comm_inp).ToHashSet();
_create_if_needed(new_sym_map);
}
} else if (_list_type == SymbolListType.Combined) {
List<string> new_sym_list = new List<string>();
var new_syms = new HashSet<(string, Venue)>();
if (vs_calc_req != null && vs_calc_req.volsurface_input != null)
new_sym_list.AddRange(VolSurfaceDataFunctions.get_symbols(vs_calc_req.volsurface_input));
new_syms.AddRange(VolSurfaceDataFunctions.get_symbols(vs_calc_req.volsurface_input));
if (vs_comm_inp != null)
new_sym_list.AddRange(VolSurfaceDataFunctions.get_symbols(vs_comm_inp));
_create_if_needed(new HashSet<string>(new_sym_list));
new_syms.AddRange(VolSurfaceDataFunctions.get_symbols(vs_comm_inp));
_create_if_needed(new_syms);
}
}
private void _create_if_needed(HashSet<string> new_sym_map) {
private void _create_if_needed(HashSet<(string, Venue)> new_sym_map) {
if (!CollectionHelper.hashset_equals(_option_symbols, new_sym_map)) {
_option_symbols = new HashSet<string>(new_sym_map);
_option_symbols = new(new_sym_map);
if (_source != null)
_source.Dispose();
_source = _create_func(_option_symbols);
_bb.post(SparkTags.AquireTag(Guid.NewGuid().ToString()),
new SymbolResourceAllocationUnit(
_option_symbols.Select(i => new mbts.SecurityTuple(SecurityType.Option, i, Venue.Unset)), this, true));
_option_symbols.Select(i => new mbts.SecurityTuple(SecurityType.Option, i.Item1, i.Item2)), this, true));
}
}
@@ -95,4 +95,4 @@ namespace mbts.spark {
#endregion
}
}
}
@@ -25,12 +25,12 @@ namespace mbts.spark {
public class SingleVolSurfaceInterpGreeksPublisher : IDisposable {
private readonly int _vs_id;
private readonly ThreadedBlackboard _bb;
private HashSet<string> _all_symbols;
private HashSet<(string, Venue)> _all_symbols;
private VolSurfaceInterpGreeksProducer _theo_producer;
private readonly ITag<VolSurfaceInput> _in_vs_input_tag;
private readonly ITag<VolSurfaceNonVolInput> _in_vs_nonvol_input_tag;
private readonly ITag<VolSurfaceStrikeMap> _in_vs_contracts_tag;
private ITag<IReadOnlyDictionary<string, OptionDriverPriceMap>>
private ITag<IReadOnlyDictionary<(string, Venue), OptionDriverPriceMap>>
_in_all_syms_driver_price_tag = SparkTags.AllOptionDriverBBOTag;
private readonly ITag<VolSurfaceStandardTime> _in_vs_standard_time_tag;
private readonly ITag<bool> _in_ui_up_tag;
@@ -38,11 +38,11 @@ namespace mbts.spark {
private readonly PerfStatsLogger _logger;
public SingleVolSurfaceInterpGreeksPublisher(int vs_id,
ThreadedBlackboard threaded_bb, IEnumerable<string> symbols) {
ThreadedBlackboard threaded_bb, IEnumerable<(string, Venue)> symbols) {
bts.Log.Gen.info($"SingleVolSurfaceInterpGreeksPublisher cons {vs_id}");
_vs_id = vs_id;
_bb = threaded_bb;
_all_symbols = new HashSet<string>(symbols);
_all_symbols = symbols.ToHashSet();
_logger = new PerfStatsLogger(10, 100,
$"SingleVolSurfaceInterpGreeksPublisher_{vs_id}");
_theo_producer = new VolSurfaceInterpGreeksProducer(vs_id);
@@ -191,4 +191,4 @@ namespace mbts.spark {
}
#endregion
}
}
}
@@ -192,7 +192,7 @@
VolSurfaceExpiration option_exp) {
var driver_map = bb.read_state(SparkTags.AllOptionDriverBBOTag);
if (driver_map != null &&
driver_map.TryGetValue(option_exp.symbol, out var sym_map)) {
driver_map.TryGetValue((option_exp.symbol, option_exp.venue), out var sym_map)) {
var vs_md = sym_map.get_driver_md(option_exp.expiration);
return vs_md.get_driver();
}
@@ -18,15 +18,15 @@ namespace mbts.spark {
// 2. VolSurfaceStrikeMap
public class SingleVolSurfaceNonVolDataSource : IDisposable {
private readonly int _vs_id;
private readonly IEnumerable<string> _option_symbols;
private readonly IEnumerable<(string, Venue)> _option_symbols;
private readonly ThreadedBlackboard _bb;
private readonly ITag<SystemContractData> _in_bb_contract_data_tag;
private readonly ITag<VolSurfaceNonVolInput> _in_bb_vs_nonvol_input_tag;
private readonly ITag<IReadOnlyDictionary<string, OptionDriverPriceMap>> _in_bb_all_driver_price_tag;
private readonly ITag<IReadOnlyDictionary<(string, Venue), OptionDriverPriceMap>> _in_bb_all_driver_price_tag;
private readonly ITag<mbts.analytics.VolSurfaceNonVolData> _out_bb_vs_nonvol_data_tag;
private readonly ITag<mbts.analytics.VolSurfaceStrikeMap> _out_bb_vs_contracts_tag;
public SingleVolSurfaceNonVolDataSource(int vs_id, IEnumerable<string> option_symbols,
public SingleVolSurfaceNonVolDataSource(int vs_id, IEnumerable<(string, Venue)> option_symbols,
ThreadedBlackboard bb) {
bts.Log.Gen.info($"SingleVolSurfaceNonVolDataSource vs_id:{vs_id}");
_vs_id = vs_id;
@@ -25,7 +25,7 @@ namespace mbts.spark {
}
private readonly RequestType _request_type = RequestType.UI;
private readonly int _vs_id;
private readonly HashSet<string> _symbols;
private readonly HashSet<(string, Venue)> _symbols;
private readonly ThreadedBlackboard _bb;
private readonly ITag<VolSurfaceCalculationRequest> _in_bb_request_tag;
private readonly ITag<VolSurfaceCalculationRequest> _in_bb_auto_request_tag;
@@ -37,12 +37,12 @@ namespace mbts.spark {
private VolSurfaceOutput _last_output;
public SingleVolSurfaceRequestCalculator(RequestType request_type,
int vs_id, IEnumerable<string> symbols,
int vs_id, IEnumerable<(string, Venue)> symbols,
ThreadedBlackboard threaded_bb) {
bts.Log.Gen.info($"SingleVolSurfaceRequestCalculator cons vs_id: {vs_id} request_type: {request_type}");
_request_type = request_type;
_vs_id = vs_id;
_symbols = new HashSet<string>(symbols);
_symbols = symbols.ToHashSet();
_bb = threaded_bb;
_in_bb_request_tag = SparkTags.VolSurfaceCalculationRequestTag(vs_id);
_in_bb_auto_request_tag = SparkTags.VolSurfaceAutoCalculationRequestTag(vs_id);
@@ -12,19 +12,18 @@ namespace mbts.analytics {
public class SymbolAggregationPublisher<TData> : IDisposable {
private readonly ThreadedBlackboard _bb;
private readonly SecurityType _sec_type;
Func<string, ITag<TData>> _get_tag;
Func<(string, Venue), ITag<TData>> _get_tag;
// the tag on which the output will be published
ITag<IReadOnlyDictionary<string, TData>> _out_tag;
ITag<IReadOnlyDictionary<(string, Venue), TData>> _out_tag;
private readonly ITag<SystemContractData> _sc_data_tag;
private Dictionary<string, ITag<TData>> _tag_map =
new Dictionary<string, ITag<TData>>();
private Dictionary<(string, Venue), ITag<TData>> _tag_map = new();
private HashSet<object> _obj_tags = new HashSet<object>();
private bool _dirty = true;
public SymbolAggregationPublisher(
ThreadedBlackboard bb,
SecurityType sec_type,
Func<string, ITag<TData>> get_tag,
ITag<IReadOnlyDictionary<string, TData>> out_tag) {
Func<(string, Venue), ITag<TData>> get_tag,
ITag<IReadOnlyDictionary<(string, Venue), TData>> out_tag) {
_bb = bb;
_sec_type = sec_type;
_get_tag = get_tag;
@@ -57,7 +56,7 @@ namespace mbts.analytics {
}
// this is not correct since it is assuming symbol/name is
// unique across securty_tuples
string symbol = st.security_name;
var symbol = (st.security_name, st.security_exchange);
if (!_tag_map.ContainsKey(symbol)) {
var tag = _get_tag(symbol);
if (tag != null) {
@@ -73,14 +72,14 @@ namespace mbts.analytics {
private void _on_timer() {
if (_dirty) {
_dirty = false;
Dictionary<string, TData> output = new Dictionary<string, TData>();
var output = new Dictionary<(string, Venue), TData>();
foreach (var kv in _tag_map) {
var symbol = kv.Key;
var symbol_tag = kv.Value;
TData symbol_data = _bb.read_state(symbol_tag);
output.Add(symbol, symbol_data);
}
IReadOnlyDictionary<string, TData> ro_output = output;
IReadOnlyDictionary<(string, Venue), TData> ro_output = output;
bts.Log.Gen.diag($"SymbolAggregationPublisher._on_timer publishing " +
$"tag: {_out_tag} sz: {ro_output.Count}");
_bb.post(_out_tag, ro_output);
@@ -185,7 +185,7 @@ namespace mbts.spark
static IReadOnlyDictionary<uint, VolSurfaceTheoPoint> _assemble_keyed_theos(
SystemContractData sc_data,
IReadOnlyDictionary<string, ExpStrikeKeyedData<TheoPoint>> theos)
IReadOnlyDictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>> theos)
{
if (sc_data is null || theos is null)
{
@@ -207,7 +207,7 @@ namespace mbts.spark
TheoPoint tp = s_kv.third;
// TODO: fix exchange later
Tuple<uint?, uint?> keys =
sc_data.get_option_sec_id(Venue.Deribit, symbol, exp, strike);
sc_data.get_option_sec_id(symbol.Item2, symbol.Item1, exp, strike);
if (keys != null)
{
var c_key = keys.Item1;
@@ -358,7 +358,7 @@ namespace mbts.spark
return;
}
mbts.analytics.VolSurfaceSettings vs_settings = _waiting_creations.Dequeue();
IDictionary<string, IEnumerable<DateTime>> exp_map = _contract_data.get_option_expirations(VolSurfaceDataFunctions.get_symbols(vs_settings), false);
var exp_map = _contract_data.get_option_expirations(VolSurfaceDataFunctions.get_symbols(vs_settings), false);
VolSurfaceInput vs_input = mbts.analytics.VolSurfaceDataFunctions.get_default_vs_input(vs_settings, exp_map);
var reply = _analytics_service.get_new_volsurface_id(new VoidMessage());
if (!reply.Ok)
@@ -37,7 +37,7 @@ namespace mbts.spark {
}
private static IDictionary<UInt32, DriverMD> _get_drivers(
IReadOnlyDictionary<string, OptionDriverPriceMap> driver_map,
IReadOnlyDictionary<(string, Venue), OptionDriverPriceMap> driver_map,
SystemContractData sc_data) {
var rv = new Dictionary<UInt32, DriverMD>();
foreach (var kv in driver_map) {
@@ -48,7 +48,7 @@ namespace mbts.spark {
}
private static IEnumerable<Tuple<SecurityImmutable, TheoPoint>> _get_theos(
IReadOnlyDictionary<string, OptionTheoInterpolationData> theo_data,
IReadOnlyDictionary<(string, Venue), OptionTheoInterpolationData> theo_data,
SystemContractData sc_data) {
var rv = new List<Tuple<SecurityImmutable, TheoPoint>>();
foreach (var kv in theo_data) {
@@ -58,11 +58,11 @@ namespace mbts.spark {
return rv;
}
private IReadOnlyDictionary<string, OptionTheoInterpolationData>
_filter_for_publish(IReadOnlyDictionary<string, OptionTheoInterpolationData> all_theos) {
private IReadOnlyDictionary<(string, Venue), OptionTheoInterpolationData>
_filter_for_publish(IReadOnlyDictionary<(string, Venue), OptionTheoInterpolationData> all_theos) {
// find the symbol vs vs_id, get the committed vs, see if it is
// owned by the current user, and only then publish it
HashSet<string> syms = new HashSet<string>();
var syms = new HashSet<(string, Venue)>();
var usage = _bb.read_state(SparkTags.VolSurfaceUsageTag);
string current_user = _bb.read_state(SparkTags.CurrentUser).name;
foreach (var u in (usage?.UsageList).empty_if_null()) {
@@ -71,7 +71,7 @@ namespace mbts.spark {
if (vs_input != null) {
if (vs_input.surface_settings.core_settings.vs_manager ==
current_user) {
syms.Add(u.SecTup.Symbol);
syms.Add((u.SecTup.Symbol, u.SecTup.Venue));
}
}
}
@@ -81,10 +81,8 @@ namespace mbts.spark {
private void _publish_data() {
SystemContractData sc_data = _bb.read_state(SparkTags.SystemContractsTag, null);
IReadOnlyDictionary<string, OptionTheoInterpolationData> all_theos =
_bb.read_state(SparkTags.AllInterpGreeks, null);
IReadOnlyDictionary<string, OptionDriverPriceMap> all_drivers =
_bb.read_state(SparkTags.AllOptionDriverBBOTag, null);
var all_theos = _bb.read_state(SparkTags.AllInterpGreeks, null);
var all_drivers = _bb.read_state(SparkTags.AllOptionDriverBBOTag, null);
if (sc_data == null || all_theos == null || all_drivers == null)
return;
var timer = Stopwatch.StartNew();
+11 -13
View File
@@ -13,9 +13,9 @@ namespace mbts.spark {
// Publishes theos for all options (on the side, also publishes the theos for TC2)
public class LiveTheoPublisher : IDisposable {
private ThreadedBlackboard _bb;
private readonly ITag<IReadOnlyDictionary<string, OptionTheoInterpolationData>>
private readonly ITag<IReadOnlyDictionary<(string, Venue), OptionTheoInterpolationData>>
_greeks_tag = SparkTags.AllInterpGreeks;
private readonly ITag<IReadOnlyDictionary<string, OptionDriverPriceMap>>
private readonly ITag<IReadOnlyDictionary<(string, Venue), OptionDriverPriceMap>>
_drivers_tag = SparkTags.AllOptionDriverBBOTag;
private readonly PerfStatsLogger _logger = new PerfStatsLogger(50, 100);
private readonly string _log_id = "LiveTheoPublisher";
@@ -84,17 +84,17 @@ namespace mbts.spark {
}
private static DriverMD _get_option_driver(
IReadOnlyDictionary<string, OptionDriverPriceMap> driver_map,
IReadOnlyDictionary<(string, Venue), OptionDriverPriceMap> driver_map,
SecurityStrike k) {
if (driver_map.TryGetValue(k.expiration.symbol, out var exp_map) &&
if (driver_map.TryGetValue((k.expiration.symbol, k.expiration.exchange), out var exp_map) &&
exp_map != null)
return exp_map.get_driver_md(k.expiration);
return DriverMD.empty;
}
private static TheoPoint _interp_theo(
IReadOnlyDictionary<string, OptionTheoInterpolationData> interp_greeks_map,
IReadOnlyDictionary<(string, Venue), OptionTheoInterpolationData> interp_greeks_map,
SecurityStrike k, double driver_price) {
if (interp_greeks_map.TryGetValue(k.expiration.symbol, out var interp_greeks) &&
if (interp_greeks_map.TryGetValue((k.expiration.symbol, k.expiration.exchange), out var interp_greeks) &&
interp_greeks != null)
return interp_greeks.interpolate_theos(k.expiration.expiration, k.strike,
driver_price);
@@ -102,14 +102,14 @@ namespace mbts.spark {
}
private void _publish_tc2_theos(IDictionary<SecurityStrike, TheoPoint> theos) {
var rv = new Dictionary<string, ExpStrikeKeyedData<TheoPoint>>();
var rv = new Dictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>>();
foreach (var kv in theos) {
SecurityStrike k = kv.Key;
TheoPoint tp = kv.Value;
ExpStrikeKeyedData<TheoPoint> sym_theos = null;
if (!rv.TryGetValue(k.expiration.symbol, out sym_theos)) {
if (!rv.TryGetValue((k.expiration.symbol, k.expiration.exchange), out sym_theos)) {
sym_theos = new ExpStrikeKeyedData<TheoPoint>();
rv.Add(k.expiration.symbol, sym_theos);
rv.Add((k.expiration.symbol, k.expiration.exchange), sym_theos);
}
sym_theos.set_data(k, tp);
}
@@ -122,10 +122,8 @@ namespace mbts.spark {
private void _interp_and_publish() {
var timer = Stopwatch.StartNew();
var res = new Dictionary<uint, GreeksTuple>();
IReadOnlyDictionary<string, OptionDriverPriceMap> driver_map =
_bb.read_state(_drivers_tag);
IReadOnlyDictionary<string, OptionTheoInterpolationData> interp_greeks =
_bb.read_state(SparkTags.AllInterpGreeks);
var driver_map = _bb.read_state(_drivers_tag);
var interp_greeks = _bb.read_state(SparkTags.AllInterpGreeks);
SystemContractData sc_data = _bb.read_state(SparkTags.SystemContractsTag);
if (driver_map == null || interp_greeks == null || sc_data == null) {
return;
@@ -102,9 +102,10 @@ namespace mbts.spark {
.GroupBy(kv => (kv.Value.driver_security.symbol, kv.Value.driver_security.exchange), kv => kv.Key);
public IDictionary<mbts.SecurityExpiration, mbts.SecurityExpiration>
get_option_to_driver_map(string option_name) {
get_option_to_driver_map(string option_name, Venue venue) {
var filt = exp_map.Where(kv => kv.Key.security_type == SecurityType.Option &&
kv.Key.symbol == option_name);
kv.Key.symbol == option_name &&
kv.Key.exchange == venue);
return filt.ToDictionary(kv => kv.Key, kv => kv.Value.driver_security);
}
@@ -33,8 +33,8 @@ namespace mbts.spark {
exp_price_map.GetValueOrDefault(exp) ?? DriverMD.empty;
public static IDictionary<VolSurfaceExpiration, DriverMD> get_vs_price_map(
IReadOnlyDictionary<string, OptionDriverPriceMap> all_sym_map,
Func<string, bool>? sym_filter = null
IReadOnlyDictionary<(string, Venue), OptionDriverPriceMap> all_sym_map,
Func<(string, Venue), bool>? sym_filter = null
) {
sym_filter ??= _ => true;
return all_sym_map.SafeWhere(kv => kv.Value is not null && sym_filter(kv.Key))
@@ -197,21 +197,21 @@ namespace mbts.spark {
return rv;
}
public IDictionary<DateTime, IEnumerable<double>> get_option_strikes(string option_name) {
return strike_map.Where(kv => kv.Key.symbol == option_name)
public IDictionary<DateTime, IEnumerable<double>> get_option_strikes(string option_name, Venue venue) {
return strike_map.Where(kv => kv.Key.symbol == option_name && kv.Key.exchange == venue)
.ToDictionary(kv => kv.Key.expiration, kv => kv.Value.Select(k => k.strike));
}
public IDictionary<SecurityExpiration, IEnumerable<double>>
get_option_strikes(HashSet<string> option_names) {
return strike_map.Where(kv => option_names.Contains(kv.Key.symbol))
get_option_strikes(HashSet<(string, Venue)> option_names) {
return strike_map.Where(kv => option_names.Contains((kv.Key.symbol, kv.Key.exchange)))
.ToDictionary(kv => kv.Key, kv => kv.Value.Select(k => k.strike));
}
public IEnumerable<DateTime> get_option_expirations(string option_name) {
public IEnumerable<DateTime> get_option_expirations(string option_name, Venue option_venue) {
foreach (var expGroup in expirationsIndex.Value) {
var (venue, type, symbol) = expGroup.Key;
if (type != SecurityType.Option || symbol != option_name) {
if (type != SecurityType.Option || symbol != option_name || venue != option_venue) {
continue;
}
foreach (var exp in expGroup.Value) {
@@ -220,8 +220,11 @@ namespace mbts.spark {
}
}
public IDictionary<string, IEnumerable<DateTime>> get_option_expirations(
IEnumerable<string> option_names, bool is_display_expiration) {
public IEnumerable<DateTime> get_option_expirations((string, Venue) option_symbol) =>
get_option_expirations(option_symbol.Item1, option_symbol.Item2);
public IDictionary<(string, Venue), IEnumerable<DateTime>> get_option_expirations(
IEnumerable<(string, Venue)> option_names, bool is_display_expiration) {
return option_names.ToDictionaryDupes(kv => kv, kv => get_option_expirations(kv));
}
@@ -13,7 +13,10 @@ public class VolSurfaceDriverGridVM : IDisposable {
public VolSurfaceDriverGridVM(VolSurfaceDriverVM driver) {
this.driver = driver;
_slaves_hook = ObservableAutoWrapper.connect(
driver.symbols, slaves, sym => new VolSurfaceSlaveVM(driver, sym));
driver.symbols,
slaves,
sym => new VolSurfaceSlaveVM(driver, new(bts.api.SecurityType.Option, sym.symbol, sym.venue)),
sym_vm => sym_vm.Dispose());
}
public VolSurfaceDriverVM driver { get; }
@@ -2,6 +2,8 @@ namespace mbts.spark;
using bts.api;
using mbts.analytics;
using System;
using System.Collections.ObjectModel;
@@ -13,7 +15,7 @@ public class VolSurfaceDriverVM : IEquatable<VolSurfaceDriverVM> {
public string name { get; }
public Venue exchange { get; }
public ObservableCollection<string> symbols { get; } = new();
public ObservableCollection<VolSurfaceSymbolVenueVM> symbols { get; } = new();
public bool Equals(VolSurfaceDriverVM other) =>
other != null && other.name == name && other.exchange == exchange;
@@ -1,6 +1,7 @@
namespace mbts.spark {
using bts;
using bts.api;
using bts.collections;
using mbts.analytics;
using mbts.ui;
@@ -75,19 +76,18 @@ namespace mbts.spark {
var symbols = symbol_structure_vm.driver_grids
.SelectMany(dg => dg.slaves.Where(sym => sym.is_selected))
.ToList();
_core_settings.master_slave_relationships = symbols
_core_settings.master_slave_relationships.SetItems(symbols
.Where(sym => sym.selected_master_symbols.Any())
.Select(sym => new VolSurfaceSymbolRelationship {
symbol = sym.name,
connected_symbols = sym.selected_master_symbols.ToList()
})
.ToList();
.Select(sym => VolSurfaceSymbolRelationship.create(
(sym.name, sym.venue),
sym.selected_master_symbols.Select(s => new SymbolVenue() { symbol = s.security_name, venue = s.security_exchange })
)));
_core_settings.implied_vol_marketdata_relationships = symbols
.Where(sym => sym.selected_fits.Any())
.Select(sym => new VolSurfaceSymbolRelationship {
symbol = sym.name,
connected_symbols = sym.selected_fits.ToList()
})
.Select(sym => VolSurfaceSymbolRelationship.create(
(sym.name, sym.venue),
sym.selected_fits.Select(s => new SymbolVenue() { symbol = s.security_name, venue = s.security_exchange})
))
.ToList();
vol_model_polynomial_vm.assign_to(_settings.polynomial_model_settings);
@@ -95,7 +95,9 @@ namespace mbts.spark {
vol_model_dual_quadratic_vm.assign_to(_settings.dualquadratic_model_settings);
vol_path_parabolic_vm.assign_to(_settings.core_settings.volpath_settings.parabolic_vol_path_settings);
_core_settings.symbol_pricing_model_map = symbols.Select(sym => Tuple.Create(sym.name, sym.pricing_model)).ToList();
foreach (var sym in symbols) {
_core_settings.symbol_pricing_model_map[(sym.name, sym.venue)] = sym.pricing_model;
}
_core_settings.put_rotation.strike_vol_movement_pairs = put_rotations
.Select(r => Tuple.Create(r.target_strike, r.move))
.ToList();
@@ -369,27 +371,27 @@ namespace mbts.spark {
.ToList();
var settings = new VolSurfaceSettings();
var core_settings = settings.core_settings;
core_settings.master_slave_relationships = symbols
core_settings.master_slave_relationships.SetItems(symbols
.Where(sym => sym.selected_master_symbols.Any())
.Select(sym => new VolSurfaceSymbolRelationship {
symbol = sym.name,
connected_symbols = sym.selected_master_symbols.ToList()
})
.ToList();
core_settings.implied_vol_marketdata_relationships = symbols
.Select(sym => VolSurfaceSymbolRelationship.create(
(sym.name, sym.venue),
sym.selected_master_symbols.Select(s => new SymbolVenue() { symbol = s.security_name, venue = s.security_exchange })
)));
core_settings.implied_vol_marketdata_relationships.SetItems(symbols
.Where(sym => sym.selected_fits.Any())
.Select(sym => new VolSurfaceSymbolRelationship {
symbol = sym.name,
connected_symbols = sym.selected_fits.ToList()
})
.ToList();
.Select(sym => VolSurfaceSymbolRelationship.create(
(sym.name, sym.venue),
sym.selected_fits.Select(s => new SymbolVenue() { symbol = s.security_name, venue = s.security_exchange })
)));
vol_model_polynomial_vm.assign_to(_settings.polynomial_model_settings);
vol_model_cubic_spline_vm.assign_to(_settings.spline_model_settings);
vol_model_dual_quadratic_vm.assign_to(_settings.dualquadratic_model_settings);
vol_path_parabolic_vm.assign_to(_settings.core_settings.volpath_settings.parabolic_vol_path_settings);
core_settings.symbol_pricing_model_map = symbols.Select(sym => Tuple.Create(sym.name, sym.pricing_model)).ToList();
foreach (var sym in symbols) {
_core_settings.symbol_pricing_model_map[(sym.name, sym.venue)] = sym.pricing_model;
}
core_settings.put_rotation.strike_vol_movement_pairs = put_rotations
.Select(r => Tuple.Create(r.target_strike, r.move))
.ToList();
@@ -1,5 +1,6 @@
namespace mbts.spark;
using bts.api;
using bts.collections;
using mbts.analytics;
@@ -13,22 +14,24 @@ using System;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using SecurityTuple = mbts.SecurityTuple;
public class VolSurfaceSlaveVM : DisposableViewModelBase, IEquatable<VolSurfaceSlaveVM> {
ImmutableList<string> _selected_fits = ImmutableList<string>.Empty;
ImmutableList<string> _selected_master_symbols = ImmutableList<string>.Empty;
ImmutableList<SecurityTuple> _selected_fits = ImmutableList<SecurityTuple>.Empty;
ImmutableList<SecurityTuple> _selected_master_symbols = ImmutableList<SecurityTuple>.Empty;
VolSurfaceEnums.VolSurfacePricingModel _pricing_model;
bool _is_selected;
public VolSurfaceSlaveVM(VolSurfaceDriverVM driver, string name) {
public VolSurfaceSlaveVM(VolSurfaceDriverVM driver, SecurityTuple security_tuple) {
this.driver = driver;
this.name = name;
this.security_tuple = security_tuple;
_dispose = Disposable.Create(
ObservableAutoWrapper.connect(driver.symbols, fit_items, s => new(s)),
ObservableAutoWrapper.connect(driver.symbols, fit_items, s => new(new(SecurityType.Option, s.symbol, s.venue))),
ObservableAutoWrapper.connect_item_hooks(fit_items, init_fit),
ObservableAutoWrapper.connect(driver.symbols, master_symbol_items, s => new(s)),
ObservableAutoWrapper.connect(driver.symbols, master_symbol_items, s => new(new(SecurityType.Option, s.symbol, s.venue))),
ObservableAutoWrapper.connect_item_hooks(master_symbol_items, init_master_symbol));
IDisposable init_master_symbol(SelectableItemVM<string> vm) {
IDisposable init_master_symbol(SelectableItemVM<SecurityTuple> vm) {
return vm.subscribe(on_is_selected_changed);
void on_is_selected_changed(bool is_selected) =>
@@ -37,7 +40,7 @@ public class VolSurfaceSlaveVM : DisposableViewModelBase, IEquatable<VolSurfaceS
: selected_master_symbols.RemoveSorted(vm.value);
}
IDisposable init_fit(SelectableItemVM<string> vm) {
IDisposable init_fit(SelectableItemVM<SecurityTuple> vm) {
return vm.subscribe(on_is_selected_changed);
void on_is_selected_changed(bool is_selected) =>
@@ -48,13 +51,16 @@ public class VolSurfaceSlaveVM : DisposableViewModelBase, IEquatable<VolSurfaceS
}
public VolSurfaceDriverVM driver { get; }
public string name { get; }
public SecurityTuple security_tuple { get; }
public string name => security_tuple.security_name;
public Venue venue => security_tuple.security_exchange;
public bool is_selected {
get => _is_selected;
set => Set(ref _is_selected, value);
}
public ImmutableList<string> selected_fits {
public ImmutableList<SecurityTuple> selected_fits {
get => _selected_fits;
private set {
if (_selected_fits != value) {
@@ -63,9 +69,9 @@ public class VolSurfaceSlaveVM : DisposableViewModelBase, IEquatable<VolSurfaceS
}
}
}
public ObservableCollection<SelectableItemVM<string>> fit_items { get; } = new();
public ObservableCollection<SelectableItemVM<SecurityTuple>> fit_items { get; } = new();
public ImmutableList<string> selected_master_symbols {
public ImmutableList<SecurityTuple> selected_master_symbols {
get => _selected_master_symbols;
private set {
if (_selected_master_symbols != value) {
@@ -74,7 +80,7 @@ public class VolSurfaceSlaveVM : DisposableViewModelBase, IEquatable<VolSurfaceS
}
}
}
public ObservableCollection<SelectableItemVM<string>> master_symbol_items { get; } = new();
public ObservableCollection<SelectableItemVM<SecurityTuple>> master_symbol_items { get; } = new();
public VolSurfaceEnums.VolSurfacePricingModel pricing_model {
get => _pricing_model;
@@ -21,7 +21,6 @@ public class VolSurfaceSymbolStructureVM : DisposableViewModelBase {
public VolSurfaceSymbolStructureVM(VolSurfaceSettings settings) {
_settings = settings;
_settings.core_settings.master_slave_relationships ??= new List<VolSurfaceSymbolRelationship>();
_settings.core_settings.implied_vol_marketdata_relationships ??= new List<VolSurfaceSymbolRelationship>();
_selected_driver_grid = backing<VolSurfaceDriverGridVM>(nameof(selected_driver_grid));
_dispose = Disposable.Create(
@@ -40,7 +39,7 @@ public class VolSurfaceSymbolStructureVM : DisposableViewModelBase {
public void on_exp_params_input(AnalyticsExpirationParametersMap data) {
var driver_groups = data.get_option_driver_symbol_map().ToDictionary(
g => g.Key,
g => g.Select(e => e.symbol).Distinct().Ordered().ToList());
g => g.Select(e => e.security_tuple).Distinct().Ordered().ToList());
bool init_with_settings = driver_grids.Count == 0;
driver_grids.RemoveWhere(dg => !driver_groups.ContainsKey((dg.driver.name, dg.driver.exchange)));
@@ -48,11 +47,11 @@ public class VolSurfaceSymbolStructureVM : DisposableViewModelBase {
driver_groups.OrderBy(kv => kv.Key),
dg => {
var driver = new VolSurfaceDriverVM(dg.Key.venue, dg.Key.symbol);
driver.symbols.SetItems(dg.Value);
driver.symbols.SetItems(dg.Value.Select(s => new VolSurfaceSymbolVenueVM(s.security_name, s.security_exchange)));
return new VolSurfaceDriverGridVM(driver);
},
(vm, dg) => {
vm.driver.symbols.sync_with(dg.Value);
vm.driver.symbols.sync_with(dg.Value.Select(s => new VolSurfaceSymbolVenueVM(s.security_name, s.security_exchange)));
return vm;
});
@@ -60,25 +59,27 @@ public class VolSurfaceSymbolStructureVM : DisposableViewModelBase {
return;
}
var sec_tuple_comp = EqualityComparer<SecurityTuple>.Default;
var price_models = _settings.core_settings.symbol_pricing_model_map;
if (price_models is null) {
return;
}
foreach (var sym in driver_grids.SelectMany(grid => grid.slaves)) {
if (_settings.core_settings.symbol_pricing_model_map is null) {
if (!price_models.TryGetValue((sym.name, sym.venue), out var pricing_model)) {
continue;
}
var pricing_model = _settings.core_settings.symbol_pricing_model_map.FirstOrDefault(pm => pm.Item1 == sym.name);
if (pricing_model != null) {
sym.is_selected = true;
sym.pricing_model = pricing_model.Item2;
var master_slaves = _settings.core_settings.master_slave_relationships.FirstOrDefault(msr => msr.symbol == sym.name);
if (master_slaves != null) {
foreach (var m in sym.master_symbol_items) {
m.is_selected = master_slaves.connected_symbols.Any(s => s == m.value);
}
sym.is_selected = true;
sym.pricing_model = pricing_model;
var master_slaves = _settings.core_settings.master_slave_relationships.FirstOrDefault(msr => msr.symbol == (sym.name, sym.venue));
if (master_slaves != null) {
foreach (var m in sym.master_symbol_items) {
m.is_selected = master_slaves.connected_symbols.Any(s => s == (m.value.security_name, m.value.security_exchange));
}
var implied_vols = _settings.core_settings.implied_vol_marketdata_relationships.FirstOrDefault(iv => iv.symbol == sym.name);
if (implied_vols != null) {
foreach (var f in sym.fit_items) {
f.is_selected = implied_vols.connected_symbols.Any(s => s == f.value);
}
}
var implied_vols = _settings.core_settings.implied_vol_marketdata_relationships.FirstOrDefault(iv => iv.symbol == (sym.name, sym.venue));
if (implied_vols != null) {
foreach (var f in sym.fit_items) {
f.is_selected = implied_vols.connected_symbols.Any(s => s == (f.value.security_name, f.value.security_exchange));
}
}
}
@@ -0,0 +1,34 @@
#nullable enable
namespace mbts.spark;
using bts;
using bts.api;
using System;
public class VolSurfaceSymbolVenueVM : IEquatable<VolSurfaceSymbolVenueVM>, ICloneable<VolSurfaceSymbolVenueVM> {
public VolSurfaceSymbolVenueVM(string? symbol, Venue venue) {
this.symbol = symbol;
this.venue = venue;
}
public string? symbol { get; }
public Venue venue { get; }
public VolSurfaceSymbolVenueVM Clone() =>
new(symbol, venue);
public bool Equals(VolSurfaceSymbolVenueVM? other) =>
other is not null
&& other.symbol == symbol
&& other.venue == venue;
public override bool Equals(object? obj) =>
Equals(obj as VolSurfaceSymbolVenueVM);
public override int GetHashCode() =>
HashCode.Combine(symbol, venue);
object ICloneable.Clone() =>
Clone();
}
@@ -165,16 +165,16 @@
void _update_points() {
var settings = _model.get_active_settings();
var master_symbols = settings == null ? new HashSet<string>() : VolSurfaceUtilityFunctions.get_master_symbols(settings);
var master_symbols = settings == null ? new HashSet<(string, Venue)>() : VolSurfaceUtilityFunctions.get_master_symbols(settings);
var committed_map = _get_exp_date_map(_model.get_committed_term_structure_map(), master_symbols);
var candidate_map = _get_exp_date_map(_model.get_candidate_term_structure_map(), master_symbols);
foreach (var s in graph_vm.series.Cast<IVolTermsSeries>()) s.update_points(s.is_committed ? committed_map : candidate_map);
}
Dictionary<DateTime, double> _get_exp_date_map(
IReadOnlyDictionary<VolSurfaceExpiration, double> exp_map, HashSet<string> master_symbols) =>
IReadOnlyDictionary<VolSurfaceExpiration, double> exp_map, HashSet<(string, Venue)> master_symbols) =>
exp_map.Where(kv => selected_symbols.Contains(kv.Key.symbol) &&
master_symbols.Contains(kv.Key.symbol))
master_symbols.Contains((kv.Key.symbol, kv.Key.venue)))
.ToDictionaryCrushed(kv => kv.Key.expiration, kv => kv.Value);
public class SymbolItem : IEquatable<SymbolItem> {
+2 -2
View File
@@ -18,8 +18,8 @@ namespace mbts.spark {
// returns true if the option_name is driven by vs_id
public static bool symbol_driven_by_vs(
this VolSurfaceUsageListImmutable list, string option_name, int vs_id) =>
list.UsageList.Any(u => u.SecTup.Symbol == option_name && u.VsId == vs_id);
this VolSurfaceUsageListImmutable list, (string, Venue) option_name, int vs_id) =>
list.UsageList.Any(u => (u.SecTup.Symbol, u.SecTup.Venue) == option_name && u.VsId == vs_id);
// returns all sec_tups that are driven by this vs_id
public static IEnumerable<bts.api.SecurityTuple> get_sectups(
@@ -77,7 +77,7 @@ namespace mbts.spark {
if (theos != null) {
var theo_map = _convert_theos(theos);
foreach (var kv in theo_map) {
string option_name = kv.Key;
var option_name = kv.Key;
if (_vs_usage_map.symbol_driven_by_vs(option_name, vs_id)) {
bts.Log.Gen.info(
"VolSurfaceInterpGreeksMultiplexer._read_theos_and_publish " +
@@ -89,15 +89,14 @@ namespace mbts.spark {
}
#region Stateless Helpers
private static IDictionary<string, OptionTheoInterpolationData> _convert_theos(
private static IDictionary<(string, Venue), OptionTheoInterpolationData> _convert_theos(
IDictionary<VolSurfaceExpiration, IEnumerable<Theos>> vs_theos) {
IDictionary<string, OptionTheoInterpolationData> rv =
new Dictionary<string, OptionTheoInterpolationData>();
var rv = new Dictionary<(string, Venue), OptionTheoInterpolationData>();
foreach (var kv in vs_theos) {
OptionTheoInterpolationData sym_data = null;
if (!rv.TryGetValue(kv.Key.symbol, out sym_data)) {
if (!rv.TryGetValue((kv.Key.symbol, kv.Key.venue), out sym_data)) {
sym_data = new OptionTheoInterpolationData(kv.Key.symbol);
rv.Add(kv.Key.symbol, sym_data);
rv.Add((kv.Key.symbol, kv.Key.venue), sym_data);
}
foreach (var t in kv.Value)
sym_data.set_data(kv.Key.expiration, t.driver,
@@ -0,0 +1,52 @@
#nullable enable
namespace mbts.analytics;
using bts.api;
using ProtoBuf;
using Spark.Core.Protobuf;
using System;
[ProtoContract]
public class SymbolVenue : IProtobuf<SymbolVenue> {
[ProtoMember(1)]
public string? symbol { get; set; }
[ProtoMember(2)]
public Venue venue { get; set; }
public SymbolVenue Clone() =>
new() {
symbol = symbol,
venue = venue
};
public bool Equals(SymbolVenue? other) =>
other is not null
&& other.symbol == symbol
&& other.venue == venue;
public override bool Equals(object? obj) =>
Equals(obj as SymbolVenue);
public override int GetHashCode() =>
HashCode.Combine(symbol, venue);
public static bool operator ==(SymbolVenue left, SymbolVenue right) =>
left is null ? right is null : left.Equals(right);
public static bool operator !=(SymbolVenue left, SymbolVenue right) =>
!(left == right);
public static implicit operator SymbolVenue((string symbol, Venue venue) tup) =>
new() {
symbol = tup.symbol,
venue = tup.venue
};
public static implicit operator (string symbol, Venue venue)(SymbolVenue symbol_venue) =>
(symbol_venue.symbol ?? string.Empty, symbol_venue.venue);
}
@@ -1,3 +1,5 @@
using Google.Protobuf.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -64,11 +66,11 @@ namespace mbts.analytics {
[ProtoBuf.ProtoMember(160)]
public List<VolSurfaceSymbolRelationship> symbol_implied_vol_marketdata_source_list;
[ProtoBuf.ProtoMember(170)]
public List<Tuple<string, VolSurfaceEnums.VolSurfacePricingModel>> symbol_pricing_model_map;
public MapField<SymbolVenue, VolSurfaceEnums.VolSurfacePricingModel> symbol_pricing_model_map { get; } = new();
[ProtoBuf.ProtoMember(180)]
public List<VolSurfaceSymbolRelationship> implied_vol_marketdata_relationships;
[ProtoBuf.ProtoMember(190)]
public List<VolSurfaceSymbolRelationship> master_slave_relationships;
public List<VolSurfaceSymbolRelationship> master_slave_relationships { get; } = new(1);
/// This tells how the abstract strike axis (moneyness, delta etc)
/// is converted to a real strike. That depends on vol and fwd.
/// This tells what vol and fwd to use for that.
@@ -1,6 +1,8 @@
#nullable enable
namespace mbts.analytics;
using bts.api;
using mbts.spark;
using System.Collections.Generic;
@@ -8,8 +10,8 @@ using System.Collections.Generic;
public class VolSurfaceStrikeMap {
public readonly IDictionary<VolSurfaceExpiration, IEnumerable<double>>? strike_map = null;
public VolSurfaceStrikeMap(IEnumerable<string> option_names, SystemContractData sc_data) {
var on_map = new HashSet<string>(option_names);
public VolSurfaceStrikeMap(IEnumerable<(string, Venue)> option_names, SystemContractData sc_data) {
var on_map = new HashSet<(string, Venue)>(option_names);
var aux_map = sc_data.get_option_strikes(on_map);
strike_map = aux_map.ToDictionaryCrushed(kv => new VolSurfaceExpiration(kv.Key), kv => kv.Value);
}
@@ -1,13 +1,24 @@
using ProtoBuf;
using System.Collections.Generic;
using System.Linq;
namespace mbts.analytics;
[ProtoContract(Name = "VolSurfaceSymbolRelationship")]
public class VolSurfaceSymbolRelationship {
[ProtoMember(10)]
public string symbol;
public SymbolVenue symbol { get; set; }
[ProtoMember(20)]
public List<string> connected_symbols;
public List<SymbolVenue> connected_symbols { get; set; } = new(1);
public static VolSurfaceSymbolRelationship create(SymbolVenue symbol, params SymbolVenue[] connected_symbols) =>
create(symbol, connected_symbols.AsEnumerable());
public static VolSurfaceSymbolRelationship create(SymbolVenue symbol, IEnumerable<SymbolVenue> connected_symbols) {
var rv = new VolSurfaceSymbolRelationship() { symbol = symbol };
rv.connected_symbols.AddRange(connected_symbols);
return rv;
}
}
@@ -1,4 +1,6 @@
using bts;
using bts.api;
using bts.collections;
using Spark.Core.Collections;
@@ -58,12 +60,12 @@ namespace mbts.analytics
};
}
public static VolSurfaceInput get_default_vs_input(VolSurfaceSettings vs_settings, IDictionary<string, IEnumerable<DateTime>> exp_list)
public static VolSurfaceInput get_default_vs_input(VolSurfaceSettings vs_settings, IDictionary<(string, Venue), IEnumerable<DateTime>> exp_list)
{
List<VolSurfaceExpiration> vs_exp_list = new List<VolSurfaceExpiration>();
foreach (KeyValuePair<string, IEnumerable<DateTime>> kv in exp_list)
foreach (var kv in exp_list)
foreach (DateTime exp in kv.Value)
vs_exp_list.Add(new VolSurfaceExpiration() { symbol = kv.Key, expiration = exp });
vs_exp_list.Add(new(SecurityType.Option, kv.Key.Item1, exp, kv.Key.Item2));
return get_default_vs_input(vs_settings, vs_exp_list);
}
@@ -225,9 +227,9 @@ namespace mbts.analytics
public static VolSurfaceEnums.VolSurfacePricingModel get_pricing_model(VolSurfaceSettings settings, VolSurfaceExpiration exp)
{
if (settings.core_settings.symbol_pricing_model_map != null)
foreach (Tuple<string, VolSurfaceEnums.VolSurfacePricingModel> t in settings.core_settings.symbol_pricing_model_map)
if (t.Item1 == exp.symbol)
return t.Item2;
foreach (var (sym, model) in settings.core_settings.symbol_pricing_model_map)
if (sym == (exp.symbol, exp.venue))
return model;
return VolSurfaceEnums.VolSurfacePricingModel.BlackScholes;
}
@@ -236,13 +238,13 @@ namespace mbts.analytics
return VolSurfaceUtilityFunctions.are_protos_equal(exp_params, VolSurfaceDataFunctions.get_default_curve_params(vs_settings));
}
public static IEnumerable<string> get_symbols(VolSurfaceInput vs_input)
public static IEnumerable<(string, Venue)> get_symbols(VolSurfaceInput vs_input)
{
return vs_input != null ? get_symbols(vs_input.surface_settings) : new string[] { };
return vs_input != null ? get_symbols(vs_input.surface_settings) : Enumerable.Empty<(string, Venue)>();
}
public static IEnumerable<string> get_symbols(VolSurfaceSettings vs_settings) =>
vs_settings.core_settings.symbol_pricing_model_map.empty_if_null().Select(i => i.Item1);
public static IEnumerable<(string, Venue)> get_symbols(VolSurfaceSettings vs_settings) =>
vs_settings.core_settings.symbol_pricing_model_map.empty_if_null().Select(i => (i.Key.symbol, i.Key.venue));
public static VolCurveParameters get_curve_parameters(VolSurfaceInput vs_input, VolSurfaceExpiration exp)
{
@@ -482,7 +484,7 @@ namespace mbts.analytics
private static void _force_distinct_connected_symbols(VolSurfaceSymbolRelationship vssr) {
var distinct_syms = vssr.connected_symbols.Distinct().ToList();
if (distinct_syms.Count != vssr.connected_symbols.Count)
vssr.connected_symbols = distinct_syms;
vssr.connected_symbols.SetItems(distinct_syms);
}
#endregion
@@ -373,17 +373,17 @@ namespace mbts.analytics {
/// <summary>
/// Puts VolSurfaceSymbolRelationship's into a map of symbol vs its connected symbols
/// </summary>
static IDictionary<string, HashSet<string>> _hash_relationship(
static IDictionary<(string, Venue), HashSet<(string, Venue)>> _hash_relationship(
VolSurfaceSettings vs_settings, IEnumerable<VolSurfaceSymbolRelationship> rels) {
var rv = rels.empty_if_null().ToDictionaryCrushed(
r => r.symbol, r => r.connected_symbols.ToHashSet());
r => (r.symbol.symbol, r.symbol.venue), r => r.connected_symbols.Select(s => (s.symbol, s.venue)).ToHashSet());
foreach (var s in VolSurfaceDataFunctions.get_symbols(vs_settings)) {
rv.GetOrAdd(s, _ => new HashSet<string>()).Add(s);
rv.GetOrAdd(s, _ => new()).Add(s);
}
return rv;
}
static HashSet<string> _get_slave_symbols(VolSurfaceSettings vs_settings) {
static HashSet<(string, Venue)> _get_slave_symbols(VolSurfaceSettings vs_settings) {
/// just all - masters
var slave_symbols = VolSurfaceDataFunctions.get_symbols(vs_settings).ToHashSet();
var master_symbols = get_master_symbols(vs_settings);
@@ -391,12 +391,12 @@ namespace mbts.analytics {
return slave_symbols;
}
static HashSet<string> _get_masters_for_symbol(VolSurfaceSettings vs_settings, string symbol) =>
static HashSet<(string, Venue)> _get_masters_for_symbol(VolSurfaceSettings vs_settings, string symbol, Venue venue) =>
_hash_relationship(
vs_settings, vs_settings.core_settings.master_slave_relationships)
.GetValueOrDefault(symbol) ?? new();
.GetValueOrDefault((symbol, venue)) ?? new();
public static HashSet<string> get_master_symbols(VolSurfaceSettings vs_settings) {
public static HashSet<(string, Venue)> get_master_symbols(VolSurfaceSettings vs_settings) {
var master_slaves = _hash_relationship(
vs_settings, vs_settings.core_settings.master_slave_relationships ?? new());
return master_slaves.Values.SelectMany().ToHashSet();
@@ -411,7 +411,7 @@ namespace mbts.analytics {
var master_symbols = get_master_symbols(vs_inp.surface_settings);
return vs_inp.surface_parameters.curve_parameters_map
.Where(t =>
master_symbols.Contains(t.Item1.symbol) ||
master_symbols.Contains((t.Item1.symbol, t.Item1.venue)) ||
(include_unlinked_slaves && t.Item2.core_parameters.unhinge_exp_from_master))
.Select(t => t.Item1)
.ToHashSet();
@@ -424,25 +424,25 @@ namespace mbts.analytics {
var slave_symbols = _get_slave_symbols(vs_inp.surface_settings);
return vs_inp.surface_parameters.curve_parameters_map
.Select(t => t.Item1)
.Where(t => slave_symbols.Contains(t.symbol))
.Where(t => slave_symbols.Contains((t.symbol, t.venue)))
.ToHashSet();
}
public static bool is_slave_expiration(
VolSurfaceExpiration vs_exp, VolSurfaceSettings vs_settings) =>
_get_slave_symbols(vs_settings).Contains(vs_exp.symbol);
_get_slave_symbols(vs_settings).Contains((vs_exp.symbol, vs_exp.venue));
public static bool is_master_expiration(
VolSurfaceExpiration vs_exp, VolSurfaceSettings vs_settings) =>
get_master_symbols(vs_settings).Contains(vs_exp.symbol);
get_master_symbols(vs_settings).Contains((vs_exp.symbol, vs_exp.venue));
public static VolSurfaceExpiration find_master_expiration(
VolSurfaceExpiration slave_vs_exp,
VolSurfaceSettings vs_settings,
IEnumerable<VolSurfaceExpiration> vs_exps
) {
var master_symbols = _get_masters_for_symbol(vs_settings, slave_vs_exp.symbol);
vs_exps = vs_exps.Where(e => master_symbols.Contains(e.symbol));
var master_symbols = _get_masters_for_symbol(vs_settings, slave_vs_exp.symbol, slave_vs_exp.venue);
vs_exps = vs_exps.Where(e => master_symbols.Contains((e.symbol, e.venue)));
VolSurfaceExpiration rv = find_nearest(vs_exps, slave_vs_exp, exp_date_diff) ??
new() { expiration = DateTime.MinValue };
/// TODO get this 2 from settings
@@ -457,10 +457,10 @@ namespace mbts.analytics {
var md_rel_map = _hash_relationship(
vs_input.surface_settings,
vs_input.surface_settings.core_settings.implied_vol_marketdata_relationships);
var source_symbols = md_rel_map.GetValueOrDefault(vs_exp.symbol) ?? new();
var source_symbols = md_rel_map.GetValueOrDefault((vs_exp.symbol, vs_exp.venue)) ?? new();
var source_exps = vs_input.surface_parameters.curve_parameters_map
.Select(t => t.Item1)
.Where(e => source_symbols.Contains(e.symbol));
.Where(e => source_symbols.Contains((e.symbol, e.venue)));
var rv = find_nearest(source_exps, vs_exp, exp_date_diff) ??
new() { expiration = DateTime.MinValue };
/// TODO get this from settings
@@ -5,6 +5,9 @@ using System.Text;
using System.Threading.Tasks;
using bts.api;
using bts.collections;
using mbts.spark;
using NUnit.Framework;
@@ -49,8 +52,6 @@ namespace mbts.analytics {
put_rotation = _get_movement_operation(VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike, VolSurfaceEnums.VolMovementTerms.Vol, Tuple.Create(-1.0, 1.0 / 100)),
full_rotation = _get_movement_operation(VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike, VolSurfaceEnums.VolMovementTerms.Vol, Tuple.Create(-0.75, 0.5 / 100), Tuple.Create(0.75, -0.5 / 100)),
strangle = _get_movement_operation(VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike, VolSurfaceEnums.VolMovementTerms.Vol, Tuple.Create(-0.75, 0.5 / 100), Tuple.Create(0.75, 0.5 / 100)),
symbol_pricing_model_map = Enumerable.Repeat(Tuple.Create("spx", VolSurfaceEnums.VolSurfacePricingModel.BlackScholes), 1).ToList(),
master_slave_relationships = Enumerable.Repeat(new VolSurfaceSymbolRelationship() { symbol = "spx", connected_symbols = new string[] { "spx" }.ToList() }, 1).ToList(),
vol_surface_model = VolSurfaceEnums.VolSurfaceModel.Polynomial,
volpath_settings = _get_volpath_settings(VolSurfaceEnums.VolSurfaceVolPathModel.TwoWaySlope),
wing_settings = _get_wing_settings(VolSurfaceEnums.VolCurveWingModel.ExplicitSlopeWithHorizontalAsymptotes, VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike),
@@ -73,6 +74,10 @@ namespace mbts.analytics {
}.ToList()
}
};
vs_input.surface_settings.core_settings.symbol_pricing_model_map.Add(
("spx", Venue.Cboe), VolSurfaceEnums.VolSurfacePricingModel.BlackScholes);
vs_input.surface_settings.core_settings.master_slave_relationships.Add(
VolSurfaceSymbolRelationship.create(("spx", Venue.Cboe), ("spx", Venue.Cboe)));
return vs_input;
}
/// The pattern for these tests that test the different
@@ -133,8 +138,6 @@ namespace mbts.analytics {
put_rotation = _get_movement_operation(VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike, VolSurfaceEnums.VolMovementTerms.Vol, Tuple.Create(-1.0, 1.0 / 100)),
full_rotation = _get_movement_operation(VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike, VolSurfaceEnums.VolMovementTerms.Vol, Tuple.Create(-0.75, 0.5 / 100), Tuple.Create(0.75, -0.5 / 100)),
strangle = _get_movement_operation(VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike, VolSurfaceEnums.VolMovementTerms.Vol, Tuple.Create(-0.75, 0.5 / 100), Tuple.Create(0.75, 0.5 / 100)),
symbol_pricing_model_map = Enumerable.Repeat(Tuple.Create("spx", VolSurfaceEnums.VolSurfacePricingModel.BlackScholes), 1).ToList(),
master_slave_relationships = Enumerable.Repeat(new VolSurfaceSymbolRelationship() { symbol = "spx", connected_symbols = new string[] { "spx" }.ToList() }, 1).ToList(),
vol_surface_model = VolSurfaceEnums.VolSurfaceModel.Polynomial,
volpath_settings = _get_volpath_settings(VolSurfaceEnums.VolSurfaceVolPathModel.TwoWaySlope),
wing_settings = _get_wing_settings(VolSurfaceEnums.VolCurveWingModel.ExplicitSlopeWithHorizontalAsymptotes, VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike),
@@ -157,6 +160,10 @@ namespace mbts.analytics {
}.ToList()
}
};
vs_input.surface_settings.core_settings.symbol_pricing_model_map.Add(
("spx", Venue.Cboe), VolSurfaceEnums.VolSurfacePricingModel.BlackScholes);
vs_input.surface_settings.core_settings.master_slave_relationships.Add(
VolSurfaceSymbolRelationship.create(("spx", Venue.Cboe), ("spx", Venue.Cboe)));
_test_meat_points(vs_exp, vs_input, exp_aux_data, exp_strikes);
_test_atm_vol_shift(vs_exp, vs_input, exp_aux_data, exp_strikes,
new VolCurveMovementOperation() { atm_strike_vol_movement = 1.0, target_terms = VolSurfaceEnums.VolMovementTerms.Vol });
@@ -200,8 +207,7 @@ namespace mbts.analytics {
/// Mostly for perf purposes, the data is not very consistent
internal static VolSurfaceInput get_generic_vs_input(IEnumerable<VolSurfaceExpiration> vs_exps) {
HashSet<string> syms = new HashSet<string>();
vs_exps.ToList().ForEach(e => syms.Add(e.symbol));
var syms = vs_exps.Select(e => (e.symbol, e.venue)).ToHashSet();
VolSurfaceExpirationAuxiliaryData exp_aux_data = _get_aux_data();
VolPathParameters exp_volpath_parameters = _get_two_way_slope_volpath_parameters(0.1 / 100.0, -0.1 / 100.0);
VolCurveCoreParameters exp_core_parameters = new VolCurveCoreParameters() {
@@ -237,13 +243,6 @@ namespace mbts.analytics {
put_rotation = _get_movement_operation(VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike, VolSurfaceEnums.VolMovementTerms.Vol, Tuple.Create(-1.0, 1.0 / 100)),
full_rotation = _get_movement_operation(VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike, VolSurfaceEnums.VolMovementTerms.Vol, Tuple.Create(-0.75, 0.5 / 100), Tuple.Create(0.75, -0.5 / 100)),
strangle = _get_movement_operation(VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike, VolSurfaceEnums.VolMovementTerms.Vol, Tuple.Create(-0.75, 0.5 / 100), Tuple.Create(0.75, 0.5 / 100)),
symbol_pricing_model_map = syms.Select(s => {
VolSurfaceEnums.VolSurfacePricingModel model = VolSurfaceEnums.VolSurfacePricingModel.BlackScholes;
if (s == "es" || s == "sp")
model = VolSurfaceEnums.VolSurfacePricingModel.Whaley;
return Tuple.Create(s, model);
}).ToList(),
master_slave_relationships = syms.Select(s => new VolSurfaceSymbolRelationship() { symbol = s, connected_symbols = Enumerable.Repeat<string>(s, 1).ToList() }).ToList(),
vol_surface_model = VolSurfaceEnums.VolSurfaceModel.Polynomial,
volpath_settings = _get_volpath_settings(VolSurfaceEnums.VolSurfaceVolPathModel.TwoWaySlope),
wing_settings = _get_wing_settings(VolSurfaceEnums.VolCurveWingModel.ExplicitSlopeWithHorizontalAsymptotes, VolSurfaceEnums.VolCurveStrikeAxis.StandardStrike)
@@ -258,6 +257,14 @@ namespace mbts.analytics {
})).ToList()
}
};
vs_input.surface_settings.core_settings.symbol_pricing_model_map.AddRange(
syms.Select(s => new KeyValuePair<SymbolVenue, VolSurfaceEnums.VolSurfacePricingModel>(
s, s.symbol switch {
"es" or "sp" => VolSurfaceEnums.VolSurfacePricingModel.Whaley,
_ => VolSurfaceEnums.VolSurfacePricingModel.BlackScholes
})));
vs_input.surface_settings.core_settings.master_slave_relationships.AddRange(
syms.Select(s => VolSurfaceSymbolRelationship.create(s, s)));
return vs_input;
}
@@ -1,4 +1,6 @@
using System;
using bts.api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -9,14 +11,16 @@ namespace BCG
public class NMSheetDriverData
{
public readonly string driver_symbol;
public readonly Venue driver_venue;
public readonly DateTime driver_expiration;
public readonly double driver_live_price;
public readonly double driver_price_at_computed_theo;
public readonly bool is_frozen;
public NMSheetDriverData(string the_driver_symbol, DateTime the_driver_expiration, double the_driver_live_price, double the_driver_price_at_computed_theo, bool the_is_frozen)
public NMSheetDriverData(string the_driver_symbol, Venue driver_venue, DateTime the_driver_expiration, double the_driver_live_price, double the_driver_price_at_computed_theo, bool the_is_frozen)
{
driver_symbol = the_driver_symbol;
this.driver_venue = driver_venue;
driver_expiration = the_driver_expiration;
driver_live_price = the_driver_live_price;
driver_price_at_computed_theo = the_driver_price_at_computed_theo;
@@ -49,9 +49,9 @@ namespace BCG {
/// input
_in_bb_main_sheet_request_tag = SparkTags.TC2Tags.NMSheetDataRequestTag(req_id.ToString());
_in_bb_secmap_tag = SparkTags.TC2Tags.ExchangeSecurityMapTag;
_in_bb_live_theos_tag = SparkTags.TC2Tags.LiveTheosTag(_nmsheet_symbol.option_name);
_in_bb_live_driver_bbo_tag = SparkTags.OptionDriverBBOTag(option.option_name);
_in_bb_precomputed_sparse_theos_tag = SparkTags.SymbolInterpGreeksTag(_nmsheet_symbol.option_name);
_in_bb_live_theos_tag = SparkTags.TC2Tags.LiveTheosTag((_nmsheet_symbol.option_name, _nmsheet_symbol.option_exchange));
_in_bb_live_driver_bbo_tag = SparkTags.OptionDriverBBOTag((option.option_name, option.option_exchange));
_in_bb_precomputed_sparse_theos_tag = SparkTags.SymbolInterpGreeksTag((_nmsheet_symbol.option_name, _nmsheet_symbol.option_exchange));
_in_bb_vol_shift_tag = SparkTags.TC2Tags.VolShiftTag(req_id.ToString());
_in_bb_sheet_settings_tag = SparkTags.TC2Tags.NMSheetSettingsTag(req_id.ToString());
_in_bb_main_sheet_visibility_tag = SparkTags.TC2Tags.NMSheetVisibilityTag(req_id.ToString());
@@ -96,9 +96,10 @@ namespace BCG {
double dr_pr = d.get_driver();
if (d.driver_security.HasValue)
return new NMSheetDriverData(d.driver_security.symbol_or_default(),
d.driver_security.exchange_or_default(),
d.driver_security.Value.security_expiration().Value,
dr_pr, dr_pr, false);
return new NMSheetDriverData(String.Empty, DateTime.MinValue, dr_pr, dr_pr, false);
return new NMSheetDriverData(String.Empty, Venue.Unset, DateTime.MinValue, dr_pr, dr_pr, false);
}
private void _compute_and_fire() {
@@ -191,17 +192,16 @@ namespace BCG {
private Dictionary<DateTime, NMSheetDriverData> _get_option_exp_driver_data_map(NMSheetDataRequest data_request,
ExpStrikeKeyedData<mbts.spark.TheoPoint> output_theo_data_map, ExpStrikeKeyedData<mbts.spark.TheoPoint> shared_live_theo_data_map,
Dictionary<DateTime, Triplet<string, DateTime, double>> live_driver_map) {
Dictionary<DateTime, Triplet<(string, Venue), DateTime, double>> live_driver_map) {
Dictionary<DateTime, NMSheetDriverData> rv = new Dictionary<DateTime, NMSheetDriverData>();
foreach (Triplet<NMSheetExpiration, bool, double> theo_request in data_request.expiration_request_list) {
DateTime option_expiration = theo_request.first.option_expiration;
/// live driver
Triplet<string, DateTime, double> live_driver_info;
live_driver_map.TryGetValue(option_expiration, out live_driver_info);
live_driver_info = live_driver_info ?? new Triplet<string, DateTime, double>(String.Empty, DateTime.MinValue, Double.NaN);
var live_driver_info = live_driver_map.GetValueOrDefault(option_expiration)
?? new((string.Empty, Venue.Unset), DateTime.MinValue, double.NaN);
/// computed driver
double computed_driver_price = _get_driverprice_for_expiration(output_theo_data_map, option_expiration);
rv[option_expiration] = new NMSheetDriverData(live_driver_info.first, live_driver_info.second, live_driver_info.third, computed_driver_price, theo_request.second);
rv[option_expiration] = new(live_driver_info.first.Item1, live_driver_info.first.Item2, live_driver_info.second, live_driver_info.third, computed_driver_price, theo_request.second);
}
return rv;
}
@@ -539,7 +539,7 @@ namespace BCG {
// string elec_equiv_symbol = ContractUtilities.get_electronic_equivelant(bts.o2.msgs.SecurityType.OPTION, contract.product);
// contract = new OptionContract(contract.exchange, elec_equiv_symbol, contract.expiration, contract.strike, contract.isCall);
// }
PriceSpec price_spec = new PriceSpec(contract.product, driver_data.driver_symbol,
var price_spec = new PriceSpec(contract.product, contract.exchange, driver_data.driver_symbol, driver_data.driver_venue,
driver_data.driver_expiration, 0, (driver_data.is_frozen && initial_state.preset_mode == SpreadWindowMode.Greeks) ?
driver_data.driver_price_at_computed_theo : -1, -1);
bts.Log.Ui.info(String.Format("NMSheetControls._add_spread_leg publishing AddSpreadLegMessage for contract: {0}",
+2
View File
@@ -27,6 +27,7 @@ namespace mbts {
security_key = 1;
security_type = security_expiration.security_type;
symbol = security_expiration.symbol;
venue = security_expiration.exchange;
expiration = security_expiration.expiration;
this.strike = strike ?? double.NaN;
this.security_expiration = security_expiration;
@@ -50,6 +51,7 @@ namespace mbts {
public uint security_key { get; }
public SecurityType security_type { get; }
public string symbol { get; }
public Venue venue { get; }
public DateTime? expiration { get; }
public double strike { get; }
public SecurityExpiration? security_expiration { get; }
+1
View File
@@ -11,6 +11,7 @@ namespace mbts {
uint security_key { get; }
SecurityType security_type { get; }
string symbol { get; }
Venue venue { get; }
DateTime? expiration { get; }
double strike { get; }
SecurityExpiration? security_expiration { get; }
@@ -130,7 +130,7 @@ namespace mbts.analytics {
private IEnumerable<PNLTradeRow> _create_pnl_rows(
IEnumerable<mbts.ITradeLogRow> trades,
IReadOnlyDictionary<string, ExpStrikeKeyedData<TheoPoint>> option_theos,
IReadOnlyDictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>> option_theos,
IReadOnlyDictionary<SecurityExpiration, FutureTheoStructure> future_theos,
IReadOnlyDictionary<uint, SecurityMD> md) {
trades = trades.Where(t => t.is_active);
@@ -213,9 +213,9 @@ namespace mbts.analytics {
private TheoPoint _get_option_theo(
ITradeLogRow tl,
IReadOnlyDictionary<string, ExpStrikeKeyedData<TheoPoint>> opt_theos) {
IReadOnlyDictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>> opt_theos) {
ExpStrikeKeyedData<TheoPoint> sym_theos = null;
if (opt_theos.TryGetValue(tl.symbol, out sym_theos)) {
if (opt_theos.TryGetValue((tl.symbol, tl.venue), out sym_theos)) {
var rv = sym_theos.get_data(tl.expiration.Value, tl.strike);
if (rv != null)
return rv;
+3
View File
@@ -21,6 +21,7 @@ namespace mbts {
user_id = m_fill.UserId;
security_type = sec.security_type();
symbol = sec.Symbol;
venue = sec.Exchange;
expiration = sec.security_expiration();
strike = sec.strike();
call_put = sec.HasOption ? sec.Option.CallPut : null;
@@ -51,6 +52,7 @@ namespace mbts {
user_id = 0;
security_type = sec.security_type();
symbol = sec.Symbol;
venue = sec.Exchange;
expiration = sec.security_expiration();
strike = sec.strike();
call_put = sec.HasOption ? sec.Option.CallPut : null;
@@ -78,6 +80,7 @@ namespace mbts {
public uint security_key { get; }
public SecurityType security_type { get; }
public string symbol { get; }
public Venue venue { get; }
public DateTime? expiration { get; }
public double strike { get; }
public SecurityExpiration? security_expiration { get; }
@@ -6,6 +6,8 @@ using mbts.ui;
using bts.api;
using mbts;
using SecurityTuple = mbts.SecurityTuple;
namespace BCG {
// Exposes one function compute(SpreadSpec) -> SpreadValue.
// In response gathers the data from the bus and calls
@@ -15,7 +17,7 @@ namespace BCG {
public class SimpleSpreadCalculator : IDisposable {
private ThreadedBlackboard _bb;
public Action on_recompute;
private readonly ITag<IReadOnlyDictionary<string, OptionDriverPriceMap>> _option_driver_price_tag =
private readonly ITag<IReadOnlyDictionary<(string, Venue), OptionDriverPriceMap>> _option_driver_price_tag =
SparkTags.AllOptionDriverBBOTag;
public SimpleSpreadCalculator(ThreadedBlackboard bb) {
@@ -44,6 +46,7 @@ namespace BCG {
}
private double _get_option_position(string option_symbol,
Venue venue,
DateTime exp, double strike, bool is_call) {
// TODO
return Double.NaN;
@@ -55,75 +58,77 @@ namespace BCG {
}
private void _fill_enhanced_price(SpreadSpec spec, SpreadValue sv,
Dictionary<string, Dictionary<DateTime, Triplet<string, DateTime, double>>> driver_price_map,
Dictionary<string, ExpStrikeKeyedData<TheoPoint>> live_theo_map) {
Dictionary<(string, Venue), Dictionary<DateTime, Triplet<(string, Venue), DateTime, double>>> driver_price_map,
Dictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>> live_theo_map) {
// TODO
}
#region Getters for drivers, theos, precomputed sparse theos
private static Triplet<string, DateTime, double> _from_drivermd(DriverMD dmd) {
return new Triplet<string, DateTime, double>(
dmd.driver_security != null ?
private static Triplet<(string, Venue), DateTime, double> _from_drivermd(DriverMD dmd) {
return new(
(dmd.driver_security != null ?
dmd.driver_security.symbol_or_default() : String.Empty,
dmd.driver_security?.Exchange ?? Venue.Unset),
dmd.driver_security != null ?
dmd.driver_security.Value.security_expiration().Value : DateTime.MinValue,
dmd.get_driver());
}
// Gets the option driver map or a single option name
private Dictionary<DateTime, Triplet<string, DateTime, double>>
_get_option_driver_map(string option_name) {
IReadOnlyDictionary<string, OptionDriverPriceMap> all_sym_map =
_bb.read_state(SparkTags.AllOptionDriverBBOTag);
Dictionary<DateTime, Triplet<(string, Venue), DateTime, double>> _get_option_driver_map(string option_name, Venue venue) {
var all_sym_map = _bb.read_state(SparkTags.AllOptionDriverBBOTag);
OptionDriverPriceMap sym_data = null;
if (all_sym_map.TryGetValue(option_name, out sym_data) && sym_data != null) {
if (all_sym_map.TryGetValue((option_name, venue), out sym_data) && sym_data != null) {
var rv = sym_data.exp_price_map.ToDictionary(
kv => kv.Key.expiration,
kv => _from_drivermd(kv.Value));
return rv;
} else {
return new Dictionary<DateTime, Triplet<string, DateTime, double>>();
return new(0);
}
}
Dictionary<DateTime, Triplet<(string, Venue), DateTime, double>> _get_option_driver_map((string option_name, Venue venue) tup) =>
_get_option_driver_map(tup.option_name, tup.venue);
// Gets the driver map for each distinct option in the spread
private Dictionary<string, Dictionary<DateTime, Triplet<string, DateTime, double>>>
_get_driver_map(SpreadSpec spec) {
IReadOnlyDictionary<string, OptionDriverPriceMap> all_sym_map =
_bb.read_state(SparkTags.AllOptionDriverBBOTag);
return all_sym_map.ToDictionary(kv => kv.Key, kv => _get_option_driver_map(kv.Key));
Dictionary<(string, Venue), Dictionary<DateTime, Triplet<(string, Venue), DateTime, double>>> _get_driver_map(SpreadSpec spec) {
var all_sym_map = _bb.read_state(SparkTags.AllOptionDriverBBOTag);
return all_sym_map.Keys.ToDictionary(_ => _, _get_option_driver_map);
}
// Gets the ExpStrikeKeyedData<TheoPoint> for each unique option name in spec
private Dictionary<string, ExpStrikeKeyedData<TheoPoint>> _get_live_theo_map(SpreadSpec spec) {
var rv = new Dictionary<string, ExpStrikeKeyedData<TheoPoint>>();
private Dictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>> _get_live_theo_map(SpreadSpec spec) {
var rv = new Dictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>>();
foreach (OptionContractPosition l in spec.contracts)
if (!rv.ContainsKey(l.contract.product)) {
if (!rv.ContainsKey((l.contract.product, l.contract.exchange))) {
ExpStrikeKeyedData<TheoPoint> sym_theos =
_bb.read_state(SparkTags.TC2Tags.LiveTheosTag(l.contract.product)) ??
_bb.read_state(SparkTags.TC2Tags.LiveTheosTag((l.contract.product, l.contract.exchange))) ??
new ExpStrikeKeyedData<TheoPoint>();
rv.Add(l.contract.product, sym_theos);
rv.Add((l.contract.product, l.contract.exchange), sym_theos);
}
return rv;
}
private Dictionary<string, OptionTheoInterpolationData> _get_interpolation_map(SpreadSpec spec) {
private Dictionary<(string, Venue), OptionTheoInterpolationData> _get_interpolation_map(SpreadSpec spec) {
return new(_bb.read_state(SparkTags.AllInterpGreeks));
}
private Dictionary<string, Dictionary<DateTime, FutureTheoStructure>>
private Dictionary<(string, Venue), Dictionary<DateTime, FutureTheoStructure>>
_get_live_future_theo_map(SpreadSpec spec) {
var rv = new Dictionary<string, Dictionary<DateTime, FutureTheoStructure>>();
var rv = new Dictionary<(string, Venue), Dictionary<DateTime, FutureTheoStructure>>();
IReadOnlyDictionary<SecurityExpiration, FutureTheoStructure> fut_theo_map =
_bb.read_state(SparkTags.TC2Tags.LiveFutureTheosTag);
if (fut_theo_map != null)
foreach (var kv in fut_theo_map) {
string sym = kv.Key.symbol;
var venue = kv.Key.exchange;
Dictionary<DateTime, FutureTheoStructure> sym_map;
if (!rv.TryGetValue(sym, out sym_map)) {
if (!rv.TryGetValue((sym, venue), out sym_map)) {
sym_map = new Dictionary<DateTime, FutureTheoStructure>();
rv.Add(sym, sym_map);
rv.Add((sym, venue), sym_map);
}
sym_map[kv.Key.expiration] = kv.Value;
}
@@ -134,4 +139,4 @@ namespace BCG {
public void Dispose() { _bb.data_callback += _on_data; }
}
}
}
@@ -18,12 +18,12 @@ namespace BCG {
public class StatelessSpreadCalculator {
private static SpreadValue _empty_sv = SpreadValue.get_nulled_sv();
#region Public Interface
public static SpreadValue compute_any_spread(SpreadSpec spread_spec, Dictionary<string, ExpStrikeKeyedData<TheoPoint>> live_theo_map,
Dictionary<string, OptionTheoInterpolationData> sparse_theo_map,
Dictionary<string, Dictionary<DateTime, Triplet<string, DateTime, double>>> driver_map,
Dictionary<string, Dictionary<DateTime, FutureTheoStructure>> future_theo_map,
Func<string, DateTime, double, bool, int, Pair<double, double>> get_leg_edge = null,
Func<string, DateTime, double, bool, double> get_option_position = null) {
public static SpreadValue compute_any_spread(SpreadSpec spread_spec, Dictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>> live_theo_map,
Dictionary<(string, Venue), OptionTheoInterpolationData> sparse_theo_map,
Dictionary<(string, Venue), Dictionary<DateTime, Triplet<(string, Venue), DateTime, double>>> driver_map,
Dictionary<(string, Venue), Dictionary<DateTime, FutureTheoStructure>> future_theo_map,
Func<string, Venue, DateTime, double, bool, int, Pair<double, double>> get_leg_edge = null,
Func<string, Venue, DateTime, double, bool, double> get_option_position = null) {
if (spread_spec == null || spread_spec.contracts == null || spread_spec.contracts.Length == 0)
return _empty_sv;
else {
@@ -48,13 +48,13 @@ namespace BCG {
double effective_driver;
mbts.spark.TheoPoint tp = _compute_single_option_leg(leg_sec, live_theo_map, sparse_theo_map, driver_map, future_theo_map, out effective_driver);
if (leg_sec.contract.isCall) {
Pair<double, double> leg_edge_pair = get_leg_edge == null ? null : get_leg_edge(leg_sec.contract.product, leg_sec.contract.expiration, leg_sec.contract.strike, true, i);
Pair<double, double> leg_edge_pair = get_leg_edge == null ? null : get_leg_edge(leg_sec.contract.product, leg_sec.contract.exchange, leg_sec.contract.expiration, leg_sec.contract.strike, true, i);
drivers[i] = effective_driver; theos[i] = tp.call; deltas[i] = tp.cdelta; gammas[i] = tp.cgamma; vegas[i] = tp.cvega; slope_vegas[i] = tp.c_slope_vega; adj_vegas[i] = tp.c_adj_vega; oevs[i] = tp.c_oev; thetas[i] = tp.c_theta; qs_midpoint_theos[i] = _get_leg_mid(tp.call, leg_edge_pair);
} else {
Pair<double, double> leg_edge_pair = get_leg_edge == null ? null : get_leg_edge(leg_sec.contract.product, leg_sec.contract.expiration, leg_sec.contract.strike, false, i);
Pair<double, double> leg_edge_pair = get_leg_edge == null ? null : get_leg_edge(leg_sec.contract.product, leg_sec.contract.exchange, leg_sec.contract.expiration, leg_sec.contract.strike, false, i);
drivers[i] = effective_driver; theos[i] = tp.put; deltas[i] = tp.pdelta; gammas[i] = tp.pgamma; vegas[i] = tp.pvega; slope_vegas[i] = tp.p_slope_vega; adj_vegas[i] = tp.p_adj_vega; oevs[i] = tp.p_oev; thetas[i] = tp.p_theta; qs_midpoint_theos[i] = _get_leg_mid(tp.put, leg_edge_pair);
}
pos[i] = get_option_position == null ? Double.NaN : get_option_position(leg_sec.contract.product, leg_sec.contract.expiration, leg_sec.contract.strike, leg_sec.contract.isCall);
pos[i] = get_option_position == null ? Double.NaN : get_option_position(leg_sec.contract.product, leg_sec.contract.exchange, leg_sec.contract.expiration, leg_sec.contract.strike, leg_sec.contract.isCall);
}
// TODO: put it as a setting
bts.Log.assert(theos.Length == drivers.Length);
@@ -149,26 +149,26 @@ namespace BCG {
/// this is the only relatively tricky thing here
private static mbts.spark.TheoPoint _compute_single_option_leg(OptionContractPosition spread_option_leg,
Dictionary<string, ExpStrikeKeyedData<mbts.spark.TheoPoint>> live_theo_map,
Dictionary<string, OptionTheoInterpolationData> sparse_theo_map,
Dictionary<string, Dictionary<DateTime, Triplet<string, DateTime, double>>> option_driver_data_map,
Dictionary<string, Dictionary<DateTime, FutureTheoStructure>> future_theo_map,
Dictionary<(string, Venue), ExpStrikeKeyedData<mbts.spark.TheoPoint>> live_theo_map,
Dictionary<(string, Venue), OptionTheoInterpolationData> sparse_theo_map,
Dictionary<(string, Venue), Dictionary<DateTime, Triplet<(string, Venue), DateTime, double>>> option_driver_data_map,
Dictionary<(string, Venue), Dictionary<DateTime, FutureTheoStructure>> future_theo_map,
out double effective_driver) {
///check to see if the option leg has the same driver
///instrument as the standard
Triplet<string, DateTime, double> driver_price_info = SpreadUtilities.get_option_driver_md(option_driver_data_map, spread_option_leg.contract.product, spread_option_leg.contract.expiration);
var driver_price_info = SpreadUtilities.get_option_driver_md(option_driver_data_map, spread_option_leg.contract.product, spread_option_leg.contract.exchange, spread_option_leg.contract.expiration);
PriceSpec leg_price_spec = spread_option_leg.legPriceSpec;
if (driver_price_info != null) {
ExpStrikeKeyedData<mbts.spark.TheoPoint> live_symbol_theo_map;
live_theo_map.TryGetValue(spread_option_leg.contract.product, out live_symbol_theo_map);
live_theo_map.TryGetValue((spread_option_leg.contract.product, spread_option_leg.contract.exchange), out live_symbol_theo_map);
OptionTheoInterpolationData symbol_sparse_theo_map;
sparse_theo_map.TryGetValue(spread_option_leg.contract.product, out symbol_sparse_theo_map);
sparse_theo_map.TryGetValue((spread_option_leg.contract.product, spread_option_leg.contract.exchange), out symbol_sparse_theo_map);
if (leg_price_spec == null) {
/// a leg with a null price spec is considered live
mbts.spark.TheoPoint tp = _compute_single_option_leg_at_live_price(spread_option_leg.contract.expiration, spread_option_leg.contract.strike, spread_option_leg.contract.isCall, live_symbol_theo_map);
effective_driver = tp.driver;
return tp;
} else if (leg_price_spec.primaryDriverSymbol == driver_price_info.first) {
} else if ((leg_price_spec.primaryDriverSymbol, leg_price_spec.primaryDriverVenue) == driver_price_info.first) {
if (leg_price_spec.driverExpiration == driver_price_info.second) {
/// the option is driven by its real driver
if (leg_price_spec.primaryFrozen) /// tied
@@ -483,7 +483,7 @@ namespace BCG {
foreach (SingleSpreadLeg l in legs) {
DateTime mapped_exp = mbts.ui.utility.ExpirationFormatter.convert_real_to_mapped((l.callPut == 'C' || l.callPut == 'P') ? SecurityType.Option : SecurityType.Future,
l.symbol, l.exp);
mapped_legs.Add(new SingleSpreadLeg(l.symbol, mapped_exp, l.strike, l.callPut, l.size));
mapped_legs.Add(new(l.symbol, l.venue, mapped_exp, l.strike, l.callPut, l.size));
}
return mapped_legs.ToArray();
}
+13 -3
View File
@@ -3,37 +3,47 @@ using System;
using BCG;
using BCG.Utilities;
using bts.api;
namespace BCG {
public class PriceSpec : ICloneable {
private PriceSpec(string product,
Venue venue,
double primary,
double secondary) {
bts.Log.assert(product != null && product != "");
bts.Log.assert(venue != Venue.Unset);
{
this.product = product;
this.venue = venue;
this.primary = primary;
bts.Log.assert(secondary == -1, "Secondary is retired");
}
}
public PriceSpec(string theProduct, string theDriverSymbol, DateTime theDriverExp,
public PriceSpec(string theProduct, Venue venue, string theDriverSymbol, Venue driverVenue, DateTime theDriverExp,
double theDriverSize, double thePrimaryPrice, double theSecondaryPrice)
: this(theProduct, thePrimaryPrice, theSecondaryPrice) {
: this(theProduct, venue, thePrimaryPrice, theSecondaryPrice) {
driverExpiration = theDriverExp;
primaryDriverSymbol = theDriverSymbol;
primaryDriverVenue = driverVenue;
primaryDriverSize = theDriverSize;
}
public readonly string product;
public readonly double primary; // a value <> -1 indicates primary frozen
public readonly Venue venue;
public readonly DateTime driverExpiration = DateTime.MinValue; // primaryDriverExpiration in reality
public readonly string primaryDriverSymbol = "ES";
public readonly Venue primaryDriverVenue;
public readonly double primaryDriverSize = 0;
public override bool Equals(object obj) {
if (obj != null && obj is PriceSpec) {
PriceSpec otherSpec = obj as PriceSpec;
return product == otherSpec.product && primary == otherSpec.primary &&
venue == otherSpec.venue &&
primaryDriverVenue == otherSpec.primaryDriverVenue &&
driverExpiration == otherSpec.driverExpiration &&
primaryDriverSymbol == otherSpec.primaryDriverSymbol &&
primaryDriverSize == otherSpec.primaryDriverSize;
@@ -48,7 +58,7 @@ namespace BCG {
public bool primaryFrozen { get { return primary != -1; } }
public object Clone() {
return new PriceSpec(product, primaryDriverSymbol, driverExpiration, primaryDriverSize, primary, -1);
return new PriceSpec(product, venue, primaryDriverSymbol, primaryDriverVenue, driverExpiration, primaryDriverSize, primary, -1);
}
}
}
@@ -1,3 +1,5 @@
using bts.api;
using System;
using System.Collections.Generic;
using System.Text;
@@ -7,19 +9,21 @@ namespace BCG
public class SingleSpreadLeg : IComparable
{
public string symbol;
public Venue venue;
public DateTime exp;
public double strike;
public char callPut;
public double size;
public SingleSpreadLeg(SingleSpreadLeg leg)
: this(leg.symbol, leg.exp, leg.strike, leg.callPut, leg.size)
: this(leg.symbol, leg.venue, leg.exp, leg.strike, leg.callPut, leg.size)
{ }
public SingleSpreadLeg(string theSymbol, DateTime theExp, double theStrike,
public SingleSpreadLeg(string theSymbol, Venue venue, DateTime theExp, double theStrike,
char theCallPut, double theSize)
{
symbol = theSymbol;
this.venue = venue;
exp = theExp;
strike = theStrike;
callPut = theCallPut;
@@ -33,12 +37,14 @@ namespace BCG
if(!stringRep.Contains(";"))
{
string[] toks = stringRep.Split(' ');
string symbol = toks[0];
DateTime exp = DateTime.Parse(toks[1]);
double strike = Double.Parse(toks[2]);
char callPut = char.Parse(toks[3]);
double size = Double.Parse(toks[4]);
return new SingleSpreadLeg[] { new SingleSpreadLeg(symbol, exp, strike, callPut, size) };
int i = 0;
string symbol = toks[i++];
Venue venue = Enum.Parse<Venue>(toks[i++], true);
DateTime exp = DateTime.Parse(toks[i++]);
double strike = Double.Parse(toks[i++]);
char callPut = char.Parse(toks[i++]);
double size = Double.Parse(toks[i++]);
return new SingleSpreadLeg[] { new(symbol, venue, exp, strike, callPut, size) };
}
else
{
@@ -148,6 +154,10 @@ namespace BCG
rv = callPut.CompareTo(other.callPut);
if (rv != 0)
return rv;
rv = venue.CompareTo(other.venue);
if (rv != 0) {
return rv;
}
return size.CompareTo(other.size);
}
else
@@ -160,10 +170,8 @@ namespace BCG
return (rv == 0);
}
public override int GetHashCode()
{
return symbol.GetHashCode() ^ exp.GetHashCode() ^ strike.GetHashCode() ^ callPut.GetHashCode();
}
public override int GetHashCode() =>
HashCode.Combine(symbol, venue, exp, strike, callPut);
#endregion
}
}
@@ -56,7 +56,7 @@ namespace BCG.OptSpreadSpec
static public string[] getAllSpecNames ()
{
List<string> rv = new List<string>();
SingleSpreadLeg[] consArgs = new SingleSpreadLeg[] { new SingleSpreadLeg("spx", DateTime.Now, 1000, 'C', 1) };
SingleSpreadLeg[] consArgs = new SingleSpreadLeg[] { new("spx", bts.api.Venue.Cboe, DateTime.Now, 1000, 'C', 1) };
foreach (Type t in getAllSpecTypes())
{
rv.Add((Activator.CreateInstance(t,new object[] {consArgs}) as SpreadSpecBase).longDescription);
+5 -5
View File
@@ -100,7 +100,7 @@ namespace BCG {
public SpreadSpec changeDriverPosition(double newPos) {
List<OptionContractPosition> newContracts = new List<OptionContractPosition>();
foreach (OptionContractPosition p in contracts)
newContracts.Add(new OptionContractPosition(p.contract, p.position, new PriceSpec(p.contract.product, p.legPriceSpec.primaryDriverSymbol, p.legPriceSpec.driverExpiration, newPos, p.legPriceSpec.primary, -1)));
newContracts.Add(new OptionContractPosition(p.contract, p.position, new PriceSpec(p.contract.product, p.contract.exchange, p.legPriceSpec.primaryDriverSymbol, p.legPriceSpec.primaryDriverVenue, p.legPriceSpec.driverExpiration, newPos, p.legPriceSpec.primary, -1)));
return new SpreadSpec(newContracts.ToArray(), longName, shortName, true);
}
@@ -133,7 +133,7 @@ namespace BCG {
PriceSpec newPriceSpec = null;
foreach (OptionContractPosition c in contracts) {
if (c.legPriceSpec.driverExpiration == futureExpDriver || TiedSpreadSymbolsHelper.is_associated(option_symbol, c.contract.product)) {
newPriceSpec = new PriceSpec(c.legPriceSpec.product, c.legPriceSpec.primaryDriverSymbol, c.legPriceSpec.driverExpiration, c.legPriceSpec.primaryDriverSize, driverPrice, -1);
newPriceSpec = new PriceSpec(c.legPriceSpec.product, c.legPriceSpec.venue, c.legPriceSpec.primaryDriverSymbol, c.legPriceSpec.primaryDriverVenue, c.legPriceSpec.driverExpiration, c.legPriceSpec.primaryDriverSize, driverPrice, -1);
rv.Add(new OptionContractPosition(c.contract, c.position, newPriceSpec));
} else
rv.Add(new OptionContractPosition(c.contract, c.position, c.legPriceSpec));
@@ -230,7 +230,7 @@ namespace BCG {
List<OptionContractPosition> legs = new List<OptionContractPosition>();
foreach (SingleSpreadLeg ol in option_spread_legs)
legs.Add(new OptionContractPosition(new OptionContract(exchange, ol.symbol, ol.exp, ol.strike, ol.isCall()), ol.size,
fl == null ? null : new PriceSpec(ol.symbol, fl.symbol, fl.exp, fl.size, fl.strike, -1)));
fl == null ? null : new PriceSpec(ol.symbol, ol.venue, fl.symbol, fl.venue, fl.exp, fl.size, fl.strike, -1)));
return new SpreadSpec(legs.ToArray());
}
@@ -243,11 +243,11 @@ namespace BCG {
List<SingleSpreadLeg> rv = new List<SingleSpreadLeg>();
foreach (OptionContractPosition p in spec.contracts) {
PriceSpec ps = p.legPriceSpec;
rv.Add(new SingleSpreadLeg(p.contract.product, p.contract.expiration, p.contract.strike, p.contract.isCall ? 'C' : 'P', p.position));
rv.Add(new SingleSpreadLeg(p.contract.product, p.contract.exchange, p.contract.expiration, p.contract.strike, p.contract.isCall ? 'C' : 'P', p.position));
if (ps != null && ps.primaryDriverSize != 0) {
if (!driver_included) {
driver_included = true;
rv.Add(new SingleSpreadLeg(ps.primaryDriverSymbol, ps.driverExpiration, ps.primary, 'F', ps.primaryDriverSize));
rv.Add(new(ps.primaryDriverSymbol, ps.primaryDriverVenue, ps.driverExpiration, ps.primary, 'F', ps.primaryDriverSize));
}
/// covered spread
}
+12 -12
View File
@@ -342,11 +342,11 @@ namespace BCG {
// BlueDataUtility.get_row_value<double>(option_driver_md_row, price_col_name, Double.NaN));
// }
public static Triplet<string, DateTime, double> get_option_driver_md(Dictionary<string, Dictionary<DateTime, Triplet<string, DateTime, double>>> option_driver_md_map,
string option_name, DateTime option_expiration) {
Dictionary<DateTime, Triplet<string, DateTime, double>> exp_data = null;
Triplet<string, DateTime, double> rv = null;
return (option_driver_md_map != null && option_driver_md_map.TryGetValue(option_name, out exp_data) && exp_data.TryGetValue(option_expiration, out rv)) ? rv : null;
public static Triplet<(string, Venue), DateTime, double> get_option_driver_md(Dictionary<(string, Venue), Dictionary<DateTime, Triplet<(string, Venue), DateTime, double>>> option_driver_md_map,
string option_name, Venue option_venue, DateTime option_expiration) {
Dictionary<DateTime, Triplet<(string, Venue), DateTime, double>> exp_data = null;
Triplet<(string, Venue), DateTime, double> rv = null;
return (option_driver_md_map != null && option_driver_md_map.TryGetValue((option_name, option_venue), out exp_data) && exp_data.TryGetValue(option_expiration, out rv)) ? rv : null;
}
// public static void fill_future_md_map(Dictionary<string, Dictionary<DateTime, double>> future_md_map, IBlueRow future_md_row)
@@ -362,10 +362,10 @@ namespace BCG {
// exp_data[future_exp_date] = BlueDataUtility.get_row_value<double>(future_md_row, "market_price", Double.NaN);
// }
public static double get_future_md(Dictionary<string, Dictionary<DateTime, double>> future_price_map, string future_name, DateTime future_expiration) {
public static double get_future_md(Dictionary<(string, Venue), Dictionary<DateTime, double>> future_price_map, string future_name, Venue future_venue, DateTime future_expiration) {
Dictionary<DateTime, double> exp_data = null;
double rv = Double.NaN;
return (future_price_map != null && future_price_map.TryGetValue(future_name, out exp_data) && exp_data.TryGetValue(future_expiration, out rv)) ? rv : Double.NaN;
return (future_price_map != null && future_price_map.TryGetValue((future_name, future_venue), out exp_data) && exp_data.TryGetValue(future_expiration, out rv)) ? rv : Double.NaN;
}
#endregion
@@ -373,7 +373,7 @@ namespace BCG {
public static SingleSpreadLeg[] convert_to_live_spread_legs(SpreadSpec spec) {
List<SingleSpreadLeg> rv = new List<SingleSpreadLeg>();
foreach (OptionContractPosition p in spec.contracts)
rv.Add(new SingleSpreadLeg(p.contract.product, p.contract.expiration, p.contract.strike, p.contract.isCall ? 'C' : 'P', p.position));
rv.Add(new SingleSpreadLeg(p.contract.product, p.contract.exchange, p.contract.expiration, p.contract.strike, p.contract.isCall ? 'C' : 'P', p.position));
return rv.ToArray();
}
@@ -568,10 +568,10 @@ namespace BCG {
public static SpreadSpec create_option_spread_spec(UInt32 spread_id,
SystemContractData sc_data,
IReadOnlyDictionary<string, OptionDriverPriceMap> driver_map) {
IReadOnlyDictionary<(string, Venue), OptionDriverPriceMap> driver_map) {
Func<SecurityImmutable, PriceSpec> get_price_spec = (sec) => {
OptionDriverPriceMap map = null;
if (!driver_map.TryGetValue(sec.Symbol, out map)) {
if (!driver_map.TryGetValue((sec.Symbol, sec.Exchange), out map)) {
return null;
}
DriverMD dmd = map.get_driver_md(sec.security_expiration().Value);
@@ -586,8 +586,8 @@ namespace BCG {
if (!dsec_exp.HasValue) {
return null;
}
return new PriceSpec(sec.Symbol, dsec.Value.Symbol,
dsec_exp.Value, 0, -1, -1);
return new(
sec.Symbol, sec.Exchange, dsec.Value.Symbol, dsec.Value.Exchange, dsec_exp.Value, 0, -1, -1);
};
SecurityMD sec_md;
if (!sc_data.sec_md_map.TryGetValue(spread_id, out sec_md)) {
+12 -12
View File
@@ -308,21 +308,21 @@ namespace mbts.spark {
// Driver prices for all exps belonging to a symbol
// Publisher: SingleOptionDriverPricePublisher
public static ITag<OptionDriverPriceMap> OptionDriverBBOTag(string option_symbol) =>
_mk_tag<OptionDriverPriceMap, string>(
public static ITag<OptionDriverPriceMap> OptionDriverBBOTag((string, Venue) option_symbol) =>
_mk_tag<OptionDriverPriceMap, (string, Venue)>(
option_symbol);
// This is an aggregation of the above, with an entry in the map
// for every symbol
// Publisher: SymbolAggregationPublisher
public static ITag<IReadOnlyDictionary<string, OptionDriverPriceMap>> AllOptionDriverBBOTag { get; } =
_mk_tag<IReadOnlyDictionary<string, OptionDriverPriceMap>>();
public static ITag<IReadOnlyDictionary<(string Symbol, Venue Venue), OptionDriverPriceMap>> AllOptionDriverBBOTag { get; } =
_mk_tag<IReadOnlyDictionary<(string, Venue), OptionDriverPriceMap>>();
public static ITag<AnalyticsExpirationParametersMap> ExpirationParametersInputTag { get; } =
_mk_tag<AnalyticsExpirationParametersMap>();
public static ITag<OptionTheoInterpolationData> SymbolInterpGreeksTag(string symbol) =>
_mk_tag<OptionTheoInterpolationData, string>(symbol);
public static ITag<OptionTheoInterpolationData> SymbolInterpGreeksTag((string, Venue) symbol) =>
_mk_tag<OptionTheoInterpolationData, (string, Venue)>(symbol);
public static ITag<IEnumerable<AnalyticsExpirationParameters>> ExpirationParametersCommitTag { get; } =
_mk_tag<IEnumerable<AnalyticsExpirationParameters>>();
@@ -342,8 +342,8 @@ namespace mbts.spark {
public static ITag<AnalyticsExpirationParametersSettings> show_analytics_exp_params { get; } =
_mk_tag<AnalyticsExpirationParametersSettings>();
public static ITag<IReadOnlyDictionary<string, OptionTheoInterpolationData>> AllInterpGreeks { get; } =
_mk_tag<IReadOnlyDictionary<string, OptionTheoInterpolationData>>();
public static ITag<IReadOnlyDictionary<(string Symbol, Venue Venue), OptionTheoInterpolationData>> AllInterpGreeks { get; } =
_mk_tag<IReadOnlyDictionary<(string, Venue), OptionTheoInterpolationData>>();
public static ITag<IReadOnlyDictionary<uint, GreeksTuple>> Greeks { get; } =
_mk_tag<IReadOnlyDictionary<uint, GreeksTuple>>();
@@ -383,13 +383,13 @@ namespace mbts.spark {
public static ITag<ExchangeSecurityMap> ExchangeSecurityMapTag { get; } =
_mk_tag<ExchangeSecurityMap>();
public static ITag<ExpStrikeKeyedData<TheoPoint>> LiveTheosTag(string symbol) =>
_mk_tag<ExpStrikeKeyedData<TheoPoint>, string>(symbol);
public static ITag<ExpStrikeKeyedData<TheoPoint>> LiveTheosTag((string, Venue) symbol) =>
_mk_tag<ExpStrikeKeyedData<TheoPoint>, (string, Venue)>(symbol);
// Aggregated version of the above
public static ITag<IReadOnlyDictionary<string, ExpStrikeKeyedData<TheoPoint>>>
public static ITag<IReadOnlyDictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>>>
AllLiveTheosTag { get; } =
_mk_tag<IReadOnlyDictionary<string, ExpStrikeKeyedData<TheoPoint>>>();
_mk_tag<IReadOnlyDictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>>>();
public static ITag<IReadOnlyDictionary<SecurityExpiration, FutureTheoStructure>>
LiveFutureTheosTag { get; } =