All Bus subscribers are using the templatized subscriptions

This commit is contained in:
Taha Afzal authored and John Colvin committed 2021-12-21 14:31:19 -05:00
1 parent 9d8dba23b9
commit 145cf2d975
15 files changed
+157 -136

No files matched your search

@@ -31,7 +31,7 @@ namespace mbts.spark {
.ObserveOn(SynchronizationContext.Current)
.Subscribe(_on_exp_parameters);
_disposables.Add(exp_params_sub);
_bb.add_to_subscription_list(_in_bb_exp_params_commit_tag);
_bb.subscribe(_in_bb_exp_params_commit_tag);
_bb.data_callback += _on_bb_data;
}
@@ -27,7 +27,8 @@ namespace mbts.spark {
ThreadedBlackboard bb) {
_sec_tup = sec_tup;
_bb = bb;
_bb.add_to_subscription_list(_in_bb_exp_params_tag, _in_bb_contracts_tag);
_bb.subscribe(_in_bb_exp_params_tag);
_bb.subscribe(_in_bb_contracts_tag);
_bb.data_callback += _on_bb_data;
_bb.timer_callback += _on_bb_timer;
}
@@ -8,6 +8,7 @@ using System.Collections.Concurrent;
using System.IO;
using System.IO.Compression;
using bts;
using bts.api;
namespace mbts.spark {
/// <summary>
@@ -29,8 +30,13 @@ namespace mbts.spark {
public class SingleVolSurfaceClientPrecomputedTheosPublisher : IDisposable {
private readonly int _vs_id;
private readonly IEnumerable<string> _sym_map;
private readonly ThreadedBlackboard _threaded_bb;
private readonly object _in_vs_input_tag, _in_vs_nonvol_input_tag, _in_vs_contracts_tag, _in_vs_driver_price_map_tag, _in_vs_standard_time_tag, _in_ui_up_tag;//, _in_active_sheet_exps_tag, _in_bb_settings_tag;
private readonly ThreadedBlackboard _bb;
private readonly ITag<VolSurfaceInput> _in_vs_input_tag;
private ITag<VolSurfaceNonVolInput> _in_vs_nonvol_input_tag;
private ITag<VolSurfaceStrikeMap> _in_vs_contracts_tag;
private ITag<IDictionary<VolSurfaceExpiration, double>> _in_vs_driver_price_map_tag;
private ITag<VolSurfaceStandardTime> _in_vs_standard_time_tag;
private ITag<bool> _in_ui_up_tag;
private VolSurfacePrecomputedTheosProducer _theo_producer = new VolSurfacePrecomputedTheosProducer();
private readonly SingleVolSurfaceClientTheosPublishHelper _local_publish_helper;
private readonly string _user;
@@ -40,7 +46,7 @@ namespace mbts.spark {
public SingleVolSurfaceClientPrecomputedTheosPublisher(int vs_id, ThreadedBlackboard threaded_bb, IEnumerable<string> symbols) {
_vs_id = vs_id;
_sym_map = symbols;
_threaded_bb = threaded_bb;
_bb = threaded_bb;
// TODO
//_user = BlackboardSetup.current_user;
_user = String.Empty;
@@ -55,23 +61,28 @@ namespace mbts.spark {
//_in_active_sheet_exps_tag = new NMSheetTags.NMSheetActiveExpirationsTag();
_local_publish_helper = new SingleVolSurfaceClientTheosPublishHelper(vs_id, threaded_bb);
//_in_bb_settings_tag = new ClickTradeSettingsTag();
_threaded_bb.add_to_subscription_list(_in_vs_input_tag, _in_vs_nonvol_input_tag, _in_vs_contracts_tag, _in_vs_driver_price_map_tag, _in_vs_standard_time_tag, _in_ui_up_tag/*, _in_active_sheet_exps_tag, _in_bb_settings_tag*/);
_threaded_bb.data_callback += _on_bb_data;
_bb.subscribe(_in_vs_input_tag);
_bb.subscribe(_in_vs_nonvol_input_tag);
_bb.subscribe(_in_vs_contracts_tag);
_bb.subscribe(_in_vs_driver_price_map_tag);
_bb.subscribe(_in_vs_standard_time_tag);
_bb.subscribe(_in_ui_up_tag);
_bb.data_callback += _on_bb_data;
}
#region Blackboard Callbacks
private void _on_bb_data(object tag, object data) {
if (_in_vs_input_tag.Equals(tag)) {
_vs_input = _threaded_bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceInput;
_vs_input = _bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceInput;
_theo_producer.set_vol_data(_vs_input);
} else if (_in_vs_nonvol_input_tag.Equals(tag))
_theo_producer.set_nonvol_parameters((_threaded_bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceNonVolInput).exp_input_map);
_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))
_set_contracts();
else if (_in_vs_driver_price_map_tag.Equals(tag))
_theo_producer.set_driver_price(_threaded_bb.sec_thread_retrieve_from_cache(tag) as IDictionary<VolSurfaceExpiration, double>);
_theo_producer.set_driver_price(_bb.sec_thread_retrieve_from_cache(tag) as IDictionary<VolSurfaceExpiration, double>);
else if (_in_vs_standard_time_tag.Equals(tag))
_theo_producer.set_system_vol_time(_threaded_bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceStandardTime);
_theo_producer.set_system_vol_time(_bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceStandardTime);
}
private void _set_contracts() {
@@ -124,7 +135,7 @@ namespace mbts.spark {
#region IDisposable
public void Dispose() {
_threaded_bb.data_callback -= _on_bb_data;
_bb.data_callback -= _on_bb_data;
}
#endregion
}
@@ -4,9 +4,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using mbts.analytics;
using bts.api;
namespace mbts.spark
{
namespace mbts.spark {
/// <summary>
/// Publishes the vol outputs for a single vol surface.
/// Despite of the name Retriever, this class computes the vols
@@ -17,49 +17,46 @@ namespace mbts.spark
/// 3. VS nonvol Data
/// Pubs :
/// 1. VS Out
public class SingleVolSurfaceCommittedOutputRetriever : IDisposable
{
private readonly object _in_bb_vs_input_tag,
_in_bb_nonvol_data_tag,
_in_vs_standard_time_tag,
_out_bb_computed_vol_tag;
public class SingleVolSurfaceCommittedOutputRetriever : IDisposable {
private readonly ITag<VolSurfaceInput> _in_bb_vs_input_tag;
private readonly ITag<VolSurfaceNonVolData> _in_bb_nonvol_data_tag;
private readonly ITag<VolSurfaceStandardTime> _in_vs_standard_time_tag;
private readonly ITag<VolSurfaceOutput> _out_bb_computed_vol_tag;
private readonly ThreadedBlackboard _bb;
private readonly HighPerformanceTimer _timer = new HighPerformanceTimer();
private readonly PerfStatsLogger _logger = new PerfStatsLogger(50, 100);
private readonly string _log_id;
public SingleVolSurfaceCommittedOutputRetriever(int volsurface_id, ThreadedBlackboard threaded_bb, IEnumerable<string> symbols)
{
public SingleVolSurfaceCommittedOutputRetriever(int volsurface_id, ThreadedBlackboard threaded_bb, IEnumerable<string> symbols) {
_bb = threaded_bb;
_in_bb_vs_input_tag = SparkTags.VolSurfaceCommittedInputTag(volsurface_id);
_in_bb_nonvol_data_tag = SparkTags.VolSurfaceNonVolDataTag(volsurface_id);
_in_vs_standard_time_tag = SparkTags.VolSurfaceStandardTimeTag(volsurface_id);
_out_bb_computed_vol_tag = SparkTags.VolSurfaceCommittedOutputTag(volsurface_id);
_log_id = String.Format("SingleVolSurfaceCommittedOutputRetriever {0}", volsurface_id);
_bb.add_to_subscription_list(_in_bb_vs_input_tag, _in_bb_nonvol_data_tag, _in_vs_standard_time_tag);
_bb.subscribe(_in_bb_vs_input_tag);
_bb.subscribe(_in_bb_nonvol_data_tag);
_bb.subscribe(_in_vs_standard_time_tag);
_bb.data_callback += _on_bb_data;
_recompute_and_publish();
}
private void _on_bb_data(object tag, object data)
{
if (_in_bb_vs_input_tag.Equals(tag) || _in_bb_nonvol_data_tag.Equals(tag) || _in_vs_standard_time_tag.Equals (tag))
private void _on_bb_data(object tag, object data) {
if (_in_bb_vs_input_tag.Equals(tag) || _in_bb_nonvol_data_tag.Equals(tag) || _in_vs_standard_time_tag.Equals(tag))
_recompute_and_publish();
}
private void _recompute_and_publish()
{
private void _recompute_and_publish() {
VolSurfaceInput vs_input = _bb.sec_thread_retrieve_from_cache(_in_bb_vs_input_tag) as VolSurfaceInput;
VolSurfaceNonVolData vs_nonvol_data = _bb.sec_thread_retrieve_from_cache(_in_bb_nonvol_data_tag) as VolSurfaceNonVolData;
VolSurfaceStandardTime vs_standard_time = _bb.sec_thread_retrieve_from_cache(_in_vs_standard_time_tag) as VolSurfaceStandardTime;
if (vs_input != null && vs_nonvol_data != null && vs_standard_time != null)
{
if (vs_input != null && vs_nonvol_data != null && vs_standard_time != null) {
_timer.start();
IDictionary<VolSurfaceExpiration, VolSurfaceExpirationAuxiliaryData> aux_data_map = VolSurfaceUtilityFunctions.compute_aux_data(vs_input, vs_nonvol_data.input, vs_nonvol_data.driver_price_map, vs_standard_time);
VolSurfaceOutput vs_output = GeneralVolSurfaceCalculator.compute(vs_input, vs_nonvol_data.contracts, aux_data_map);
_timer.stop();
_logger.log(_log_id, _log_id, _timer.lastIntervalTime);
_bb.sec_thread_write(_out_bb_computed_vol_tag, vs_output);
_bb.sec_thread_write(_out_bb_computed_vol_tag, vs_output);
}
}
@@ -9,17 +9,14 @@ using bts.utils;
using bts.api;
namespace mbts.spark
{
namespace mbts.spark {
/// Listens to the input (either committed or candidate depending on the arg)
/// and creates the actual source that is immutable wrt the symbol list.
/// (Making the real sources immutable wrt to the symbol list simplifies
/// things a lot. Symbol lists rarely every change, but its a pain to
/// handle such changes)
public class SingleVolSurfaceDataSource : IDisposable
{
public enum SymbolListType
{
public class SingleVolSurfaceDataSource : IDisposable {
public enum SymbolListType {
Committed,
Candidate,
Combined,
@@ -28,54 +25,46 @@ namespace mbts.spark
private readonly int _vs_id;
private readonly ThreadedBlackboard _bb;
private readonly Func<IEnumerable<string>, IDisposable> _create_func;
private readonly object _in_bb_committed_data_tag, _in_bb_calc_req_tag;
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 IDisposable _source = null;
public SingleVolSurfaceDataSource(SymbolListType list_type, int vs_id, ThreadedBlackboard threaded_bb,
Func<IEnumerable<string>, IDisposable> create_func)
{
Func<IEnumerable<string>, IDisposable> create_func) {
Log.Gen.info(String.Format("SingleVolSurfaceDataSource constructed vs_id {0}", vs_id));
_list_type = list_type;
_vs_id = vs_id;
_vs_id = vs_id;
_bb = threaded_bb;
_create_func = create_func;
_in_bb_committed_data_tag = SparkTags.VolSurfaceCommittedInputTag(vs_id);
_in_bb_calc_req_tag = SparkTags.VolSurfaceCalculationRequestTag(vs_id);
_bb.add_to_subscription_list(_in_bb_committed_data_tag, _in_bb_calc_req_tag);
_bb.subscribe(_in_bb_committed_data_tag);
_bb.subscribe(_in_bb_calc_req_tag);
_bb.data_callback += _on_bb_data;
_recompute();
}
private void _on_bb_data(object tag, object data)
{
private void _on_bb_data(object tag, object data) {
if (_in_bb_committed_data_tag.Equals(tag) || _in_bb_calc_req_tag.Equals(tag))
_recompute();
}
private void _recompute()
{
private void _recompute() {
VolSurfaceCalculationRequest vs_calc_req = _bb.sec_thread_retrieve_from_cache(_in_bb_calc_req_tag) as VolSurfaceCalculationRequest;
VolSurfaceInput vs_comm_inp = _bb.sec_thread_retrieve_from_cache(_in_bb_committed_data_tag) as VolSurfaceInput;
if (_list_type == SymbolListType.Candidate)
{
if (vs_calc_req != null && vs_calc_req.volsurface_input != null)
{
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));
_create_if_needed(new_sym_map);
}
}
else if (_list_type == SymbolListType.Committed)
{
if (vs_comm_inp != null)
{
} 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));
_create_if_needed(new_sym_map);
}
}
else if (_list_type == SymbolListType.Combined)
{
} else if (_list_type == SymbolListType.Combined) {
List<string> new_sym_list = new List<string>();
if (vs_calc_req != null && vs_calc_req.volsurface_input != null)
new_sym_list.AddRange(VolSurfaceDataFunctions.get_symbols(vs_calc_req.volsurface_input));
@@ -85,23 +74,20 @@ namespace mbts.spark
}
}
private void _create_if_needed(HashSet<string> new_sym_map)
{
if (!CollectionHelper.hashset_equals(_option_symbols, new_sym_map))
{
private void _create_if_needed(HashSet<string> new_sym_map) {
if (!CollectionHelper.hashset_equals(_option_symbols, new_sym_map)) {
_option_symbols = new HashSet<string>(new_sym_map);
if (_source != null)
_source.Dispose();
_source = _create_func(_option_symbols);
_bb.sec_thread_write(SparkTags.AquireTag (Guid.NewGuid().ToString()),
_bb.sec_thread_write(SparkTags.AquireTag(Guid.NewGuid().ToString()),
new SymbolResourceAllocationUnit(
_option_symbols.Select(i => new mbts.SecurityTuple(SecurityType.Option, i, Venue.Unset)), this, true));
}
}
#region IDisposable
public void Dispose()
{
public void Dispose() {
if (_source != null)
_source.Dispose();
_bb.data_callback -= _on_bb_data;
@@ -8,6 +8,7 @@ using bts;
using bts.api.analytics;
using System.Reactive.Linq;
using System.Threading;
using bts.api;
using System.Collections;
namespace mbts.spark {
@@ -20,7 +21,7 @@ namespace mbts.spark {
public class SingleVolSurfaceGateway : IDisposable {
private readonly int _volsurface_id;
private readonly ThreadedBlackboard _threaded_bb;
private readonly object _in_bb_committ_tag;
private readonly ITag<VolSurfaceInput> _in_bb_committ_tag;
private AnalyticsService _analytics_service;
private readonly HighPerformanceTimer _timer = new HighPerformanceTimer();
private readonly string _user;
@@ -35,7 +36,7 @@ namespace mbts.spark {
_user = String.Empty; //BlackboardSetup.current_user; // TODO
_in_bb_committ_tag = SparkTags.VolSurfaceCommitTag(volsurface_id);
_analytics_service = analytics_service;
_threaded_bb.add_to_subscription_list(_in_bb_committ_tag);
_threaded_bb.subscribe(_in_bb_committ_tag);
_threaded_bb.data_callback += _on_bb_data;
var vs_sub = _analytics_service.subscribei_volsurfaces()
.ObserveOn(SynchronizationContext.Current)
@@ -5,19 +5,20 @@ using System.Text;
using System.Threading.Tasks;
using bts.api.analytics;
using bts.api;
using mbts.analytics;
namespace mbts.spark {
public class SingleVolSurfaceManager : IDisposable {
private IEnumerable<IDisposable> _resources;
private readonly object _in_bb_delete_tag = SparkTags.VolSurfaceDeleteTag;
private readonly ITag<int> _in_bb_delete_tag = SparkTags.VolSurfaceDeleteTag;
private readonly ThreadedBlackboard _threaded_bb;
public SingleVolSurfaceManager(int vs_id, ThreadedBlackboard t_bb, bts.api.IBus global_bus,
AnalyticsService analytics_service) {
_threaded_bb = t_bb;
_threaded_bb.add_to_subscription_list(_in_bb_delete_tag);
_threaded_bb.subscribe(_in_bb_delete_tag);
_threaded_bb.data_callback += _on_data;
_resources = new IDisposable[]
{
@@ -55,13 +55,13 @@ namespace mbts.spark {
}
#endregion
private readonly int _vs_id;
private readonly object _in_bb_sec_map_tag,
_in_bb_committed_output_tag,
_in_bb_calc_resp_tag,
_in_bb_inp_dirty_tag,
_in_bb_selected_exp_tag,
_in_bb_market_impliedvol_side_tag,
_in_bb_ignore_market_implied_vol_source_settings_tag;
private readonly ITag<IReadOnlyDictionary<uint, SecurityMD>> _in_bb_sec_map_tag;
private readonly ITag<mbts.analytics.VolSurfaceOutput> _in_bb_committed_output_tag;
private readonly ITag<VolSurfaceCalculationResponse> _in_bb_calc_resp_tag;
private readonly ITag<bool> _in_bb_inp_dirty_tag;
private readonly ITag<Tuple<VolSurfaceDisplayGridExpiration, bool>> _in_bb_selected_exp_tag;
private readonly ITag<mbts.analytics.VolSurfaceEnums.MarketSide> _in_bb_market_impliedvol_side_tag;
private readonly ITag<bool> _in_bb_ignore_market_implied_vol_source_settings_tag;
private CachedExpMD _cached_exp_md = new CachedExpMD();
private readonly ThreadedBlackboard _bb;
private readonly HighPerformanceTimer _timer = new HighPerformanceTimer();
@@ -78,9 +78,12 @@ namespace mbts.spark {
_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);
_bb.add_to_subscription_list(_in_bb_committed_output_tag, _in_bb_calc_resp_tag,
_in_bb_inp_dirty_tag, _in_bb_selected_exp_tag,
_in_bb_market_impliedvol_side_tag, _in_bb_ignore_market_implied_vol_source_settings_tag);
_bb.subscribe(_in_bb_committed_output_tag);
_bb.subscribe(_in_bb_calc_resp_tag);
_bb.subscribe(_in_bb_inp_dirty_tag);
_bb.subscribe(_in_bb_selected_exp_tag);
_bb.subscribe(_in_bb_market_impliedvol_side_tag);
_bb.subscribe(_in_bb_ignore_market_implied_vol_source_settings_tag);
_bb.data_callback += _on_bb_data;
_bb.timer_callback += _on_bb_timer;
}
@@ -3,31 +3,30 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using mbts.analytics;
namespace mbts.spark
{
using mbts.analytics;
using bts.api;
namespace mbts.spark {
/// Subs :
/// 1. Securities (AllBasicSecuritiesTag)
/// 2. Driver prices (VolSurfaceOptionDriverTag)
/// 3. NonVolInput (VolSurfaceNonVolInputTag)
/// Publishes :
/// 1. VolSurfaceNonVolData which is simply a union of the 3 inputs
public class SingleVolSurfaceNonVolDataSource : IDisposable
{
public class SingleVolSurfaceNonVolDataSource : IDisposable {
private readonly IEnumerable<string> _option_symbols;
private readonly ThreadedBlackboard _bb;
private readonly object _in_bb_contract_data_tag,
_in_bb_vs_nonvol_input_tag,
_in_bb_driver_price_tag,
_out_bb_vs_nonvol_data_tag,
_out_bb_vs_contracts_tag;
private readonly ITag<SystemContractData> _in_bb_contract_data_tag;
private readonly ITag<VolSurfaceNonVolInput> _in_bb_vs_nonvol_input_tag;
private readonly ITag<IDictionary<mbts.analytics.VolSurfaceExpiration, double>> _in_bb_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;
/// This is the only cached data to avoid computing it
/// when more frequently changing data move around
private IDictionary<VolSurfaceExpiration, IEnumerable<double>> _sec_map = new Dictionary<VolSurfaceExpiration, IEnumerable<double>>();
public SingleVolSurfaceNonVolDataSource(int vs_id, IEnumerable<string> option_symbols, ThreadedBlackboard bb)
{
public SingleVolSurfaceNonVolDataSource(int vs_id, IEnumerable<string> option_symbols, ThreadedBlackboard bb) {
_option_symbols = option_symbols;
_bb = bb;
_in_bb_contract_data_tag = SparkTags.SystemContractsTag;
@@ -35,14 +34,14 @@ namespace mbts.spark
_in_bb_driver_price_tag = SparkTags.VolSurfaceOptionDriverTag(vs_id);
_out_bb_vs_nonvol_data_tag = SparkTags.VolSurfaceNonVolDataTag(vs_id);
_out_bb_vs_contracts_tag = SparkTags.VolSurfaceContractsTag(vs_id);
_bb.add_to_subscription_list(_in_bb_contract_data_tag, _in_bb_vs_nonvol_input_tag, _in_bb_driver_price_tag);
_bb.subscribe(_in_bb_contract_data_tag);
_bb.subscribe(_in_bb_vs_nonvol_input_tag);
_bb.subscribe(_in_bb_driver_price_tag);
_bb.data_callback += _on_bb_data;
}
private void _on_bb_data(object tag, object data)
{
if (_in_bb_contract_data_tag.Equals(tag))
{
private void _on_bb_data(object tag, object data) {
if (_in_bb_contract_data_tag.Equals(tag)) {
SystemContractData contract_data = _bb.sec_thread_retrieve_from_cache(_in_bb_contract_data_tag) as SystemContractData;
_sec_map.Clear();
if (contract_data != null)
@@ -51,13 +50,11 @@ namespace mbts.spark
_sec_map[new VolSurfaceExpiration() { symbol = s, expiration = kv.Key }] = kv.Value;
_bb.sec_thread_write(_out_bb_vs_contracts_tag, _sec_map.ToDictionary(kv => kv.Key, kv => kv.Value.ToList() as IEnumerable<double>));
_recompute_and_fire();
}
else if (_in_bb_vs_nonvol_input_tag.Equals(tag) || _in_bb_driver_price_tag.Equals(tag))
} else if (_in_bb_vs_nonvol_input_tag.Equals(tag) || _in_bb_driver_price_tag.Equals(tag))
_recompute_and_fire();
}
private void _recompute_and_fire()
{
private void _recompute_and_fire() {
VolSurfaceNonVolInput vs_nonvol_input = _bb.sec_thread_retrieve_from_cache(_in_bb_vs_nonvol_input_tag) as VolSurfaceNonVolInput;
var price_map = _bb.sec_thread_retrieve_from_cache(_in_bb_driver_price_tag) as IDictionary<VolSurfaceExpiration, double>;
if (_sec_map != null && vs_nonvol_input != null && price_map != null)
@@ -21,7 +21,8 @@ namespace mbts.spark {
private IDictionary<VolSurfaceExpiration, double> _option_driver_price_map =
new Dictionary<VolSurfaceExpiration, double>();
private bool _option_driver_dirty = false;
private HashSet<object> _option_driver_price_tags = new HashSet<object>();
private HashSet<ITag<OptionDriverPriceMap>> _option_driver_price_tags =
new HashSet<ITag<OptionDriverPriceMap>>();
public SingleVolSurfaceOptionDriverSource(int vs_id,
@@ -34,7 +35,7 @@ namespace mbts.spark {
foreach (string o in _option_symbols) {
var tag = SparkTags.OptionDriverBBOTag(o);
_option_driver_price_tags.Add(tag);
_threaded_bb.add_to_subscription_list(tag);
_threaded_bb.subscribe(tag);
}
_threaded_bb.data_callback += _on_bb_data;
_threaded_bb.timer_callback += _on_timer;
@@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using bts.api;
using mbts.analytics;
namespace mbts.spark {
@@ -21,7 +23,11 @@ namespace mbts.spark {
private readonly int _vs_id;
private readonly HashSet<string> _symbols;
private readonly ThreadedBlackboard _threaded_bb;
private readonly object _in_bb_request_tag, _in_bb_dirty_tag, _in_bb_nonvol_data_tag, _in_bb_vs_standard_time_tag, _in_bb_market_impliedvol_side_tag;
private readonly ITag<VolSurfaceCalculationRequest> _in_bb_request_tag;
private readonly ITag<VolSurfaceNonVolData> _in_bb_nonvol_data_tag;
private readonly ITag<VolSurfaceStandardTime> _in_bb_vs_standard_time_tag;
private readonly ITag<VolSurfaceEnums.MarketSide> _in_bb_market_impliedvol_side_tag;
private readonly ITag<bool> _in_bb_dirty_tag;
private HighPerformanceTimer _timer = new HighPerformanceTimer();
/// data
private VolSurfaceOutput _last_output;
@@ -35,7 +41,11 @@ namespace mbts.spark {
_in_bb_vs_standard_time_tag = SparkTags.VolSurfaceStandardTimeTag(vs_id);
_in_bb_market_impliedvol_side_tag = SparkTags.VolSurfaceMarketImpliedVolSide(vs_id);
_in_bb_dirty_tag = SparkTags.VolSurfaceDirtyStateTag(vs_id);
_threaded_bb.add_to_subscription_list(_in_bb_request_tag, _in_bb_nonvol_data_tag, _in_bb_vs_standard_time_tag, _in_bb_vs_standard_time_tag, _in_bb_dirty_tag);
_threaded_bb.subscribe(_in_bb_request_tag);
_threaded_bb.subscribe(_in_bb_nonvol_data_tag);
_threaded_bb.subscribe(_in_bb_vs_standard_time_tag);
_threaded_bb.subscribe(_in_bb_vs_standard_time_tag);
_threaded_bb.subscribe(_in_bb_dirty_tag);
_threaded_bb.data_callback += _on_bb_data;
_recompute_and_publish(true);
}
@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using mbts.analytics;
using bts;
using bts.api;
namespace mbts.spark {
/// Publishes the committed and candidate greeks in the
@@ -18,21 +19,27 @@ namespace mbts.spark {
/// 1. VolSurfaceTheoData (cand and comm theos)
public class SingleVolSurfaceTheoSource : IDisposable {
private readonly int _volsurface_id;
private readonly ThreadedBlackboard _threaded_bb;
private readonly object _in_committed_vol_output_tag, _in_candidate_vol_output_tag, _in_input_dirty_tag, _in_window_state_tag;
private readonly ThreadedBlackboard _bb;
private readonly ITag<VolSurfaceOutput> _in_committed_vol_output_tag;
private readonly ITag<VolSurfaceCalculationResponse> _in_candidate_vol_output_tag;
private readonly ITag<bool> _in_input_dirty_tag;
private readonly ITag<bool> _in_window_state_tag;
private readonly HighPerformanceTimer _timer = new HighPerformanceTimer();
private bool _is_dirty = true;
public SingleVolSurfaceTheoSource(int volsurface_id, ThreadedBlackboard threaded_bb) {
_volsurface_id = volsurface_id;
_threaded_bb = threaded_bb;
_bb = threaded_bb;
_in_committed_vol_output_tag = SparkTags.VolSurfaceCommittedOutputTag(_volsurface_id);
_in_candidate_vol_output_tag = SparkTags.VolSurfaceCalculationResponseTag(_volsurface_id);
_in_input_dirty_tag = SparkTags.VolSurfaceDirtyStateTag(_volsurface_id);
_in_window_state_tag = SparkTags.VolSurfaceTheoWindowStateTag(_volsurface_id);
_threaded_bb.add_to_subscription_list(_in_committed_vol_output_tag, _in_candidate_vol_output_tag, _in_input_dirty_tag, _in_window_state_tag);
_threaded_bb.data_callback += _on_data;
_threaded_bb.timer_callback += _on_timer;
_bb.subscribe(_in_committed_vol_output_tag);
_bb.subscribe(_in_candidate_vol_output_tag);
_bb.subscribe(_in_input_dirty_tag);
_bb.subscribe(_in_window_state_tag);
_bb.data_callback += _on_data;
_bb.timer_callback += _on_timer;
}
#region Blackboard
@@ -55,9 +62,9 @@ namespace mbts.spark {
private static readonly IDictionary<VolSurfaceExpiration, IEnumerable<Theos>> _empty_theos = new Dictionary<VolSurfaceExpiration, IEnumerable<Theos>>();
private VolSurfaceTheoData _last_data = new VolSurfaceTheoData(new Dictionary<VolSurfaceExpiration, HashSet<double>>(), _empty_theos, _empty_theos, false);
private void _compute_and_publish(bool is_active_candidate, bool is_active_theos_window) {
VolSurfaceCalculationResponse calc_resp = _threaded_bb.sec_thread_retrieve_from_cache(_in_candidate_vol_output_tag) as VolSurfaceCalculationResponse;
VolSurfaceCalculationResponse calc_resp = _bb.sec_thread_retrieve_from_cache(_in_candidate_vol_output_tag) as VolSurfaceCalculationResponse;
VolSurfaceOutput candidate_output = calc_resp != null ? calc_resp.volsurface_calculation_output : null,
committed_output = _threaded_bb.sec_thread_retrieve_from_cache(_in_committed_vol_output_tag) as VolSurfaceOutput;
committed_output = _bb.sec_thread_retrieve_from_cache(_in_committed_vol_output_tag) as VolSurfaceOutput;
IDictionary<VolSurfaceExpiration, HashSet<double>> secs = _get_securities(committed_output, candidate_output);
IDictionary<VolSurfaceExpiration, IEnumerable<Theos>> comm_theo_map = _empty_theos, cand_theo_map = _empty_theos;
if (is_active_theos_window) {
@@ -70,7 +77,7 @@ namespace mbts.spark {
}
var new_data = new VolSurfaceTheoData(secs, comm_theo_map, cand_theo_map, is_active_candidate);
if (_is_valid_update(new_data))
_threaded_bb.sec_thread_write(SparkTags.VolSurfaceTheoOutputTag(_volsurface_id), new_data);
_bb.sec_thread_write(SparkTags.VolSurfaceTheoOutputTag(_volsurface_id), new_data);
}
private bool _is_valid_update(VolSurfaceTheoData new_data) {
@@ -109,19 +116,19 @@ namespace mbts.spark {
/// If the details window is not active, the calculations are suspended
private bool _is_active_theos_window() {
object rv_obj = _threaded_bb.sec_thread_retrieve_from_cache(_in_window_state_tag);
object rv_obj = _bb.sec_thread_retrieve_from_cache(_in_window_state_tag);
return rv_obj != null && (bool)rv_obj;
}
private bool _is_active_candidate() {
object rv_obj = _threaded_bb.sec_thread_retrieve_from_cache(_in_input_dirty_tag);
object rv_obj = _bb.sec_thread_retrieve_from_cache(_in_input_dirty_tag);
return rv_obj != null && (bool)rv_obj;
}
#region IDisposable
public void Dispose() {
_threaded_bb.data_callback -= _on_data;
_threaded_bb.timer_callback -= _on_timer;
_bb.data_callback -= _on_data;
_bb.timer_callback -= _on_timer;
}
#endregion
}
@@ -32,10 +32,10 @@ namespace mbts.spark {
private ThreadedBlackboard _threaded_bb;
private IVolSurfaceBroker _broker;
private bts.api.analytics.AnalyticsService _analytics_service;
private readonly object _in_bb_create_tag = SparkTags.VolSurfaceCreateTag,
_in_bb_contract_data_tag = SparkTags.SystemContractsTag,
_in_bb_delete_tag = SparkTags.VolSurfaceDeleteTag,
_in_bb_exp_params_tag = SparkTags.ExpirationParametersInputTag;
private readonly ITag<VolSurfaceSettings> _in_bb_create_tag = SparkTags.VolSurfaceCreateTag;
private readonly ITag<SystemContractData> _in_bb_contract_data_tag = SparkTags.SystemContractsTag;
private readonly ITag<int> _in_bb_delete_tag = SparkTags.VolSurfaceDeleteTag;
private readonly ITag<AnalyticsExpirationParametersMap> _in_bb_exp_params_tag = SparkTags.ExpirationParametersInputTag;
private IDictionary<int, SingleVolSurfaceManager> _vs_manager_map = new Dictionary<int, SingleVolSurfaceManager>();
private Queue<mbts.analytics.VolSurfaceSettings> _waiting_creations = new Queue<mbts.analytics.VolSurfaceSettings>();
private bts.api.IBus _bus;
@@ -48,9 +48,10 @@ namespace mbts.spark {
_broker = broker;
_analytics_service = analytics_service;
// subs to bb
_threaded_bb.add_to_subscription_list(_in_bb_contract_data_tag,
_in_bb_create_tag, _in_bb_delete_tag,
_in_bb_exp_params_tag);
_threaded_bb.subscribe(_in_bb_contract_data_tag);
_threaded_bb.subscribe(_in_bb_create_tag);
_threaded_bb.subscribe(_in_bb_delete_tag);
_threaded_bb.subscribe(_in_bb_exp_params_tag);
_threaded_bb.data_callback += _on_bb_update;
_threaded_bb.timer_callback += _on_timer;
// sub to service
@@ -5,6 +5,7 @@ using System.Linq;
using System.Reactive.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
using bts.api;
@@ -34,30 +35,34 @@ namespace mbts.spark {
public OnBBData data_callback;
public Action timer_callback;
public void add_to_subscription_list(params object[] tags) {
}
#region Templatized sub/write
public void add_to_subscription_list<T>(ITag<T> tag) {
var observable = _bus.subscribe(tag).OnDispatcher().Subscribe(
data => _on_bus_data(tag, data));
}
public void subscribe<T>(ITag<T> tag) {
var observable = _bus.subscribe(tag).OnDispatcher().Subscribe(
data => _on_bus_data(tag, data));
}
public void sec_thread_write<T>(ITag<T> tag, T data, bool block_until_written = false) {
_bus.post(tag, data);
}
private void _on_bus_data<T>(ITag<T> tag, T data) {
data_callback(tag, data);
}
#endregion
// public void add_to_subscription_list(Func<object, bool> sub_func) { }
// public void add_to_subscription_list(params object[] tags) {
// }
public void sec_thread_write(object tag, object value) { sec_thread_write(tag, value, false); }
public void sec_thread_write(object tag, object value, bool block_until_written) {
}
public void sec_thread_write<T>(ITag<T> tag, T data, bool block_until_written) {
_bus.post(tag, data);
}
public void sec_thread_dowork() { }
public object sec_thread_retrieve_from_cache(object tag) {
@@ -27,7 +27,7 @@ namespace mbts.spark {
public VolSurfaceLocalTheosManager(ThreadedBlackboard bb) {
_bb = bb;
_in_bb_volsurface_usage_tag = SparkTags.VolSurfaceUsageTag;
_bb.add_to_subscription_list(_in_bb_volsurface_usage_tag);
_bb.subscribe(_in_bb_volsurface_usage_tag);
_bb.data_callback += _on_data;
_analyze_usages();
}
@@ -50,7 +50,7 @@ namespace mbts.spark {
if (!_vs_theo_tags.ContainsKey(vs_id)) {
var vs_loc_theo_tag = SparkTags.VolSurfaceLocalTheosTag(vs_id);
_vs_theo_tags.Add(vs_id, vs_loc_theo_tag);
_bb.add_to_subscription_list(vs_loc_theo_tag);
_bb.subscribe(vs_loc_theo_tag);
}
_read_theos_and_publish(vs_id);
}