Cleaning up SingleVolSurfaceMarketImpliedVolSource
This commit is contained in:
1 parent
0a6f2d5adb
commit
a743500a37
2 files changed
+37
-34
No files matched your search
@@ -66,6 +66,7 @@
|
||||
private readonly ThreadedBlackboard _bb;
|
||||
private readonly HighPerformanceTimer _timer = new HighPerformanceTimer();
|
||||
private readonly PerfStatsLogger _logger = new PerfStatsLogger(50, 50);
|
||||
private TimeSpan _compute_period = TimeSpan.FromMilliseconds(333);
|
||||
private bool _is_dirty = true;
|
||||
|
||||
public SingleVolSurfaceMarketImpliedVolSource(int vs_id, ThreadedBlackboard bb) {
|
||||
@@ -88,15 +89,12 @@
|
||||
_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) {
|
||||
if (tag != null)
|
||||
if (_in_bb_committed_output_tag.Equals(tag) || _in_bb_calc_resp_tag.Equals(tag) ||
|
||||
if (_in_bb_committed_output_tag.Equals(tag) ||
|
||||
_in_bb_calc_resp_tag.Equals(tag) ||
|
||||
_in_bb_inp_dirty_tag.Equals(tag) || _in_bb_selected_exp_tag.Equals(tag) ||
|
||||
_in_bb_market_impliedvol_side_tag.Equals(tag) ||
|
||||
_in_bb_ignore_market_implied_vol_source_settings_tag.Equals(tag))
|
||||
@@ -118,9 +116,13 @@
|
||||
|
||||
private DateTime _last_publish_time = DateTime.MinValue;
|
||||
private void _on_bb_timer() {
|
||||
_check_bbo_change();
|
||||
if (_is_dirty)
|
||||
_recompute_and_publish();
|
||||
if (DateTime.Now - _last_publish_time >= _compute_period) {
|
||||
_check_bbo_change();
|
||||
if (_is_dirty)
|
||||
_recompute_and_publish();
|
||||
_is_dirty = false;
|
||||
_last_publish_time = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
private void _recompute_and_publish() {
|
||||
@@ -129,13 +131,8 @@
|
||||
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(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;
|
||||
sel_exp != null && sel_exp.Item1 != null) {
|
||||
var impliedvol_side = _get_market_impliedvol_side(_bb, _vs_id);
|
||||
VolSurfaceExpiration orig_exp = new VolSurfaceExpiration() {
|
||||
symbol = sel_exp.Item1.symbol,
|
||||
expiration = sel_exp.Item1.expiration
|
||||
@@ -152,13 +149,14 @@
|
||||
out md_exp);
|
||||
_timer.stop();
|
||||
_logger.log("SingleVolSurfaceMarketImpliedVolSource",
|
||||
"SingleVolSurfaceMarketImpliedVolSource", _timer.lastIntervalTime);
|
||||
"SingleVolSurfaceMarketImpliedVolSource",
|
||||
_timer.lastIntervalTime);
|
||||
if (exp_impl_vol_map is null) {
|
||||
return;
|
||||
}
|
||||
var sz = exp_impl_vol_map.put_rawk_vols.Count() + exp_impl_vol_map.call_rawk_vols.Count();
|
||||
bts.Log.Gen.info($"SingleVolSurfaceMarketImpliedVolSource._recompute_and_publish " +
|
||||
exp_impl_vol_map.log_string());
|
||||
bts.Log.Gen.info(
|
||||
$"SingleVolSurfaceMarketImpliedVolSource._recompute_and_publish " +
|
||||
exp_impl_vol_map.log_string());
|
||||
_bb.post(SparkTags.VolSurfaceMarketImpliedVolTag(_vs_id),
|
||||
new Dictionary<VolSurfaceExpiration,
|
||||
Tuple<VolSurfaceExpiration, VolCurveMarketImpliedVolData>>() {
|
||||
@@ -199,7 +197,8 @@
|
||||
}
|
||||
return Double.NaN;
|
||||
}
|
||||
internal static IDictionary<double, Tuple<VolSurfaceBBOUnit, VolSurfaceBBOUnit>>
|
||||
internal static
|
||||
IDictionary<double, Tuple<VolSurfaceBBOUnit, VolSurfaceBBOUnit>>
|
||||
get_option_bbo(ThreadedBlackboard bb, VolSurfaceExpiration vs_exp) {
|
||||
var sc_data = bb.read_state(SparkTags.SystemContractsTag);
|
||||
IDictionary<double, Tuple<VolSurfaceBBOUnit, VolSurfaceBBOUnit>> rv =
|
||||
@@ -214,14 +213,15 @@
|
||||
|
||||
internal static bool _ignore_market_implied_vol_source_settings(
|
||||
ThreadedBlackboard bb, int vs_id) {
|
||||
return bb.read_state(SparkTags.VolSurfaceIgnoreImpliedVolSettingsTag(vs_id),
|
||||
false);
|
||||
return bb.read_state(
|
||||
SparkTags.VolSurfaceIgnoreImpliedVolSettingsTag(vs_id), false);
|
||||
}
|
||||
|
||||
internal static VolSurfaceEnums.MarketSide
|
||||
_get_market_impliedvol_side(ThreadedBlackboard bb, int vs_id) {
|
||||
return bb.read_state(
|
||||
SparkTags.VolSurfaceMarketImpliedVolSide(vs_id), VolSurfaceEnums.MarketSide.Mid);
|
||||
SparkTags.VolSurfaceMarketImpliedVolSide(vs_id),
|
||||
VolSurfaceEnums.MarketSide.Mid);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -9,13 +9,11 @@ using bts.api;
|
||||
using mbts.co2;
|
||||
|
||||
namespace mbts.analytics {
|
||||
/// Just a packaging around BBO
|
||||
/// (TODO:move it to common edge location and replace
|
||||
/// blue2's BBOPacket with this)
|
||||
public class VolSurfaceBBOUnit : IEquatable<VolSurfaceBBOUnit> {
|
||||
public readonly double bid_price, ask_price;
|
||||
public readonly uint bid_size, ask_size;
|
||||
private static VolSurfaceBBOUnit _empty = new VolSurfaceBBOUnit(Double.NaN, 0, Double.NaN, 0);
|
||||
private static VolSurfaceBBOUnit _empty =
|
||||
new VolSurfaceBBOUnit(Double.NaN, 0, Double.NaN, 0);
|
||||
|
||||
public VolSurfaceBBOUnit(double this_bid_price, uint this_bid_size,
|
||||
double this_ask_price, uint this_ask_size) {
|
||||
@@ -48,7 +46,8 @@ namespace mbts.analytics {
|
||||
if (sum_q == 0) {
|
||||
return Double.NaN;
|
||||
}
|
||||
double w_mid_price = (bid_price * bid_size + ask_price * ask_size) / sum_q;
|
||||
double w_mid_price =
|
||||
(bid_price * bid_size + ask_price * ask_size) / sum_q;
|
||||
if (Double.IsNaN(w_mid_price))
|
||||
w_mid_price = !Double.IsNaN(bid_price) ? bid_price : ask_price;
|
||||
return w_mid_price;
|
||||
@@ -60,10 +59,11 @@ namespace mbts.analytics {
|
||||
|
||||
public bool Equals(VolSurfaceBBOUnit other) {
|
||||
if (other != null)
|
||||
return VolSurfaceUtilityFunctions.compare_doubles(bid_price, other.bid_price) &&
|
||||
bid_size == other.bid_size &&
|
||||
VolSurfaceUtilityFunctions.compare_doubles(ask_price, other.ask_price) &&
|
||||
ask_size == other.ask_size;
|
||||
return
|
||||
VolSurfaceUtilityFunctions.compare_doubles(bid_price, other.bid_price) &&
|
||||
bid_size == other.bid_size &&
|
||||
VolSurfaceUtilityFunctions.compare_doubles(ask_price, other.ask_price) &&
|
||||
ask_size == other.ask_size;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@@ -82,10 +82,13 @@ namespace mbts.analytics {
|
||||
if (Object.ReferenceEquals(y, null)) return false;
|
||||
return x.Equals(y);
|
||||
}
|
||||
public static bool operator !=(VolSurfaceBBOUnit x, VolSurfaceBBOUnit y) { return !(x == y); }
|
||||
public static bool operator !=(VolSurfaceBBOUnit x, VolSurfaceBBOUnit y) {
|
||||
return !(x == y);
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return String.Format("{0}/{1} {2}/{3}", bid_price, bid_size, ask_price, ask_size);
|
||||
return String.Format("{0}/{1} {2}/{3}",
|
||||
bid_price, bid_size, ask_price, ask_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user