From 77ad9ca011391e29ad4f3154cd287d52e52bb35d Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 12 Jul 2018 12:00:46 -0500 Subject: [PATCH] fixing no UTC to UTC time comparison bug; also, somehow swapped day vs start of day comparison --- src/client/spark/view/Spark/PAndL/PnLCalculator.cs | 12 ++++++------ src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/client/spark/view/Spark/PAndL/PnLCalculator.cs b/src/client/spark/view/Spark/PAndL/PnLCalculator.cs index 49280eed8..af042874e 100644 --- a/src/client/spark/view/Spark/PAndL/PnLCalculator.cs +++ b/src/client/spark/view/Spark/PAndL/PnLCalculator.cs @@ -78,7 +78,7 @@ namespace mbts.spark { class PnLCalculator { readonly IEnumerable _data; readonly pnl_calc_type _calc_type; - readonly DateTime _start_of_trading_day; + readonly DateTime _start_of_trading_day_utc; public PnLCalculator(IEnumerable data, pnl_calc_type calc_type, TimeSpan start_of_day_ts) { _data = data; @@ -86,18 +86,18 @@ namespace mbts.spark { // Note that this isn't the acutal start of the trading day // but it's close enough for pnl purposes. // In reality, instruments have different schedules - _start_of_trading_day = DateTime.Now.Date.Add(start_of_day_ts).AddDays(-1); + _start_of_trading_day_utc = DateTime.Now.Date.Add(start_of_day_ts).AddDays(-1).ToUniversalTime(); } public IEnumerable get_summary_position() { return (from pnl_item in _data group pnl_item by (pnl_item.account, pnl_item.exchange, pnl_item.symbol, pnl_item.security, pnl_item.sec_md) into grouping /* let start_of_day = _get_start_of_day(grouping.Key.symbol) */ - select new PnLSummaryRow(_calc_type, _start_of_trading_day, grouping.Key, - grouping.Where(y => y.fill.Timestamp.ToDateTime() < _start_of_trading_day).Sum(y => (uint)y.buy_quantity), - grouping.Where(y => y.fill.Timestamp.ToDateTime() < _start_of_trading_day).Sum(y => (uint)y.sell_quantity), + select new PnLSummaryRow(_calc_type, _start_of_trading_day_utc, grouping.Key, + grouping.Where(y => y.fill.Timestamp.ToDateTime() >= _start_of_trading_day_utc).Sum(y => (uint)y.buy_quantity), + grouping.Where(y => y.fill.Timestamp.ToDateTime() >= _start_of_trading_day_utc).Sum(y => (uint)y.sell_quantity), grouping.Sum(y => (int)(y.buy_quantity - y.sell_quantity)), - grouping.Where(y => y.fill.Timestamp.ToDateTime() >= _start_of_trading_day).Sum(y => (int)(y.buy_quantity - y.sell_quantity)), + grouping.Where(y => y.fill.Timestamp.ToDateTime() < _start_of_trading_day_utc).Sum(y => (int)(y.buy_quantity - y.sell_quantity)), grouping.weighted_average(y => y.fill.LastPrice, y => y.buy_quantity), grouping.weighted_average(y => y.fill.LastPrice, y => y.sell_quantity), grouping.Select(i => i.fill) diff --git a/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs b/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs index 52f2f8120..2d4b3b05c 100644 --- a/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs +++ b/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs @@ -27,11 +27,11 @@ namespace mbts.spark { public PnLSummaryRow(pnl_calc_type calc_type, DateTime start_of_day, (string, Venue?, string, SecurityImmutable?, SecurityMD?) key, - uint buy_quant, uint sell_quant, int net_pos, int sod_pos, double wavg_buy, double wavg_sell, IEnumerable fills) { + uint day_buy_quant, uint day_sell_quant, int net_pos, int sod_pos, double wavg_buy, double wavg_sell, IEnumerable fills) { this._start_of_day = start_of_day; this.key = key; - day_long_quantity = buy_quant; - day_short_quantity = sell_quant; + day_long_quantity = day_buy_quant; + day_short_quantity = day_sell_quant; total_net_position = net_pos; start_net_position = sod_pos; weighted_average_buy = wavg_buy;