From 6f39705d4fab2157449820fc072225d02fcc1b80 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 12 Jul 2018 13:26:47 -0500 Subject: [PATCH] PnL will now use cpp from config rather than security --- .../spark/view/Spark/PAndL/PnLSummaryRow.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs b/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs index 2d4b3b05c..a59c27111 100644 --- a/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs +++ b/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs @@ -20,8 +20,7 @@ namespace mbts.spark { IEnumerable _fills; ulong _bbo_ref, _last_ref; double _driver; - //List _schedules = new List() { MarketSchedule.es_schedule }; - + static readonly Dictionary cpp_dict = config.Configuration.get().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; }