From e1fbd84b26b37d2eef3acaf49a86f37dbb541267 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 28 Feb 2018 15:07:15 -0600 Subject: [PATCH] PnL - mock up the cpp store --- .../spark/view/Spark/PAndL/PnLSummaryRow.cs | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs b/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs index cfd7f16f5..f77b5133c 100644 --- a/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs +++ b/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs @@ -34,6 +34,20 @@ namespace mbts.spark { (string account, Venue? exchange, string symbol, SecurityImmutable? security, SecurityMD? sec_md) key; double _buy_quantity, _sell_quantity, _pnl; IEnumerable _fills; + Dictionary _cpp_store_mockup = new Dictionary() { + { "ES", 50.0 }, + { "SP", 250.0 }, + { "NQ", 20.0 }, + { "GE", 2500.0 }, + { "ZB", 1000.0 }, + { "ZN", 1000.0 }, + { "SI", 50.0 }, + { "GC", 100.0 }, + { "HG", 250.0 }, + { "CL", 1000.0 }, + { "ZC", 50.0 }, + { "ZS", 50.0 } + }; public PnLSummaryRow((string, Venue?, string, SecurityImmutable?, SecurityMD?) key, double buy_quant, double sell_quant, /*double pnl_val,*/ IEnumerable fills) { this.key = key; @@ -45,13 +59,18 @@ namespace mbts.spark { public void update_pnl(pnl_calc_type pnl_request) { if (key.sec_md.HasValue) { + // + //double cpp = key.security.Value.ContractSpec.CashPerPoint; + double cpp = 1.0; + _cpp_store_mockup.TryGetValue(key.security.Value.Symbol, out cpp); + if (pnl_request.HasFlag(pnl_calc_type.bid_and_ask)) { ulong unused = 0; key.sec_md.Value.md.get_bbo(ref unused, out NativePriceSize bid, out NativePriceSize ask); double summary_pnl = 0.0; foreach (var fill in _fills) { - double _tick_pnl = _get_pnl(bid.price, ask.price, fill); + double _tick_pnl = _get_pnl(bid.price, ask.price, fill, cpp); summary_pnl += _tick_pnl; } pnl = summary_pnl; @@ -60,7 +79,7 @@ namespace mbts.spark { double summary_pnl = 0.0; foreach (var fill in _fills) { - double _tick_pnl = _get_pnl(driver, fill); + double _tick_pnl = _get_pnl(driver, fill, cpp); summary_pnl += _tick_pnl; } pnl = summary_pnl; @@ -147,25 +166,25 @@ namespace mbts.spark { return Double.NaN; } - private double _get_pnl(double bid_for_long, double ask_for_short, FillImmutable fill) { - if (fill.Side == Side.Buy) { return _get_long_pnl(bid_for_long, fill.LastPrice, fill.LastShares); } - if (fill.Side == Side.Sell) { return _get_short_pnl(ask_for_short, fill.LastPrice, fill.LastShares); } + private double _get_pnl(double bid_for_long, double ask_for_short, FillImmutable fill, double cpp) { + if (fill.Side == Side.Buy) { return _get_long_pnl(bid_for_long, fill.LastPrice, fill.LastShares, cpp); } + if (fill.Side == Side.Sell) { return _get_short_pnl(ask_for_short, fill.LastPrice, fill.LastShares, cpp); } return Double.NaN; } - private double _get_pnl(double driver, FillImmutable fill) { + private double _get_pnl(double driver, FillImmutable fill, double cpp) { if (!Double.IsNaN(driver)) { - if (fill.Side == Side.Buy) { return _get_long_pnl(driver, fill.LastPrice, fill.LastShares); } - if (fill.Side == Side.Sell) { return _get_short_pnl(driver, fill.LastPrice, fill.LastShares); } + if (fill.Side == Side.Buy) { return _get_long_pnl(driver, fill.LastPrice, fill.LastShares, cpp); } + if (fill.Side == Side.Sell) { return _get_short_pnl(driver, fill.LastPrice, fill.LastShares, cpp); } } return Double.NaN; } - private double _get_long_pnl(double driver, double price, double quantity, double cpp = 1.0) { + private double _get_long_pnl(double driver, double price, double quantity, double cpp) { return (driver - price) * quantity * cpp; } - private double _get_short_pnl(double driver, double price, double quantity, double cpp = 1.0) { + private double _get_short_pnl(double driver, double price, double quantity, double cpp) { return (price - driver) * quantity * cpp; }