Add fake slide report data
This commit is contained in:
1 parent
07c3150d2a
commit
96cd807720
5 files changed
+160
-11
No files matched your search
@@ -41,7 +41,7 @@ namespace mbts.analytics {
|
||||
}
|
||||
|
||||
public IDictionary<mbts.SecurityTuple, double> get_cpp_map() {
|
||||
return input.get_cpp_list().ToDictionary(i => new mbts.SecurityTuple(i.Item1, i.Item2, Venue.Unset), i => i.Item3);
|
||||
return input.get_cpp_list().ToDictionaryCrushed(i => new mbts.SecurityTuple(i.Item1, i.Item2, Venue.Sim), i => i.Item3);
|
||||
}
|
||||
|
||||
private static mbts.SecurityExpiration _unset = mbts.SecurityExpiration.empty;
|
||||
@@ -59,4 +59,4 @@ namespace mbts.analytics {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
#nullable enable
|
||||
namespace bts.daemons {
|
||||
using bts.api;
|
||||
using bts.utils;
|
||||
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading;
|
||||
|
||||
[Export(typeof(IShellDaemon))]
|
||||
public sealed class FakeSymbolDriverDaemon : IShellDaemon, IDisposable {
|
||||
IDisposable _dispose;
|
||||
|
||||
public FakeSymbolDriverDaemon(IBus bus) {
|
||||
int tid_counter = 1;
|
||||
IDictionary<int, string> vol_surfaces = new Dictionary<int, string>();
|
||||
var sec_trades = new Dictionary<uint, List<ITradeLogRow>>();
|
||||
_dispose = Disposable.Create(
|
||||
bus.subscribe(SparkTags.VolSurfaceListTag).Subscribe(vss => vol_surfaces = vss),
|
||||
bus.subscribe(SparkTags.SecuritiesTag).SubscribeEach(secs => {
|
||||
var btc_secs = secs.Values.Where(
|
||||
s => s.security.Symbol == "BTC" &&
|
||||
s.security.ContractCase == Security.ContractOneofCase.Future)
|
||||
.ToList();
|
||||
var fake_trades = btc_secs.Select(
|
||||
s => get_fake_trade(to_sec_exp(s.security), 4200)).ToList();
|
||||
bus.post(SparkTags.TradeLogTag, fake_trades);
|
||||
var bbo_upd_refs = btc_secs.ToDictionary(s => s.security.Id, _ => 0UL);
|
||||
var driver_sym_prices = btc_secs.ToImmutableDictionary(
|
||||
s => to_sec_exp(s.security), get_driver_price);
|
||||
|
||||
double get_driver_price(SecurityMD smd) {
|
||||
var upd_ref = bbo_upd_refs[smd.security.Id];
|
||||
var rv = double.NaN;
|
||||
if (smd.md.get_bbo(ref upd_ref, out var bid, out var ask)) {
|
||||
rv = bid.price.if_nan(ask.price);
|
||||
}
|
||||
bbo_upd_refs[smd.security.Id] = upd_ref;
|
||||
return rv;
|
||||
}
|
||||
|
||||
return Observable.Interval(TimeSpan.FromSeconds(2)).Subscribe(_ => {
|
||||
var bd = driver_sym_prices.ToBuilder();
|
||||
foreach (var sec in btc_secs) {
|
||||
var sec_exp = to_sec_exp(sec.security);
|
||||
bd[sec_exp] = get_driver_price(sec).if_nan(driver_sym_prices[sec_exp]);
|
||||
}
|
||||
driver_sym_prices = bd.ToImmutable();
|
||||
foreach (var vsid in vol_surfaces.Keys) {
|
||||
bus.post(SparkTags.VolSurfaceDriverSymbolPriceTag(vsid), driver_sym_prices);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
static SecurityExpiration to_sec_exp(SecurityImmutable sec) =>
|
||||
new(sec.Exchange, sec.ContractCase, sec.Symbol, sec.security_expiration() ?? DateTime.MinValue, sec.Id);
|
||||
|
||||
ITradeLogRow get_fake_trade(
|
||||
SecurityExpiration sec_exp,
|
||||
double price,
|
||||
int size = 1,
|
||||
string account = "ACC A",
|
||||
double? strike = null,
|
||||
PutOrCall? cp = null,
|
||||
double? theo = null
|
||||
) {
|
||||
var t1 = new FakeTradeLogRow(
|
||||
Interlocked.Increment(ref tid_counter),
|
||||
sec_exp,
|
||||
strike,
|
||||
cp,
|
||||
size,
|
||||
price,
|
||||
theo ?? price + 10 * new Random().NextDouble(),
|
||||
account,
|
||||
true,
|
||||
DateTime.Now,
|
||||
"FakeTrader");
|
||||
return t1;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(ref _dispose);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#nullable enable
|
||||
namespace mbts {
|
||||
using bts.api;
|
||||
|
||||
using System;
|
||||
|
||||
public class FakeTradeLogRow : ITradeLogRow {
|
||||
public FakeTradeLogRow(
|
||||
int trade_id,
|
||||
SecurityExpiration security_expiration,
|
||||
double? strike,
|
||||
PutOrCall? call_put,
|
||||
int size,
|
||||
double price,
|
||||
double theo,
|
||||
string account,
|
||||
bool is_day_trade,
|
||||
DateTime time_entered,
|
||||
string trader
|
||||
) {
|
||||
this.trade_id = trade_id;
|
||||
security_type = security_expiration.security_type;
|
||||
symbol = security_expiration.symbol;
|
||||
expiration = security_expiration.expiration;
|
||||
this.strike = strike ?? double.NaN;
|
||||
this.security_expiration = security_expiration;
|
||||
this.call_put = call_put ?? PutOrCall.Call;
|
||||
security_strike = new(security_expiration, this.strike, null);
|
||||
this.size = size;
|
||||
this.price = price;
|
||||
this.theo = theo;
|
||||
this.account = account;
|
||||
this.is_day_trade = is_day_trade;
|
||||
this.time_entered = time_entered;
|
||||
this.trader = trader;
|
||||
}
|
||||
|
||||
public int trade_id { get; }
|
||||
public SecurityType security_type { get; }
|
||||
public string symbol { get; }
|
||||
public DateTime? expiration { get; }
|
||||
public double strike { get; }
|
||||
public SecurityExpiration? security_expiration { get; }
|
||||
public SecurityStrike? security_strike { get; }
|
||||
public PutOrCall? call_put { get; }
|
||||
public int size { get; }
|
||||
public double price { get; }
|
||||
public double theo { get; }
|
||||
public string account { get; }
|
||||
public bool is_day_trade { get; }
|
||||
public DateTime time_entered { get; }
|
||||
public string trader { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ namespace mbts.analytics {
|
||||
var cpp_map = _vs_nonvol_data.get_cpp_map();
|
||||
var fut_theo_map = VolSurfaceUtilityFunctions.compute_future_theos(
|
||||
account_fut_pos_map.Keys.Select(
|
||||
kv => new SecurityExpiration(Venue.Unset, SecurityType.Future, kv.symbol, kv.expiration)),
|
||||
kv => new SecurityExpiration(Venue.Sim, SecurityType.Future, kv.symbol, kv.expiration)),
|
||||
_vs_nonvol_data.input.exp_input_map,
|
||||
_future_prices_map);
|
||||
var fut_theo_map_vsexp = fut_theo_map.ToDictionary(
|
||||
@@ -265,7 +265,7 @@ namespace mbts.analytics {
|
||||
kv => kv.Value);
|
||||
|
||||
var delta_terms_symbol = new mbts.SecurityTuple(
|
||||
_report_params.RiskTermsType, _report_params.RiskTermsName, Venue.Unset);
|
||||
_report_params.RiskTermsType, _report_params.RiskTermsName, Venue.Sim);
|
||||
|
||||
var option_exp_slide_greeks = VolSurfaceRiskCalculator.compute_option_slide(
|
||||
_report_params.Greeks,
|
||||
|
||||
@@ -267,9 +267,9 @@ namespace mbts.analytics
|
||||
foreach (KeyValuePair<VolSurfaceExpiration, IDictionary<double, Tuple<double, double>>> kv in pos_map)
|
||||
{
|
||||
IEnumerable<Theos> exp_theos = theo_map.TryGetValue(kv.Key, out exp_theos) ? exp_theos : null;
|
||||
double cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Option, kv.Key.symbol, Venue.Unset), out cpp) ? cpp : Double.NaN,
|
||||
double cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Option, kv.Key.symbol, Venue.Sim), out cpp) ? cpp : Double.NaN,
|
||||
delta_terms_sym_cpp = cpp_map.TryGetValue(delta_terms_symbol, out delta_terms_sym_cpp) ? delta_terms_sym_cpp : Double.NaN,
|
||||
oev_terms_sym_cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Option, oev_terms_option_symbol, Venue.Unset), out oev_terms_sym_cpp) ? oev_terms_sym_cpp : Double.NaN;
|
||||
oev_terms_sym_cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Option, oev_terms_option_symbol, Venue.Sim), out oev_terms_sym_cpp) ? oev_terms_sym_cpp : Double.NaN;
|
||||
rv[kv.Key] = _compute_single_exp_option_slide(ordered_greeks, perc_move_handles, kv.Value, VolSurfaceUtilityFunctions.hash_strikes(exp_theos), cpp, delta_terms_sym_cpp, oev_terms_sym_cpp);
|
||||
}
|
||||
return rv;
|
||||
@@ -376,7 +376,7 @@ namespace mbts.analytics
|
||||
IDictionary<VolSurfaceExpiration, IEnumerable<SlideGreekUnit>> rv = new Dictionary<VolSurfaceExpiration, IEnumerable<SlideGreekUnit>>();
|
||||
foreach (string future_symbol in new HashSet<string>(fut_pos_map.Keys.Select(e => e.symbol)))
|
||||
{
|
||||
double cpp = cpp_map.TryGetValue(new mbts.SecurityTuple(SecurityType.Future, future_symbol, Venue.Unset), out cpp) ? cpp : Double.NaN,
|
||||
double cpp = cpp_map.TryGetValue(new mbts.SecurityTuple(SecurityType.Future, future_symbol, Venue.Sim), out cpp) ? cpp : Double.NaN,
|
||||
delta_terms_symbol_cpp = cpp_map.TryGetValue(delta_terms_symbol, out delta_terms_symbol_cpp) ? delta_terms_symbol_cpp : Double.NaN;
|
||||
IDictionary<VolSurfaceExpiration, IEnumerable<SlideGreekUnit>> sym_rv = _compute_single_symbol_future_slide(ordered_greeks, handles, future_symbol, fut_theo_map, fut_pos_map, cpp, delta_terms_symbol_cpp);
|
||||
sym_rv.ToList().ForEach(kv => rv.Add(kv));
|
||||
@@ -476,7 +476,7 @@ namespace mbts.analytics
|
||||
VolSurfaceExpiration exp = kv_exp.Key;
|
||||
double exp_pos = kv_exp.Value;
|
||||
VolSurfaceDriverTheo exp_theo = theo_map.TryGetValue(exp, out exp_theo) ? exp_theo : VolSurfaceDriverTheo.empty;
|
||||
double cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Future, exp.symbol, Venue.Unset), out cpp) ? cpp : Double.NaN;
|
||||
double cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Future, exp.symbol, Venue.Sim), out cpp) ? cpp : Double.NaN;
|
||||
IEnumerable<Tuple<double, double, double>> exp_handle_theos = _compute_future_slide_theos(perc_handles, exp_theo.theo, exp_theo.delta, exp_theo.roll);
|
||||
SlideContractUnit exp_val = new SlideContractUnit(n_greeks, exp_handle_theos.Select(t => t.Item3));
|
||||
slide_expiration_map.Add(VolSurfaceRiskCalculator._to_sec_exp(exp, false), exp_val);
|
||||
@@ -513,7 +513,7 @@ namespace mbts.analytics
|
||||
{
|
||||
slide_strike_map = new Dictionary<SecurityStrike, SlideContractUnit>();
|
||||
double delta_terms_cpp = cpp_map.TryGetValue (delta_terms_symbol, out delta_terms_cpp) ? delta_terms_cpp : Double.NaN,
|
||||
oev_terms_cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Option, oev_terms_option_symbol,Venue.Unset), out oev_terms_cpp) ? oev_terms_cpp : Double.NaN;
|
||||
oev_terms_cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Option, oev_terms_option_symbol,Venue.Sim), out oev_terms_cpp) ? oev_terms_cpp : Double.NaN;
|
||||
int n_greeks = ordered_greeks.Count(),
|
||||
zero_handle_index = perc_handles.find_first_index(0.0),
|
||||
pnl_index = ordered_greeks.find_first_index(VolSurfaceGreeks.Pnl);
|
||||
@@ -523,7 +523,7 @@ namespace mbts.analytics
|
||||
{
|
||||
SecurityExpiration exp = _to_sec_exp(kv_exp.Key, true);
|
||||
IDictionary<double, Tuple<double, double>> exp_pos_map = kv_exp.Value;
|
||||
double cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Option, exp.symbol, Venue.Unset), out cpp) ? cpp : Double.NaN;
|
||||
double cpp = cpp_map.TryGetValue(new SecurityTuple(SecurityType.Option, exp.symbol, Venue.Sim), out cpp) ? cpp : Double.NaN;
|
||||
/* strike */
|
||||
foreach (var kv_k in exp_pos_map)
|
||||
{
|
||||
@@ -569,7 +569,7 @@ namespace mbts.analytics
|
||||
|
||||
internal static mbts.SecurityExpiration _to_sec_exp(VolSurfaceExpiration exp, bool is_option)
|
||||
{
|
||||
return new SecurityExpiration(Venue.Unset, is_option ? SecurityType.Option : SecurityType.Future, exp.symbol, exp.expiration);
|
||||
return new SecurityExpiration(Venue.Sim, is_option ? SecurityType.Option : SecurityType.Future, exp.symbol, exp.expiration);
|
||||
}
|
||||
|
||||
internal static IDictionary<SecurityStrike, T> _to_strike_map<T>(IDictionary<SecurityExpiration, IDictionary<double, T>> exp_map)
|
||||
|
||||
Reference in new issue
Block a user