PnL will now use cpp from config rather than security

This commit is contained in:
Jake Norbut committed 2018-07-12 13:26:47 -05:00
1 parent 07377b8cc9
commit 6f39705d4f
1 file changed
+16 -6
@@ -20,8 +20,7 @@ namespace mbts.spark {
IEnumerable<FillImmutable> _fills;
ulong _bbo_ref, _last_ref;
double _driver;
//List<MarketSchedule> _schedules = new List<MarketSchedule>() { MarketSchedule.es_schedule };
static readonly Dictionary<string, double> cpp_dict = config.Configuration.get<bts.config.CppConfig>().cpp_entry;
public PnLSummaryRow(pnl_calc_type calc_type,
@@ -46,18 +45,29 @@ namespace mbts.spark {
private double _get_cpp_for_security(SecurityImmutable s) {
if (s.security_type() == SecurityType.Spread) {
var distinct_cpps = s.Spread.Legs
.Select(l => l.Security.ContractSpec.CashPerPoint)
.Select(l => get_cpp_for_symbol(l.Security))
.Distinct();
bool all_legs_have_same_cpp = distinct_cpps.Count() < 2;
if (all_legs_have_same_cpp) {
return s.Spread.Legs.First().Security.ContractSpec.CashPerPoint;
return distinct_cpps.First();
} else {
Logger.error(bts.log.Subsystem.Ui,
Logger.error(bts.log.Subsystem.Ui,
$"Security {s} contains legs with the following cash multipliers: { string.Join(",", distinct_cpps.Select(d => d.ToString())) } ");
return Double.NaN;
}
} else {
return get_cpp_for_symbol(s);
}
// local function for looking up cpp for a single SecurityImmutable
double get_cpp_for_symbol(SecurityImmutable si) {
if (cpp_dict.TryGetValue(si.Symbol, out double cpp_out)) {
return cpp_out;
} else {
Logger.error(bts.log.Subsystem.Ui, $"No cash multiplier found for Security {si}, Symbol {si.Symbol}");
}
return double.NaN;
}
return s.ContractSpec.CashPerPoint;
}