Normalizing options market data form coins to USD

This commit is contained in:
Taha Afzal committed 2022-02-04 12:39:26 -05:00
1 parent 96e6c0dfb5
commit 0a6f2d5adb
3 files changed
+43 -5

No files matched your search

@@ -179,15 +179,37 @@
private IDictionary<double, Tuple<VolSurfaceBBOUnit, VolSurfaceBBOUnit>>
_get_bbo(VolSurfaceExpiration vs_exp) {
return _get_bbo(_bb, vs_exp);
return get_option_bbo(_bb, vs_exp);
}
private static bool _normalize_bbo = true;
#region Static helpers
// for some markets (crypto ie), the options prices are not in
// the same terms as strikes, ie strikes are in USD whereras the
// option prices are in BTC
internal static double get_option_price_mult(
ThreadedBlackboard bb,
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)) {
var vs_bbo = sym_map.get_driver_bbo(option_exp.expiration);
return vs_bbo.get_weighted_mid_price();
}
return Double.NaN;
}
internal static IDictionary<double, Tuple<VolSurfaceBBOUnit, VolSurfaceBBOUnit>>
_get_bbo(ThreadedBlackboard bb, VolSurfaceExpiration vs_exp) {
get_option_bbo(ThreadedBlackboard bb, VolSurfaceExpiration vs_exp) {
var sc_data = bb.read_state(SparkTags.SystemContractsTag);
var rv = sc_data.get_option_bbo_vsexp(vs_exp);
return rv.Item2;
IDictionary<double, Tuple<VolSurfaceBBOUnit, VolSurfaceBBOUnit>> rv =
sc_data.get_option_bbo_vsexp(vs_exp).Item2;
double mult = get_option_price_mult(bb, vs_exp);
if (_normalize_bbo)
return rv.ToDictionary(kv => kv.Key, kv =>
Tuple.Create(kv.Value.Item1.mult_price(mult),
kv.Value.Item2.mult_price(mult)));
return rv;
}
internal static bool _ignore_market_implied_vol_source_settings(
@@ -146,7 +146,7 @@ namespace mbts.spark {
VolSurfaceExpiration md_exp;
VolCurveMarketImpliedVolData exp_impl_data =
VolSurfaceCoreFunctions.compute_implied_vols(vs_inp, vs_exp, aux_data_map,
arg_vs_exp => SingleVolSurfaceMarketImpliedVolSource._get_bbo(_bb, arg_vs_exp),
arg_vs_exp => SingleVolSurfaceMarketImpliedVolSource.get_option_bbo(_bb, arg_vs_exp),
impliedvol_side,
SingleVolSurfaceMarketImpliedVolSource._ignore_market_implied_vol_source_settings(
_bb, _vs_id),
@@ -25,6 +25,11 @@ namespace mbts.analytics {
ask_size = this_ask_size;
}
public VolSurfaceBBOUnit mult_price(double mult) {
return new VolSurfaceBBOUnit(bid_price * mult, bid_size,
ask_price * mult, ask_size);
}
public VolSurfaceBBOUnit(NativePriceSize bid, NativePriceSize ask)
: this(bid.price, bid.size, ask.price, ask.size) {
}
@@ -38,6 +43,17 @@ namespace mbts.analytics {
return mid_price;
}
public double get_weighted_mid_price(bool get_one_sided_mid = true) {
uint sum_q = bid_size + ask_size;
if (sum_q == 0) {
return Double.NaN;
}
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;
}
public double get_bid_ask_spread() { return ask_price - bid_price; }
public static VolSurfaceBBOUnit empty { get { return _empty; } }