public void OpenBar(DateTime openTime) { if (trades == null) { trades = new List <_HistoricalTrade>(); } if (LongExposureBars == null) { LongExposureBars = new List <PortfolioBacktestBar>(); ShortExposureBars = new List <PortfolioBacktestBar>(); } var currentLongExposure = !trades.Any() ? 0 : trades.Select(t => t.Volume * (t.TradeType == TradeType.Buy ? 1 : -1)).Aggregate((x, y) => x + y); var currentShortExposure = !trades.Any() ? 0 : trades.Select(t => t.Volume * t.EntryPrice * (t.TradeType == TradeType.Sell ? 1 : -1)).Aggregate((x, y) => x + y); LongExposureBars.Add(new PortfolioBacktestBar(openTime, currentLongExposure)); ShortExposureBars.Add(new PortfolioBacktestBar(openTime, currentShortExposure)); }
public void CloseBar() { LongExposureBars.Last().Close = !trades.Any() ? 0 : trades.Select(t => t.Volume * (t.TradeType == TradeType.Buy ? 1 : -1)).Aggregate((x, y) => x + y); ShortExposureBars.Last().Close = !trades.Any() ? 0 : trades.Select(t => t.Volume * t.EntryPrice * (t.TradeType == TradeType.Sell ? 1 : -1)).Aggregate((x, y) => x + y); }