コード例 #1
0
        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));
        }
コード例 #2
0
 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);
 }