Performance improvementswith throttling and smmaller number of handles

This commit is contained in:
Taha committed 2025-06-26 16:14:01 -04:00
1 parent f0b5e398f0
commit d2deb768b9
6 files changed
+71 -18

No files matched your search

@@ -12,8 +12,8 @@ using bts.api;
using mbts.ui.converters;
namespace mbts.spark {
// This class gathers all the inputs needed to calculate InterpGreeks, pass it to
// VolSurfacePrecomputedTheosProducer, and publishes the InterpGreeks to the bus
// This class gathers all the inputs needed to calculate InterpGreeks for a single vol surface,
// passes it to VolSurfacePrecomputedTheosProducer, and publishes the InterpGreeks to the bus
// (called SingleVolSurfaceClientPrecomputedTheosPublisher in Edge)
// It listens to
// a. vol surface inputs
@@ -107,6 +107,43 @@ namespace mbts.spark
private bts.api.IBus _bus;
private List<IDisposable> _subs = new List<IDisposable>();
private static void add_temp_vsu_entries(IDictionary<string, int> name_id_map,
VolSurfaceUsageList ulist) {
Action<string, Venue, string> add_entry = (option_name, option_venue, vs_name) => {
int vs_key;
if (name_id_map.TryGetValue(vs_name, out vs_key)) {
ulist.UsageList.Add(new VolSurfaceUsageEntry() {
VsId = vs_key,
SymbolName = option_name,
SecTup = new bts.api.SecurityTuple {
Type = SecurityType.Option,
Venue = option_venue,
Symbol = option_name
}
});
}
};
add_entry("SPX", Venue.Cboe, "CBOE_skews");
add_entry("SPXW", Venue.Cboe, "CBOE_skews");
add_entry("E1B", Venue.Glbx, "CME_Skews");
add_entry("E1C", Venue.Glbx, "CME_Skews");
add_entry("E3B", Venue.Glbx, "CME_Skews");
add_entry("E3C", Venue.Glbx, "CME_Skews");
add_entry("E3D", Venue.Glbx, "CME_Skews");
add_entry("E4A", Venue.Glbx, "CME_Skews");
add_entry("E4B", Venue.Glbx, "CME_Skews");
add_entry("E4C", Venue.Glbx, "CME_Skews");
add_entry("E4C", Venue.Glbx, "CME_Skews");
add_entry("E4D", Venue.Glbx, "CME_Skews");
add_entry("ES", Venue.Glbx, "CME_Skews");
add_entry("EW1", Venue.Glbx, "CME_Skews");
add_entry("EW2", Venue.Glbx, "CME_Skews");
add_entry("EW3", Venue.Glbx, "CME_Skews");
add_entry("EW4", Venue.Glbx, "CME_Skews");
}
public VolSurfaceBusManager(bts.api.IBus bus,
bts.api.analytics.AnalyticsService analytics_service,
bts.api.orderman.OrderService order_service)
@@ -158,7 +195,7 @@ namespace mbts.spark
_subs.Add(new LiveTheoPublisher(_bb));
_subs.Add(new InterpTheosServerPublisher(_bb, bus, order_service, contracts_throttle));
_subs.Add(new VolSurfaceInterpGreeksMultiplexer(_bb));
// usage
// list of all volsurface. in this callback, we read the usage config, and detemine the id of the named vol surface
var list_sub = _bus.subscribe(SparkTags.VolSurfaceListTag).OnDispatcher().Subscribe(t =>
{
VolSurfaceUsageList ulist = new VolSurfaceUsageList();
@@ -169,9 +206,12 @@ namespace mbts.spark
}
Log.Ui.info($"VolSurfaceUsageList name_to_ids count: {name_to_ids.Count}");
var vs_usage = mbts.config.Configuration.get<bts.config.toggles.VolSurfaceUsage>();
Log.Ui.info($"VolSurfaceUsageList vs_usage acount: {vs_usage.Items.Count}");
Log.Ui.info($"VolSurfaceUsageList vs_usage acount: {vs_usage.Items.Count}");
foreach (var u in vs_usage.Items)
{
if (string.Compare(u.OptionName, "SPX", 0) == 0 || string.Compare(u.OptionName, "SPXW", 0) == 0){
continue;
}
if (string.Compare(u.OptionName, "SPX", 0) == 0 || string.Compare(u.OptionName, "SPXW", 0) == 0 && u.OptionVenue == Venue.Unset)
{
u.OptionVenue = Venue.Cboe;
@@ -201,10 +241,11 @@ namespace mbts.spark
else
{
Log.Gen.error($"Could not find vol surface with name: {vs_name}");
}
}
}
add_temp_vsu_entries(name_to_ids, ulist);
var list_imm = new VolSurfaceUsageListImmutable(ulist);
Log.Ui.info(list_imm.log_string());
Log.Ui.info("VolSurfaceUsage: " + list_imm.log_string());
_bb.post(SparkTags.VolSurfaceUsageTag, list_imm);
_spin_vss(list_imm);
});
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace mbts.analytics {
public static class VolSurfaceConstants {
public static int vol_time_sample_mins = 1;
public static int vol_time_sample_mins = 5;
}
// TODO: remove this
public static class VolSurfaceTemp {
@@ -9,8 +9,8 @@ using bts.api;
using mbts.spark;
namespace mbts.analytics {
// This class computes the theos/greeks for a number of driver
// prices (specified in the vs settings).
// This class computes interp theos/greeks (ie for a number of driver
// prices (specified in the vs settings)) for a volsurface
// It has public setters that get
// 1. contracts
// 2. vs input
@@ -41,7 +41,8 @@ namespace mbts.analytics {
private IDictionary<VolSurfaceExpiration, Tuple<double, double>>
_computed_driver_range_map = new Dictionary<VolSurfaceExpiration, Tuple<double, double>>();
private readonly IEnumerable<double> _default_abs_moves =
new double[] { 300, -200, -125, -100, -75, -50, -25, 0, 25, 50, 75, 100, 125, 200, 300 };
//new double[] { 300, -200, -125, -100, -75, -50, -25, 0, 25, 50, 75, 100, 125, 200, 300 };
new double[] { -100, -50, 0, 50, 100 };
private readonly double _cushion_percentage = 25.0;
public event
@@ -135,8 +136,8 @@ namespace mbts.analytics {
false, true, false, false, false, _filter_map);
timer.stop();
vol_compute_time = timer.last_interval_time_ms;
Log.Gen.info($"VolSurfacePrecomputedTheosProducer._compute_and_fire volmat time " +
$"{timer.last_interval_time_ms}");
Log.Gen.info($"VolSurfacePrecomputedTheosProducer._compute_and_fire volmat input_type: {input_type} vs_id: {_vs_id} time " +
$"{timer.last_interval_time_ms} tid: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
timer.start();
IDictionary<VolSurfaceExpiration, IEnumerable<Theos>> exp_theo_map =
VolSurfaceTheoCalculator.compute_standard_greeks(synced_vs_input.surface_settings,
@@ -21,6 +21,7 @@ using System.Reactive.Linq;
using System.Threading;
using bts.api.orderman;
using bts;
using mbts.analytics;
namespace BCG {
public partial class NMSheetControl : UserControl {
@@ -253,7 +254,7 @@ namespace BCG {
/// windows timer
_windows_timer = new System.Windows.Forms.Timer(components);
_windows_timer.Enabled = true;
_windows_timer.Interval = 20;
_windows_timer.Interval = 100;
_windows_timer.Tick += _windows_timer_tick;
_toolstripmenuitem_card.Visible = false;
/// status bar
@@ -721,9 +722,9 @@ namespace BCG {
private void _windows_timer_tick(object sender, EventArgs e) {
_publish_activation_state();
//_threaded_bb.sec_thread_dowork();
// this computes the data and then paints it
_check_and_propagate_data();
_poll_theo_acceptance_button();
//_poll_theo_acceptance_button();
_refresh_statusbar_data(false);
}
@@ -784,21 +785,31 @@ namespace BCG {
#region Coalescer NMSheetData interaction
private DateTime _last_data_draw_time = DateTime.MinValue;
private const double _min_draw_period_ms = 333.3;
private const double _min_draw_period_ms = 500;
private NMSheetGeometricLayout _last_geo_lo_info = null;
private VolSurfaceTimer _vs_timer = new VolSurfaceTimer();
// this is where we assemble the data (in _coalescer.get_data())
// and then painted in _respond_to_data
private void _check_and_propagate_data() {
if (is_visible) {
if ((DateTime.Now - _last_data_draw_time).Milliseconds >= Math.Max(_settings.setting_grid_internal.grid_paint_throttle_ms, _min_draw_period_ms)) {
_vs_timer.start();
NMSheetData new_sheet_data = _coalescer.get_data();
_vs_timer.stop();
Log.Gen.info($"NMSheetControl._check_and_propagate_data get_data time: {_vs_timer.last_interval_time_ms} msecs symbols: {_title_prefix} tid: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
if (new_sheet_data != null) {
_last_data_draw_time = DateTime.Now;
_sheet_data = new_sheet_data;
_vs_timer.start();
_respond_to_data();
_vs_timer.stop();
Log.Gen.info($"NMSheetControl._check_and_propagate_data _respond_to_data time: {_vs_timer.last_interval_time_ms} msecs symbols: {_title_prefix} tid: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
}
}
}
}
// this is the painting
private void _respond_to_data() {
if (_sheet_data != null) {
_set_driver_control_display();
+2 -2
View File
@@ -114,12 +114,12 @@ VolSurfaceUsage {
items: {
option_name: "SPX"
option_venue: VENUE_CBOE
vs_name: "Main"
vs_name: "CBOE_skews"
}
items: {
option_name: "SPXW"
option_venue: VENUE_CBOE
vs_name: "Main"
vs_name: "CBOE_skews"
}
items: {
option_name: "ES"