public void UpdateTimeIndex(MarketEvent market) { var marketHoldings = this.bars.Symbols.ToDictionary(symbol => symbol, cost => decimal.Zero); var cash = this.currentCash; var commision = this.currentComission; var total = this.currentCash; foreach (var symbol in this.bars.Symbols) { var qty = this.currentPositions[symbol]; var closePrice = this.bars.GetLastClosePrice(symbol); if (closePrice == null) { if (qty != 0) { throw new InvalidOperationException($"Unknown close price for {symbol} with position qty={qty}."); } closePrice = decimal.Zero; } var marketValue = qty * closePrice.Value; marketHoldings[symbol] = marketValue; total += marketValue; } var change = this.initialCapital != decimal.Zero ? ((total - this.initialCapital) / this.initialCapital) * 100 : decimal.Zero; var holding = new Holding(); foreach (var kvp in marketHoldings) { holding.SymbolHoldings.Add(kvp.Key, kvp.Value); } holding.Comission = commision; holding.Cash = cash; holding.Total = total; holding.Change = change; var dateTime = market.CurrentTime; if (this.HoldingHistory.ContainsKey(dateTime)) { this.HoldingHistory[dateTime] = holding; } else { this.HoldingHistory.Add(dateTime, holding); } }