public static ConstructGen<double> DoBW(ComID[] coms_, ConstructGen<PairTrade> pairTrades_) { var conRets = new ConstructGen<double>(coms_.Select(x => x.Name).ToArray()); for (int rebalIndex = 0; rebalIndex < pairTrades_.Dates.Count; ++rebalIndex) { var rebalDate = pairTrades_.Dates[rebalIndex]; var tradeEndDate = (rebalIndex < (pairTrades_.Dates.Count - 1) ? pairTrades_.Dates[rebalIndex + 1] : DateTime.Today); var pairTradesOnDay = pairTrades_.GetValues(rebalDate); for (int i = 0; i < pairTradesOnDay.Length; ++i) { var pairTrade = pairTradesOnDay[i]; if (pairTrade == null) continue; var rets = pairTrade.WeightedBackwardation.GetSubValues(rebalDate.AddDays(1d), tradeEndDate); rets = rets.DivideBy(pairTrade.GetStdev(rebalDate, 63) * 3000d); conRets.SetColumnValues(i, rets); } } conRets.SortKeys(); conRets = conRets.ProcessEachCell(x => (double.IsNaN(x) || double.IsInfinity(x) || double.IsNegativeInfinity(x) ? 0d : x)); return conRets; }