Пример #1
0
    private static DatedDataCollectionGen<double> getIndexOfSorts(ConstructGen<double> prices_)
    {
      var returns = prices_.ToReturns();

      var indexLevels = new double[returns.Dates.Count];


      for (int i = 0; i < indexLevels.Length; ++i)
      {
        var todayReturns = returns.GetValues(returns.Dates[i]);

        var todayPrices = prices_.GetValues(returns.Dates[i]);

        // only use returns if the price series has started
        var usedReturns = todayReturns.Where((x, j) => todayPrices[j] > 1e-7);

        var avgReturn = !usedReturns.Any() ? 1d : 1d + usedReturns.Average();

        indexLevels[i] = (i == 0) ? 100d : indexLevels[i - 1] * avgReturn;
      }

      return new DatedDataCollectionGen<double>(prices_.Dates.ToArray(), indexLevels);
    }