diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceClientPrecomputedTheosPublisher.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceClientPrecomputedTheosPublisher.cs
index bf48d6bb4..e8d034607 100644
--- a/src/client/spark/AW2/Bus/SingleVolSurfaceClientPrecomputedTheosPublisher.cs
+++ b/src/client/spark/AW2/Bus/SingleVolSurfaceClientPrecomputedTheosPublisher.cs
@@ -12,21 +12,21 @@ using bts.api;
namespace mbts.spark {
///
- /// This is the client version of SingleVolSurfaceServerPrecomputedTheosProvider.
- /// For a vs (and immutable list of option symbols)
- /// It listens to
- /// a. vol surface inputs
- /// b. exp params (roll, rates etc)
- /// c. securities (exp, strikes) for options in the vs
- /// d. driver prices for options in vs
- /// and passes the data above to VolSurfacePrecomputedTheosProducer where
- /// the real calculations take place
- ///
- /// It also monitors "publish_from_client". If a vs has
- /// that set to false, it no-ops the VolSurfacePrecomputedTheosProducer
- /// by passing a null. Otherwise it brings the VolSurfacePrecomputedTheosProducer
- /// to life, by passing a vs_input
- ///
+ // This is the client version of SingleVolSurfaceServerPrecomputedTheosProvider.
+ // For a vs (and immutable list of option symbols)
+ // It listens to
+ // a. vol surface inputs
+ // b. exp params (roll, rates etc)
+ // c. securities (exp, strikes) for options in the vs
+ // d. driver prices for options in vs
+ // and passes the data above to VolSurfacePrecomputedTheosProducer where
+ // the real calculations take place
+ //
+ // It also monitors "publish_from_client". If a vs has
+ // that set to false, it no-ops the VolSurfacePrecomputedTheosProducer
+ // by passing a null. Otherwise it brings the VolSurfacePrecomputedTheosProducer
+ // to life, by passing a vs_input
+ //
public class SingleVolSurfaceClientPrecomputedTheosPublisher : IDisposable {
private readonly int _vs_id;
private readonly IEnumerable _sym_map;
@@ -38,12 +38,15 @@ namespace mbts.spark {
private ITag _in_vs_standard_time_tag;
private ITag _in_ui_up_tag;
private VolSurfacePrecomputedTheosProducer _theo_producer = new VolSurfacePrecomputedTheosProducer();
+ // this is a buffer, that based on a setting can choose not to publish theos
private readonly SingleVolSurfaceClientTheosPublishHelper _local_publish_helper;
private readonly string _user;
private VolSurfaceInput _vs_input = null;
- public SingleVolSurfaceClientPrecomputedTheosPublisher(int vs_id, ThreadedBlackboard threaded_bb, IEnumerable symbols) {
+ public SingleVolSurfaceClientPrecomputedTheosPublisher(int vs_id,
+ ThreadedBlackboard threaded_bb, IEnumerable symbols) {
+ bts.Log.Gen.info($"SingleVolSurfaceClientPrecomputedTheosPublisher cons {vs_id}");
_vs_id = vs_id;
_sym_map = symbols;
_bb = threaded_bb;
@@ -58,9 +61,7 @@ namespace mbts.spark {
_in_vs_driver_price_map_tag = SparkTags.VolSurfaceOptionDriverTag(vs_id);
_in_vs_standard_time_tag = SparkTags.VolSurfaceStandardTimeTag(vs_id);
_in_ui_up_tag = SparkTags.VolSurfaceActiveUITag(_vs_id);
- //_in_active_sheet_exps_tag = new NMSheetTags.NMSheetActiveExpirationsTag();
_local_publish_helper = new SingleVolSurfaceClientTheosPublishHelper(vs_id, threaded_bb);
- //_in_bb_settings_tag = new ClickTradeSettingsTag();
_bb.subscribe(_in_vs_input_tag);
_bb.subscribe(_in_vs_nonvol_input_tag);
_bb.subscribe(_in_vs_contracts_tag);
@@ -73,64 +74,49 @@ namespace mbts.spark {
#region Blackboard Callbacks
private void _on_bb_data(object tag, object data) {
if (_in_vs_input_tag.Equals(tag)) {
- _vs_input = _bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceInput;
+ _vs_input = _bb.read_state(_in_vs_input_tag);
_theo_producer.set_vol_data(_vs_input);
} else if (_in_vs_nonvol_input_tag.Equals(tag))
- _theo_producer.set_nonvol_parameters((_bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceNonVolInput).exp_input_map);
- else if (_in_vs_contracts_tag.Equals(tag)) // || _in_active_sheet_exps_tag.Equals(tag))
+ _theo_producer.set_nonvol_parameters((_bb.read_state(_in_vs_nonvol_input_tag)).exp_input_map);
+ else if (_in_vs_contracts_tag.Equals(tag))
_set_contracts();
else if (_in_vs_driver_price_map_tag.Equals(tag))
- _theo_producer.set_driver_price(_bb.sec_thread_retrieve_from_cache(tag) as IDictionary);
+ _theo_producer.set_driver_price(_bb.read_state(_in_vs_driver_price_map_tag));
else if (_in_vs_standard_time_tag.Equals(tag))
- _theo_producer.set_system_vol_time(_bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceStandardTime);
+ _theo_producer.set_system_vol_time(_bb.read_state(_in_vs_standard_time_tag));
}
private void _set_contracts() {
- // this was filtering contracts for TC2
- // var all_contracts = _threaded_bb.sec_thread_retrieve_from_cache(_in_vs_contracts_tag) as IDictionary>;
- // if (all_contracts != null) {
- // HashSet active_sheet_exp_map = _threaded_bb.sec_thread_retrieve_from_cache(_in_active_sheet_exps_tag) as HashSet;
- // var filter_contracts = active_sheet_exp_map == null ? null : active_sheet_exp_map.Select(e => new VolSurfaceExpiration(e.nmsheet_symbol.option_name, e.option_expiration)).Where(e => all_contracts.ContainsKey(e)).ToDictionary(e => e, e => all_contracts[e]);
- // _theo_producer.set_contracts(all_contracts, _compute_theos_for_active_sheet_expirations_only ? filter_contracts : null);
- // }
+ // in edge this used to filter exps that were active in TC2
+ var all_contracts = _bb.read_state(_in_vs_contracts_tag);
+ if (all_contracts != null) {
+ _theo_producer.set_contracts(all_contracts.strike_map);
+ }
}
private bool _compute_theos_for_active_sheet_expirations_only {
- // this was an optimization to calculate theos for visible expirations only
- get {
- return false;
- // SymbolBasedSettingsManager click_trade_manager = _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_settings_tag) as SymbolBasedSettingsManager;
- // if (click_trade_manager != null) {
- // GeneralClickTradeSettings gen_settings = click_trade_manager.fetch_associated_general_settings();
- // if (gen_settings != null)
- // return gen_settings.compute_theos_for_active_sheet_expirations_only;
- // }
- // return false;
- }
+ // in edge this was optimized to calculate for active TC2 expirations only
+ get { return false; }
}
#endregion
private int _n_updates = 0;
- private void _theo_producer_on_theos(IDictionary> exp_theo_map, double vol_compute_time, double theo_compute_time) {
- int n_active_exps = exp_theo_map == null ? 0 : exp_theo_map.Where(kv => kv.Value != null && kv.Value.Count() > 0).Count();
- Log.Gen.info(String.Format("AW2 local compute # {0}, Exps = {1} Vol time = {2}, Theo time = {3}", ++_n_updates, n_active_exps, vol_compute_time, theo_compute_time));
+ private void _theo_producer_on_theos(IDictionary> exp_theo_map,
+ double vol_compute_time, double theo_compute_time) {
+ int n_active_exps = exp_theo_map == null ? 0 :
+ exp_theo_map.Where(kv => kv.Value != null && kv.Value.Count() > 0).Count();
+ Log.Gen.info(String.Format("AW2 local compute # {0}, Exps = {1} Vol time = {2}, Theo time = {3}",
+ ++_n_updates, n_active_exps, vol_compute_time, theo_compute_time));
+ bts.Log.Gen.info($"SingleVolSurfaceClientPrecomputedTheosPublisher._theo_producer_on_theos vs_id:{_vs_id} sz:{n_active_exps}");
_local_publish_helper.publish(exp_theo_map);
}
- private void _theo_producer_on_vols(IDictionary> exp_vol_map, double vol_compute_time, double theo_compute_time) {
- // Doesnt look like this is being used
- // bts.api.data.VolSurfaceLocalVols[] vols = new bts.api.data.VolSurfaceLocalVols[exp_vol_map.Count];
- // int idx = 0;
- // foreach (var entry in exp_vol_map) {
- // vols[idx++] = new bts.api.data.VolSurfaceLocalVols {
- // vs_id = _vs_id,
- // expiration = entry.Key.expiration,
- // symbol = entry.Key.symbol,
- // vols = entry.Value.Select(x => (bts.api.analytics.VolMatrix)x).ToArray()
- // };
- // }
- // _threaded_bb.sec_thread_write(new bts.api.data.VolSurfaceLocalVolsTag(_vs_id), vols);
+ private void _theo_producer_on_vols(
+ IDictionary> exp_vol_map,
+ double vol_compute_time, double theo_compute_time) {
+ // this was not used in edge
+ bts.Log.Gen.info($"SingleVolSurfaceClientPrecomputedTheosPublisher._theo_producer_on_vols sz:{exp_vol_map.Count()}");
}
#region IDisposable
diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceClientTheosPublishHelper.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceClientTheosPublishHelper.cs
index 89d44a60a..88ee9afc7 100644
--- a/src/client/spark/AW2/Bus/SingleVolSurfaceClientTheosPublishHelper.cs
+++ b/src/client/spark/AW2/Bus/SingleVolSurfaceClientTheosPublishHelper.cs
@@ -7,10 +7,10 @@ using System.Threading.Tasks;
using mbts.analytics;
namespace mbts.spark {
- /// This class is held by the SingleVolSurfaceClientPrecomputedTheosPublisher
- /// and acts as a buffer for publishing values. If wait_for_theo_confirmation
- /// setting is true, it publshes an alert tag, otherwise publishes the theos
- /// directly
+ // This class is held by the SingleVolSurfaceClientPrecomputedTheosPublisher
+ // and acts as a buffer for publishing values. If wait_for_theo_confirmation
+ // setting is true, it publshes an alert tag, otherwise publishes the theos
+ // directly
public class SingleVolSurfaceClientTheosPublishHelper {
private readonly int _vs_id;
private readonly ThreadedBlackboard _bb;
@@ -27,7 +27,8 @@ namespace mbts.spark {
_bb.post(SparkTags.VolSurfaceLocalTheosTag(_vs_id), exp_theo_map);
else {
if (_is_theo_acceptance_confirmation_on)
- _bb.post(SparkTags.VolSurfaceTheoAlertTag, new VolSurfaceTheoAlertData(Guid.NewGuid().ToString(), _vs_id, exp_theo_map));
+ _bb.post(SparkTags.VolSurfaceTheoAlertTag,
+ new VolSurfaceTheoAlertData(Guid.NewGuid().ToString(), _vs_id, exp_theo_map));
else
_bb.post(SparkTags.VolSurfaceLocalTheosTag(_vs_id), exp_theo_map);
}
@@ -36,15 +37,8 @@ namespace mbts.spark {
private bool _is_theo_acceptance_confirmation_on {
get {
- return true;
- // this was a setting when theos could be accepted or buffered
- // SymbolBasedSettingsManager click_trade_manager = _bb.sec_thread_retrieve_from_cache(new ClickTradeSettingsTag()) as SymbolBasedSettingsManager;
- // if (click_trade_manager != null) {
- // GeneralClickTradeSettings gen_settings = click_trade_manager.fetch_associated_general_settings();
- // if (gen_settings != null)
- // return gen_settings.theo_acceptance_confirmation;
- // }
- // return false;
+ // in edge this was in a TC2 setting
+ return false;
}
}
}
diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceManager.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceManager.cs
index e3e4a3c6e..c7d70917b 100644
--- a/src/client/spark/AW2/Bus/SingleVolSurfaceManager.cs
+++ b/src/client/spark/AW2/Bus/SingleVolSurfaceManager.cs
@@ -32,12 +32,13 @@ namespace mbts.spark {
a_syms => new SingleVolSurfaceCommittedOutputRetriever(vs_id, t_bb, a_syms)),
new SingleVolSurfaceDataSource(SingleVolSurfaceDataSource.SymbolListType.Candidate, vs_id, t_bb,
a_syms => new SingleVolSurfaceRequestCalculator(vs_id, a_syms, t_bb)),
- // new SingleVolSurfaceMarketImpliedVolSource(vs_id, t_bb),
+ new SingleVolSurfaceMarketImpliedVolSource(vs_id, t_bb),
new SingleVolSurfaceTheoSource(vs_id, t_bb),
+ // TODO: suspending heatmaps for now (12/24/21)
// new SingleVolSurfaceHeatmapManager (vs_id, t_bb),
// server work that can optionally be done on the client
- // TODO
- // new SingleVolSurfaceDataSource (SingleVolSurfaceDataSource.SymbolListType.Committed, vs_id, t_bb, a_syms => new SingleVolSurfaceClientPrecomputedTheosPublisher (vs_id, t_bb, a_syms)),
+ new SingleVolSurfaceDataSource (SingleVolSurfaceDataSource.SymbolListType.Committed, vs_id, t_bb,
+ a_syms => new SingleVolSurfaceClientPrecomputedTheosPublisher (vs_id, t_bb, a_syms)),
};
}
diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs
index c6be16188..c8f26c0eb 100644
--- a/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs
+++ b/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs
@@ -68,16 +68,17 @@ namespace mbts.spark {
private readonly PerfStatsLogger _logger = new PerfStatsLogger(50, 50);
private bool _is_dirty = true;
- public SingleVolSurfaceMarketImpliedVolSource(int volsurface_id, ThreadedBlackboard bb) {
- _vs_id = volsurface_id;
+ public SingleVolSurfaceMarketImpliedVolSource(int vs_id, ThreadedBlackboard bb) {
+ bts.Log.Gen.info($"SingleVolSurfaceMarketImpliedVolSource cons vs_id:{vs_id}");
+ _vs_id = vs_id;
_bb = bb;
_in_bb_sec_map_tag = SparkTags.SecuritiesTag;
- _in_bb_committed_output_tag = SparkTags.VolSurfaceCommittedOutputTag(volsurface_id);
- _in_bb_calc_resp_tag = SparkTags.VolSurfaceCalculationResponseTag(volsurface_id);
- _in_bb_inp_dirty_tag = SparkTags.VolSurfaceDirtyStateTag(volsurface_id);
+ _in_bb_committed_output_tag = SparkTags.VolSurfaceCommittedOutputTag(vs_id);
+ _in_bb_calc_resp_tag = SparkTags.VolSurfaceCalculationResponseTag(vs_id);
+ _in_bb_inp_dirty_tag = SparkTags.VolSurfaceDirtyStateTag(vs_id);
_in_bb_selected_exp_tag = SparkTags.VolSurfaceGridSelectionTag(_vs_id);
_in_bb_market_impliedvol_side_tag = SparkTags.VolSurfaceMarketImpliedVolSide(_vs_id);
- _in_bb_ignore_market_implied_vol_source_settings_tag = SparkTags.VolSurfaceIgnoreImpliedVolSettingsTag(volsurface_id);
+ _in_bb_ignore_market_implied_vol_source_settings_tag = SparkTags.VolSurfaceIgnoreImpliedVolSettingsTag(vs_id);
_bb.subscribe(_in_bb_committed_output_tag);
_bb.subscribe(_in_bb_calc_resp_tag);
_bb.subscribe(_in_bb_inp_dirty_tag);
@@ -86,6 +87,9 @@ namespace mbts.spark {
_bb.subscribe(_in_bb_ignore_market_implied_vol_source_settings_tag);
_bb.data_callback += _on_bb_data;
_bb.timer_callback += _on_bb_timer;
+ // TODO: mimicking the UI by posting a selected expiration
+ _bb.post(_in_bb_selected_exp_tag, Tuple.Create(new VolSurfaceDisplayGridExpiration("ew3", new DateTime(2022, 3, 18),
+ VolSurfaceEnums.VolSurfaceExpirationCalculationMethod.Master), true));
}
private void _on_bb_data(object tag, object data) {
@@ -98,9 +102,11 @@ namespace mbts.spark {
}
private void _check_bbo_change() {
- var sc_data = _bb.sec_thread_retrieve_from_cache(SparkTags.SystemContractsTag) as SystemContractData;
- Tuple sel_exp_tup = _bb.sec_thread_retrieve_from_cache(_in_bb_selected_exp_tag)
- as Tuple;
+ var sc_data = _bb.read_state(SparkTags.SystemContractsTag);
+ Tuple sel_exp_tup = _bb.read_state(_in_bb_selected_exp_tag);
+ if (sc_data == null || sel_exp_tup == null) {
+ return;
+ }
SecurityExpiration new_sel_exp = sel_exp_tup.Item1.ToVSExp().to_security_expiration();
var new_md = sc_data.get_option_bbo(new_sel_exp);
bool bbo_dirty = _cached_exp_md.set(new_sel_exp, new_md);
@@ -115,12 +121,13 @@ namespace mbts.spark {
}
private void _recompute_and_publish() {
- Tuple sel_exp = _bb.sec_thread_retrieve_from_cache(_in_bb_selected_exp_tag) as Tuple;
+ Tuple sel_exp = _bb.read_state(_in_bb_selected_exp_tag);
VolSurfaceOutput vs_output = _resolve_curr_cand();
if (vs_output != null && vs_output.volsurface_input != null && vs_output.aux_data_map != null &&
sel_exp != null && sel_exp.Item1 != null &&
- DateTime.Now.Subtract(_last_publish_time) >
- TimeSpan.FromMilliseconds(vs_output.volsurface_input.surface_settings.core_settings.market_fit_settings.graph_update_period_ms)) {
+ DateTime.Now.Subtract(_last_publish_time) > TimeSpan.FromMilliseconds(250)
+ // TODO
+ /*TimeSpan.FromMilliseconds(vs_output.volsurface_input.surface_settings.core_settings.market_fit_settings.graph_update_period_ms)*/) {
VolSurfaceEnums.MarketSide impliedvol_side = _get_market_impliedvol_side(_bb, _vs_id);
_last_publish_time = DateTime.Now;
_is_dirty = false;
@@ -138,8 +145,12 @@ namespace mbts.spark {
_ignore_market_implied_vol_source_settings(_bb, _vs_id), out md_exp);
_timer.stop();
_logger.log("SingleVolSurfaceMarketImpliedVolSource", "SingleVolSurfaceMarketImpliedVolSource", _timer.lastIntervalTime);
+ var sz = exp_impl_vol_map.put_rawk_vols.Count() + exp_impl_vol_map.call_rawk_vols.Count();
+ bts.Log.Gen.info($"SingleVolSurfaceMarketImpliedVolSource posting implied vols sz:{sz}");
_bb.post(SparkTags.VolSurfaceMarketImpliedVolTag(_vs_id),
- new Dictionary>() { { orig_exp, Tuple.Create(md_exp, exp_impl_vol_map) } });
+ new Dictionary>() {
+ { orig_exp, Tuple.Create(md_exp, exp_impl_vol_map) }
+ });
}
}
@@ -148,21 +159,20 @@ namespace mbts.spark {
object obj_is_dirty = _bb.sec_thread_retrieve_from_cache(_in_bb_inp_dirty_tag);
bool is_dirty = obj_is_dirty != null && (bool)obj_is_dirty;
if (is_dirty) {
- VolSurfaceCalculationResponse vs_resp = _bb.sec_thread_retrieve_from_cache(_in_bb_calc_resp_tag) as VolSurfaceCalculationResponse;
+ VolSurfaceCalculationResponse vs_resp = _bb.read_state(_in_bb_calc_resp_tag);
return vs_resp != null ? vs_resp.volsurface_calculation_output : null;
} else
- return _bb.sec_thread_retrieve_from_cache(_in_bb_committed_output_tag) as VolSurfaceOutput;
+ return _bb.read_state(_in_bb_committed_output_tag);
}
- private IDictionary> _get_bbo(
- VolSurfaceExpiration vs_exp) {
+ private IDictionary> _get_bbo(VolSurfaceExpiration vs_exp) {
return _get_bbo(_bb, vs_exp);
}
#region Static helpers
internal static IDictionary> _get_bbo(
- ThreadedBlackboard bb, VolSurfaceExpiration vs_exp) {
- var sc_data = bb.sec_thread_retrieve_from_cache(SparkTags.SystemContractsTag) as SystemContractData;
+ ThreadedBlackboard bb, VolSurfaceExpiration vs_exp) {
+ var sc_data = bb.read_state(SparkTags.SystemContractsTag);
return sc_data.get_option_bbo(vs_exp.to_security_expiration());
}
diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs
index 6ad8e5762..085661cff 100644
--- a/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs
+++ b/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs
@@ -10,6 +10,8 @@ using bts.api;
namespace mbts.spark {
// Publishes the committed and candidate greeks in the
// form of VolSurfaceTheoData
+ // (this was the data that was published in the winform syncfusion grid,
+ // with the cnaidate/committed next to each other)
// Subs :
// 1. Comm Vol Output
// 2. Cand Calc Response
@@ -59,9 +61,9 @@ namespace mbts.spark {
private void _on_timer() {
if (_is_dirty) {
- /// publishes new values when there is an
- /// 1. theos window up
- /// 2. waiting candidate change
+ // publishes new values when there is an
+ // 1. theos window up
+ // 2. waiting candidate change
_compute_and_publish(_is_active_candidate(), _is_active_theos_window());
_is_dirty = false;
}
diff --git a/src/client/spark/Analytics/Misc/VolSurfaceUtilityFunctions.cs b/src/client/spark/Analytics/Misc/VolSurfaceUtilityFunctions.cs
index 9be877085..b440313fb 100644
--- a/src/client/spark/Analytics/Misc/VolSurfaceUtilityFunctions.cs
+++ b/src/client/spark/Analytics/Misc/VolSurfaceUtilityFunctions.cs
@@ -433,6 +433,7 @@ namespace mbts.analytics {
/// Puts VolSurfaceSymbolRelationship's into a map of symbol vs its connected symbols
private static IDictionary> _hash_relationship(VolSurfaceSettings vs_settings, IEnumerable rels) {
+ rels = rels ?? new VolSurfaceSymbolRelationship[] { };
IDictionary> rv = rels.ToDictionary(r => r.symbol, r => new HashSet(r.connected_symbols.ToArray()));
foreach (string s in VolSurfaceDataFunctions.get_symbols(vs_settings))
if (!rv.ContainsKey(s) || rv[s] == null || rv[s].Count == 0)