public static void Go_Mark()
    {
      var tickers = new [] {"ES"};

      //var holidays = SI.Strategy.BondSpreadAnalysis.Mongo.DataBuilder.GetEUTADates();

      var startMonth = new DateTime(2010, 1, 15);
      var endMonth = new DateTime(2015, 11, 05);

      var numContracts = 2;

      Func<DateTime, bool> closePointFunc = (date) =>
      {
        if (MyCalendar.IsWeekend(date.Date))// || holidays.Contains(date.Date))
          return false;

        if (date.Minute != 20 && date.Minute != 50)
          return false;

        if (date.Hour < 8) return false;

        if (date.Hour >= 18) return false;

        if (date.Hour == 17 && date.Minute > 30) return false;

        return true;
      };

      foreach (var ticker in tickers)
      {
        var rollDates = new List<DateTime>();

        var ric_And_lastTrade = new List<Tuple<string, DateTime>>();
        {
          var sql =
            string.Format(
              "select f.SymmetryCode, ff.LastTradeDate, fid.Identifier from fI f, fifuture ff, fiidentifier fid where f.SymmetryCode like '{0}%Index' and f.fiid=ff.fiid and fid.fiid=f.fiid and fid.IdentifierType =4 order by ff.LastTradeDate",
              ticker);

          var ds = Singleton<ConnMngr>.Instance.ExecuteGetSingleTable(DBNames.SQLSERVER_SYMMETRYTS, sql);

          foreach (DataRow row in ds.Rows)
          {
            ric_And_lastTrade.Add(new Tuple<string, DateTime>(DataRowHelpers.GetString(row, "Identifier"),
              DataRowHelpers.GetDate(row, "LastTradeDate")));
          }
        }

        // only take quarterly contracts
        ric_And_lastTrade =
          ric_And_lastTrade.Select(
            x => new { Tuple = x, MonthCode = FutureMaintainer.OutputLine.GetBaseMonthYear(x.Item1).Item2 })
            .Where(
              x =>
                x.MonthCode == MonthCode.H || x.MonthCode == MonthCode.M || x.MonthCode == MonthCode.U ||
                x.MonthCode == MonthCode.Z)
            .Select(x => x.Tuple).ToList();


        var cons = new List<OHLCRow>[numContracts];

        for (int contractIndex = 0; contractIndex < numContracts; ++contractIndex)
        {
          var contractCon = new List<OHLCRow>();
          cons[contractIndex] = contractCon;

          var outputFile = string.Format(@"{0}\{1}_{2}.csv", MARK_OUT_DIR, ticker, contractIndex + 1);

          var monthDate = startMonth;

          while (monthDate < endMonth)
          {
            var livecontracts = ric_And_lastTrade.Where(
              x => x.Item2 > monthDate || (x.Item2.Month == monthDate.Month && x.Item2.Year == monthDate.Year));

            var frontContract = livecontracts.ElementAt(0);
            var desiredContract = livecontracts.ElementAt(contractIndex);

            // get all the contract's values within the pricingMonth_

            var contractInMonthValues = getDDC(
              directory_:FUTURES_DIR,
              ticker_: desiredContract.Item1,
              pricingMonth_: monthDate.Month,
              pricingYear_: monthDate.Year,
              isCloseMinute_: closePointFunc);

            // if we are in the pricingMonth_ of the roll of the first contract, then we need to take only some of the values,
            // and the rest from the next contract
            if (monthDate.Month == frontContract.Item2.Month && monthDate.Year == frontContract.Item2.Year)
            {
              var lastContractDate = frontContract.Item2.AddDays(-7d);

              rollDates.Add(lastContractDate.Date);

              contractCon.AddRange(contractInMonthValues.Data.TakeWhile(dataPoint => dataPoint.Date < lastContractDate.Date));

              // now need to get the next contract values and fill for rest of pricingMonth_

              var nextContract = livecontracts.ElementAt(contractIndex + 1);

              var nextContractValues = getDDC(
                directory_: FUTURES_DIR,
                ticker_: nextContract.Item1,
                pricingMonth_: monthDate.Month,
                pricingYear_: monthDate.Year,
                isCloseMinute_: closePointFunc);

              contractCon.AddRange(nextContractValues.Data.Where(dataPoint => dataPoint.Date >= lastContractDate.Date));
            }
            else
            {
              contractCon.AddRange(contractInMonthValues.Data);
            }
            monthDate = monthDate.AddMonths(1);
          }
          contractCon.WriteToCSV(outputFile);
        }

        var ddc = new DatedDataCollectionGen<RollRow>(
          cons[0].Select(x => x.Date).ToArray(),
          cons[0].Select(x => new RollRow() {Date=x.Date, FirstContract = x.Ticker, FirstPrice = x.Close}).ToArray());

        for (int i = 1; i < numContracts; ++i)
        {
          foreach (var v in cons[i])
          {
            var ddV = ddc.ValueOnExactDate(v.Date);

            if (ddV == null) continue;

            ddV.SetContrct(i, v.Ticker);
            ddV.SetPrice(i, v.Close);
          }
        }

        ddc.Data.WriteToCSV(string.Format(@"{0}\{1}_combined.csv", MARK_OUT_DIR, ticker));
      }
    }
    public static void GoAleks()
    {
      var futuresTickers = new[]
      {
        /*"TU","TY","US","WN",*/"FV"
      };

      Func<DateTime, bool> closePointFunc = (date) =>
      {
        if (MyCalendar.IsWeekend(date.Date))
          return false;

        if (date.Minute != 0 && date.Minute != 30)
          return false;

        return true;
      };
      var endMonth = new DateTime(2015, 12, 05);

      foreach (var ticker in futuresTickers)
      {
        var rollDates = new List<DateTime>();


        var ric_And_lastTrade = new List<Tuple<string, DateTime>>();
        {
          var sql =
            string.Format(
              "select f.SymmetryCode, ff.LastTradeDate, fid.Identifier from fI f, fifuture ff, fiidentifier fid where f.SymmetryCode like '{0}%Comdty' and f.fiid=ff.fiid and fid.fiid=f.fiid and fid.IdentifierType =4 order by ff.LastTradeDate",
              ticker);

          var ds = Singleton<ConnMngr>.Instance.ExecuteGetSingleTable(DBNames.SQLSERVER_SYMMETRYTS, sql);

          foreach (DataRow row in ds.Rows)
          {
            ric_And_lastTrade.Add(new Tuple<string, DateTime>(DataRowHelpers.GetString(row, "Identifier"),
              DataRowHelpers.GetDate(row, "LastTradeDate")));
          }
        }

        // only take quarterly contracts
        ric_And_lastTrade =
          ric_And_lastTrade.Select(
            x => new { Tuple = x, MonthCode = FutureMaintainer.OutputLine.GetBaseMonthYear(x.Item1).Item2 })
            .Where(
              x =>
                x.MonthCode == MonthCode.H || x.MonthCode == MonthCode.M || x.MonthCode == MonthCode.U ||
                x.MonthCode == MonthCode.Z)
            .Select(x => x.Tuple).ToList();


        var cons = new List<OHLCRow>[2];
        var contractIndicies = new[] { 0, 1 };

        for (int i = 0; i < contractIndicies.Length; ++i)
        {
          var conOuterCon = new List<OHLCRow>();
          cons[i] = conOuterCon;

          var contractIndex = contractIndicies[i];

          var outputFile = string.Format(@"{0}\{1}_{2}.csv", ALEKS_OUT_DIR, ticker, contractIndex + 1);

          var monthDate = new DateTime(2015, 1, 15);

          while (monthDate < endMonth)
          {
            var livecontracts = ric_And_lastTrade.Where(
              x => x.Item2 > monthDate || (x.Item2.Month == monthDate.Month && x.Item2.Year == monthDate.Year));

            var frontContract = livecontracts.ElementAt(0);
            var desiredContract = livecontracts.ElementAt(contractIndex);

            // get all the contract's values within the pricingMonth_


            var contractInMonthValues = getDDC(
              directory_: FUTURES_DIR,
              ticker_: desiredContract.Item1,
              pricingMonth_: monthDate.Month,
              pricingYear_: monthDate.Year,
              isCloseMinute_: closePointFunc);

            // if we are in the pricingMonth_ of the roll of the first contract, then we need to take only some of the values,
            // and the rest from the next contract
            if (monthDate.Month == frontContract.Item2.Month && monthDate.Year == frontContract.Item2.Year)
            {
              var lastContractDate = frontContract.Item2.AddDays(-7d);

              rollDates.Add(lastContractDate.Date);

              conOuterCon.AddRange(contractInMonthValues.Data.TakeWhile(dataPoint => dataPoint.Date < lastContractDate.Date));

              // now need to get the next contract values and fill for rest of pricingMonth_

              var nextContract = livecontracts.ElementAt(contractIndex + 1);

              var nextContractValues = getDDC(
                directory_: FUTURES_DIR,
                ticker_: nextContract.Item1,
                pricingMonth_: monthDate.Month,
                pricingYear_: monthDate.Year,
                isCloseMinute_: closePointFunc);

              conOuterCon.AddRange(nextContractValues.Data.Where(dataPoint => dataPoint.Date >= lastContractDate.Date));
            }
            else
            {
              conOuterCon.AddRange(contractInMonthValues.Data);
            }
            monthDate = monthDate.AddMonths(1);
          }
          conOuterCon.WriteToCSV(outputFile);
        }

        var rollRows = new List<RollRow>();
        var index = 0;
        foreach (var v in cons[0])
        {
          var rollRow = new RollRow()
          {
            Date = v.Date,
            FirstContract = v.Ticker,
            FirstPrice = v.Close
          };

          for (; index < cons[1].Count; ++index)
          {
            if (cons[1][index].Date > v.Date)
            {
              index -= 3;
              index = Math.Max(0, index);
              break;
            }

            if (cons[1][index].Date == v.Date)
            {
              rollRow.SecondContract = cons[1][index].Ticker;
              rollRow.SecondPrice = cons[1][index].Close;
              break;
            }
          }

          rollRows.Add(rollRow);
        }

        rollRows.WriteToCSV(string.Format(@"{0}\{1}_combined.csv", ALEKS_OUT_DIR, ticker));
      }


    }