Пример #1
0
    public void Refresh()
    {
      // going to get historical values from our database
      ConstructGen<double> hist = new ConstructGen<double>(m_tickers.Count<string>());

      for (int i = 0; i < m_tickers.Length; ++i)
      {
        var histvalues = BbgTalk.HistoryRequester.GetHistory(SI.Data.DataConstants.DATA_START, m_tickers[i],
          "PX_LAST", false, null);

        //histvalues = histvalues.unwind_1d();

        hist.SetColumnValues(i, histvalues);
      }

      hist.SortKeys();

      // initialise 'today's' values to previous day
      hist.SetValues(DateTime.Today, (double[])hist.GetValues(hist.LastDate).Clone());

      double[] avgs = new double[m_windowLength];

      // initialise the avgs array NOTE: today's value is in item with index 0
      for (int i = 0; i < m_windowLength; ++i)
        avgs[i] = hist.GetValues(hist.Dates[hist.Dates.Count - 1 - i]).Average();

      m_avgs = avgs;
      m_liveValues = hist.GetValues(DateTime.Today);
    }
Пример #2
0
    protected ATMVolsRankGroup(FXGroup group_)
    {
      var currencies = Singleton<FXIDs>.Instance.Where(x => x.IsGroup(group_)).ToArray();

      var oneWeek = new ConstructGen<double>(currencies.Select(x => x.Code).ToArray());
      var oneMonth = new ConstructGen<double>(currencies.Select(x => x.Code).ToArray());

      for (int i = 0; i < currencies.Length; ++i)
      {
        {
          var vols = BbgTalk.HistoryRequester.GetHistory(DataConstants.DATA_START, currencies[i].AtTheMoneyVolTicker_1W, "PX_LAST", false);
          oneWeek.SetColumnValues(i, vols);
        }
        {
          var vols = BbgTalk.HistoryRequester.GetHistory(DataConstants.DATA_START, currencies[i].AtTheMoneyVolTicker_1M, "PX_LAST", false);
          oneMonth.SetColumnValues(i, vols);
        }
      }

      {
        oneWeek.SortKeys();
        var avg1W = oneWeek.AvgRows();
        ATM_1W_Avg = avg1W;
        ATM_1W_o6M = avg1W.ToPercentileRanked(126);
        ATM_1W_o1Y = avg1W.ToPercentileRanked(252);
      }

      {
        oneMonth.SortKeys();
        var avg1M = oneMonth.AvgRows();
        ATM_1M_Avg = avg1M;
        ATM_1M_o6M = avg1M.ToPercentileRanked(126);
        ATM_1M_o1Y = avg1M.ToPercentileRanked(252);
      }
    }
Пример #3
0
    public static ConstructGen<double> TestOnCT()
    {
      var str = KnownStructure.US_WN;

      var comps = new[]
      {
        new ChartComponent(),
        new ChartComponent(),
        new ChartComponent(),
      };

      var bondsRollMonthly = Generator.Go(cashBondRollOption_: Generator.CashBondRolling.Monthly);
      var spreadsRollMonthly = new Dictionary<BondCurves, List<CTDLine<BondSpreads>>>();
      spreadsRollMonthly[BondCurves.USD3mLibor] = Generator.GetSpreads(bondsRollMonthly, BondCurves.USD3mLibor, Generator.CashBondRolling.Monthly);

      var cdRollMonthly = new ChartDataSource(comps, spreadsRollMonthly, bondsRollMonthly);

      var impl = StructureFactory.GetStructure(str);

      impl.Configure(comps);

      var data = cdRollMonthly.GetData().SmoothedData.GetEndValues(650);

      var con = new ConstructGen<double>(1);
      con.SetColumnValues(0, data);

      return con;
    }
Пример #4
0
        public static ConstructGen<double> getOHLCSeriesFromBbg(DateTime firstDate_, string ticker_, bool insertNan_ = true)
        {
            var ret = new ConstructGen<double>(new string[] { "PX_OPEN", "PX_HIGH", "PX_LOW", "PX_CLOSE_1D" });
            DateTime[] bbgDates = null;
            for (int i = 0; i < ret.ColumnHeadings.Length; ++i)
            {
                DateTime start;
                if (i == 3)
                    start = firstDate_.AddDays(1);
                else
                    start = firstDate_;

                var b = BbgTalk.HistoryRequester.GetHistory(start, ticker_, ret.ColumnHeadings[i], false);

                if (b == null || b.Length == 0)
                {
                    throw new Exception(string.Format("No data retrieved for given ticker '{0}'", ticker_.ToUpper()));
                }
                else
                    b = HelperMethods.ensureAllWeekdays(b, insertNan_);

                if (i == 3)
                {
                    var closeData = bbgDates.Length > b.Dates.Length ? b.Data : b.Data.Skip(1).ToArray();
                    ret.SetColumnValues(i, bbgDates.SkipLast().ToArray(), closeData);
                }
                else
                {
                    ret.SetColumnValues(i, b.Dates, b.Data);
                    bbgDates = b.Dates;
                }
            }
            
            foreach (var d in ret.Dates.OrderByDescending(d => d))
            {
                if (ret.GetValue(d, 3) == 0)
                {
                    ret.RemoveValues(d);
                }
                else break;                
            }

            return ret;
        }
Пример #5
0
    public static ConstructGen<PairTrade> CalculateWeights(ComID[] commodities_)
    {
      // calculate the weighting
      var con = new ConstructGen<PairTrade>(commodities_.Select(x => x.Name).ToArray());

      for (int i = 0; i < con.ArrayLength; ++i)
        con.SetColumnValues(i, CalculateWeights(commodities_[i]));

      if (con.NeedsToSortKeys())
        con.SortKeys();

      return con;
    }
Пример #6
0
    public static void Collate(BondMarket market_=BondMarket.US)
    {
      var allTenors = SI.ExtensionMethods.CreateArray(1, 30, x => x + 1);

      var con = new ConstructGen<double>(allTenors.Select(x => string.Format("cmt_{0}", x)).ToArray());

      for (int i = 0; i < allTenors.Length; ++i)
      {
        var cr = Get(market_, allTenors[i]);
        if (cr == null) continue;

        con.SetColumnValues(i, cr.Values.GetColumnValuesAsDDC((int) CMTCarry.ColPosition.Carry));
      }

      con.WriteToCSV(string.Format(@"e:\temp\CMTCarry_{0}.csv", market_));
    }
    private static ConstructGen<double> expandToFullUniverse(ConstructGen<double> input_)
    {
      if (input_.ArrayLength == Singleton<FXIDs>.Instance.Count)
        return input_;

      System.Diagnostics.Debug.Assert(input_.ColumnHeadings != null, "Column Headings not set on ConstructGen<double> wts, therefore can't ascertain securities");

      ConstructGen<double> ret = new ConstructGen<double>(Singleton<FXIDs>.Instance.Count);
      ret.ColumnHeadings = Singleton<FXIDs>.Instance.ColumnHeadings;

      for (int i = 0; i < input_.ArrayLength; ++i)
      {
        Currency c = Singleton<FXIDs>.Instance[input_.ColumnHeadings[i]];

        ret.SetColumnValues(c.ArrayIndex, input_.Dates.ToArray<DateTime>(), input_.GetColumnValues(i));
      }
      return ret;
    }
Пример #8
0
    protected override SI.ReturnsEval.DataSeriesEvaluator doPnl(TraderArgs args_, ConstructGen<double> wts_)
    {
      ConstructGen<double> allCcys = new ConstructGen<double>(Singleton<FXIDs>.Instance.ColumnHeadings);

      for (int i = 0; i < args_.Products.Count; ++i)
      {
        ProductFX prod = (ProductFX)args_.Products[i];
        allCcys.SetColumnValues(prod.CoreProduct.ArrayIndex, wts_.Dates.ToArray(), wts_.GetColumnValues(i));
      }

      var result = ReturnsFromFXWeights.DoIt_DailyWeights(allCcys);
      var eval = new ReturnsEval.DataSeriesEvaluator("FX pnl", ReturnsEval.DataSeriesType.Returns);

      if (args_.WtIndicators.Any())
        eval.Name = string.Format("FX : {0}", args_.WtIndicators[0].ToString());
      
      eval.AddInnerSeries(result.CombinedPnl.Dates.ToArray(), result.CombinedPnl.ToArray(), result.CombinedPnl.ColumnHeadings);

      return eval;
    }
Пример #9
0
    public static ConstructGen<double> GetTestData()
    {
      var ret = new ConstructGen<double>(new string[] {"PX_OPEN", "PX_HIGH", "PX_LOW", "PX_CLOSE_1D"});

      for (int i = 0; i < ret.ColumnHeadings.Length; ++i)
      {
        var s = BbgTalk.HistoryRequester.GetHistory(new DateTime(2015, 1, 1), "EUR CMPL CURNCY", ret.ColumnHeadings[i], false);

        if (i == 3)
        {
          s = unwind_1d(s);
        }

        ret.SetColumnValues(i, s.Dates, s.Data);
      }

      ret.Dates.Remove(DateTime.Today);

      return ret;
    }
Пример #10
0
    public static void GoMulti()
    {
      var data = DataRetriever.GetData(indexStart_: "ES", suffix_: "Index", contractIndex_: 1);

      var listOfEvals = new List<ReturnsEval.DataSeriesEvaluator>();

      foreach (var firstWindow in new[] {5, 10, 15, 20, 25, 50, })
      {
        var indic = new SI.Research.Technicals.MACross(firstWindow, firstWindow * 2);

        var signals = indic.GenerateWeightSeries(data, null);

        for (int i = 0; i < signals.Length; ++i)
          signals.Data[i] = signals.Data[i] < 0d ? -1d : 1d;

        signals = CollapseToChanges(signals);

        if (false)
        {
          var con = new ConstructGen<double>(new[] { "Signal", "CleanPrice" });
          con.SetColumnValues(0, signals);

          foreach (var date in con.Dates)
            con.SetValue(date, 1, data.ValueOnExactDate(date));

          con.DisplayInGrid("changes with price levels");
        }

        //signals.DisplayInGrid("changes");


        var pnl = GeneratePnl(data, signals);

        var eval = new ReturnsEval.DataSeriesEvaluator(pnl.Dates, pnl.Data, string.Format("ES_{0}", firstWindow), ReturnsEval.DataSeriesType.Returns);
        listOfEvals.Add(eval);

      }
      listOfEvals.Display("blah");
    }
Пример #11
0
    private void btnCombinePnl_Click(object sender, EventArgs e)
    {
      var all = spreadWeightGeneratorCollectionGrid1.ListOfGenerators;

      if (all.Count() == 0) return;

      ConstructGen<double> con = new ConstructGen<double>(all.Count());
      con.ColumnHeadings = new string[con.ArrayLength];

      for (int i = 0; i < con.ArrayLength; ++i)
      {
        var item = all.ElementAt(i);
        con.ColumnHeadings[i] = item.ToString();
        con.SetColumnValues(i, item.GetSimplePnl());
      }

      if (con.NeedsToSortKeys())
        con.SortKeys();

      var eval = new ReturnsEval.DataSeriesEvaluator("Combined", ReturnsEval.DataSeriesType.Returns);
      eval.AddInnerSeries(con.Dates.ToArray(), con.ToArray(), con.ColumnHeadings);

      eval.Display("Combined");
    }
Пример #12
0
        private static void ConstructTickerTrueSpreads(List<RollResults> results, ref ConstructGen<string> ticker, ref ConstructGen<double> spreads,
                                                  Func<RollResults, RollResultContractItem> GetResults, string headingTickerPostfix, string headingValuePostfix)
        {
            var resultItem = results.Where(r => GetResults(r) != null).ToArray();
            if (resultItem.Any())
            {
                var content =
                    resultItem.Select(r => new { r.Identifier, GetResults(r).TrueSpread }).ToLookup(l => l.Identifier);
                var lookupHeader = resultItem.Select(r => r.Identifier).ToArray();
                ticker = new ConstructGen<string>(content.Count)
                {
                    ColumnHeadings = resultItem.Select(r => r.Identifier + " " + headingTickerPostfix).ToArray()
                };
                spreads = new ConstructGen<double>(content.Count)
                {
                    ColumnHeadings = resultItem.Select(r => r.Identifier + " " + headingValuePostfix).ToArray()
                };

                for (int i = 0; i < ticker.ArrayLength; i++)
                {
                    var series = content[lookupHeader[i]].First().TrueSpread;
                    if (series != null)
                    {
                        ticker.SetColumnValues(i, series.Dates, series.Data.Select(x => x.Name).ToArray());
                        spreads.SetColumnValues(i, series.Dates, series.Data.Select(x => x.Value).ToArray());
                    }
                }
            }            
        }
    public static ConstructGen<double> GetInvoiceSpreadsAsConstruct()
    {
      var configs = invoiceSpreadConfigs().ToArray();

      var con = new ConstructGen<double>(
        configs.Select(x => string.Format("{0}_{1}_{2}", x.Future, x.Series + 1, x.Curve.ToString())).ToArray());

      for (int i = 0; i < configs.Length; ++i)
      {
        var spreads = getInvoiceSpreadsCollectionFromMongo(configs[i]);
        con.SetColumnValues(i,
          new DatedDataCollectionGen<double>(spreads.Lines.Select(x => x.Date).ToArray(),
            spreads.Lines.Select(x => x.InvoiceSpread ?? 0d).ToArray()));
      }

      if (con.NeedsToSortKeys())
        con.SortKeys();

      // feed forward missing values
      {
        var values = con.GetValues(con.Dates[0]);

        for (int i = 1; i < con.Dates.Count; ++i)
        {
          var date = con.Dates[i];

          var todayValues = con.GetValues(date);

          for (int j = 0; j < todayValues.Length; ++j)
          {
            if (todayValues[j] == 0d)
              todayValues[j] = values[j];
          }

          values = todayValues;
        }
      }

      return con;
    }
Пример #14
0
    public static ConstructGen<double> GetFlow(ConstructGen<double> wts_)
    {
      var ret = new ConstructGen<double>(wts_.ColumnHeadings);

      for (int i = 0; i < wts_.ArrayLength; ++i)
      {
        ret.SetColumnValues(i, wts_.GetColumnValuesAsDDC(i).ToDifferences().ToAbs());
      }
      return ret;
    }
    public ConstructGen<double> AllConstantMaturityPrices()
    {
      if (m_allFuturePrices != null)
        return m_allFuturePrices;

      // get the quarterlyin contracts
      var allIMMs = Underlying.IMM_Contracts();

      // build up the list of prices for all contracts

      ConstructGen<double> subCon;
      {
        var con = new ConstructGen<double>(allIMMs.Select(x => x.SymmetryCode).ToArray());
        {
          for (int i = 0; i < con.ArrayLength; ++i)
            con.SetColumnValues(i, allIMMs[i].GetPrices(marketSnapCode_:MarketSnapCode,quoteSource_:QuoteSourceCode,priceType_:1));

          con.SortKeys();
        }

        var dates = SI.Strategy.RatesSpreads.DateHelper.GetBusinessDates(CurveNames.USD3M);

        subCon = new ConstructGen<double>(con.ColumnHeadings);

        foreach (var date in dates)
          if (con.Dates.Contains(date))
            subCon.SetValues(date, con.GetValues(date));
      }

      // create the construct that will hode the constant maturity prices
      // is NumContracts+1 as first column will be interest rate fixing

      m_allFuturePrices =
        new ConstructGen<double>(
          ExtensionMethods.CreateArrayRep(Underlying.FutureStart, NumContracts+1)
            .Select((x, i) => string.Format("{0}cm{1}", x.ToUpper(), i))
            .ToArray());

      foreach (var date in subCon.Dates)
      {
        // set the fixing
        m_allFuturePrices.SetValue(date, 0, Underlying.FixingInstrmnet.GetPrices().ValueOnDate(date)*100d);

        for (int pointIndex = 0; pointIndex < NumContracts; ++pointIndex)
        {
          var daysForward = Convert.ToDouble(pointIndex + 1)*DaysSpan;
          var forwardDate = date.AddDays(daysForward);

          int beforeIndex=-1, afterIndex=-1;
          for (int i = 0; i < allIMMs.Count-1; ++i)
          {
            if(allIMMs[i].Maturity.Value==forwardDate)
            {
              beforeIndex = i;
              afterIndex = i;
              break;
            }
            else if (allIMMs[i].Maturity.Value < forwardDate && allIMMs[i+1].Maturity.Value > forwardDate)
            {
              beforeIndex = i;
              afterIndex = i + 1;
            }
          }

          // were the indexes of the contract that straddle the forward date found?
          if (beforeIndex >= 0)
          {
            if (beforeIndex == afterIndex)
            {
              m_allFuturePrices.SetValue(date, pointIndex+1, 100d-subCon.GetValue(date, beforeIndex));
            }
            else
            {
              var beforeValue = subCon.GetValue(date, beforeIndex);
              var afterValue = subCon.GetValue(date, afterIndex);

              if (beforeValue == 0d || afterValue == 0d)
                continue;

              var width = allIMMs[afterIndex].Maturity.Value - allIMMs[beforeIndex].Maturity.Value;

              var w1 = forwardDate - allIMMs[beforeIndex].Maturity.Value;

              var propAfter = w1.TotalDays/width.TotalDays;

              var interpValue = (afterValue*propAfter) + (beforeValue*(1d - propAfter));

              m_allFuturePrices.SetValue(date, pointIndex+1, 100d-interpValue);
            }
          }
        }
      }

      return m_allFuturePrices;
    }
Пример #16
0
    internal static DatedDataCollectionGen<double> getRollingAvgVol(FXGroup group_, int daysCalc_)
    {
      ConstructGen<double> ccyReturns = Singleton<FXSpots>.Instance.GetData(DataConstants.DATA_START, DateTime.Today).ToReturns();

      Currency[] ccys = Singleton<FXIDs>.Instance.Where(x=>x.IsGroup(group_)).ToArray();

      ConstructGen<double> ccyVols = new ConstructGen<double>(ccys.Length);

      // set individual ccy vols

      for(int i=0;i<ccyVols.ArrayLength;++i)
      {
        DatedDataCollectionGen<double> rets = new DatedDataCollectionGen<double>(ccyReturns.Dates.ToArray(), ccyReturns.GetColumnValues(ccys[i].ArrayIndex));
        DatedDataCollectionGen<double> stdevs = rets.ToRollingStdev(windowSize_: daysCalc_);
        ccyVols.SetColumnValues(i, stdevs.Dates, stdevs.Data);
      }

      // average them

      double[] avgs = new double[ccyVols.Dates.Count];

      for (int i = 0; i < avgs.Length; ++i)
        avgs[i] = ccyVols.GetValues(ccyVols.Dates[i]).Average();

      return new DatedDataCollectionGen<double>(ccyVols.Dates.ToArray(), avgs);
    }
Пример #17
0
      public ChartData GetDataFromCarbonFrame()
      {
          var enabled = Components.Where(x => x.IsReady()).ToList();

          if (!enabled.Any())
              return null;
          
          var listofAllRollDates = new Dictionary<CTCTDType, Tuple<string, DateTime>[]>();
          var listOfAllOldDates = new Dictionary<CTCTDType, Tuple<string, DateTime>[]>();

          ConstructGen<double> con = new ConstructGen<double>(enabled.Count());
          ConstructGen<double> conOld = new ConstructGen<double>(enabled.Count());
          ConstructGen<double> conOldOld = new ConstructGen<double>(enabled.Count());
          ConstructGen<double> conSmoothed = new ConstructGen<double>(enabled.Count());          

          for (int i = 0; i < con.ArrayLength; ++i)
          {
              var curDataTuple = ChartComponentCarbonMediator.GetItemsFromCarbonFrame(enabled[i], g => g.CurrentResult, r => r.TrueSpread);
              con.SetColumnValues(i, curDataTuple.Item2);
              var oDataTuple = ChartComponentCarbonMediator.GetItemsFromCarbonFrame(enabled[i], g => g.OResult, r => r.TrueSpread);
              conOld.SetColumnValues(i, oDataTuple.Item2);
              var ooDataTuple = ChartComponentCarbonMediator.GetItemsFromCarbonFrame(enabled[i], g => g.OOResult, r => r.TrueSpread);
              conOldOld.SetColumnValues(i, ooDataTuple.Item2);
              var smoothDataTuple = ChartComponentCarbonMediator.GetItemsFromCarbonFrame(enabled[i], g => g.SmoothResult, r => r.TrueSpread);
              conSmoothed.SetColumnValues(i, smoothDataTuple.Item2);


              for (int j = 1; j < con.Dates.Count; ++j)
              {
                  // if the bond hasn't changed, then just adjust the previous value by change in the bond
                  if (j < curDataTuple.Item1.Data.Length)
                  { 
                      if (String.CompareOrdinal(curDataTuple.Item1.Data[j], curDataTuple.Item1.Data[j - 1]) != 0)
                      {
                          listofAllRollDates.AddOrAppendDictionaryValueArray(enabled[i].CTCTDType, new Tuple<string, DateTime>(enabled[i].Component + "\n" + curDataTuple.Item1.Data[j], curDataTuple.Item1.Dates[j]));
                          listOfAllOldDates.AddOrAppendDictionaryValueArray(enabled[i].CTCTDType, new Tuple<string, DateTime>(enabled[i].Component + "\n" + curDataTuple.Item1.Data[j - 1], curDataTuple.Item1.Dates[j - 1]));
                      }
                  }
              }
          }


          return new ChartData
          {
              OriginalData = con.SumRows(),
              OldData = conOld.SumRows(),
              OldOldData = conOldOld.SumRows(),
              SmoothedData = conSmoothed.SumRows(),

              NewDates = listofAllRollDates.SelectMany(d => d.Value.Select(v => v.Item2)).Distinct().OrderBy(x => x).ToArray(),
              OldDates = listOfAllOldDates.SelectMany(d => d.Value.Select(v => v.Item2)).Distinct().OrderBy(x => x).ToArray(),
              OldRollTypeDates = listOfAllOldDates.Select(k => new {k.Key, v = k.Value.Distinct().OrderBy(x => x).ToArray() } ).ToDictionary(k => k.Key, k => k.v),
              NewRollTypeDates = listofAllRollDates.Select(k => new { k.Key, v = k.Value.Distinct().OrderBy(x => x).ToArray() }).ToDictionary(k => k.Key, k => k.v),
          };

      }
Пример #18
0
    private void buildData()
    {
      var pxDates = new List<DateTime>();
      var pxValues = new List<double>();

      for (int y = 2003;y <= DateTime.Now.Year; ++y)
      {
        // find the contracts
        var conLon = Long.Underlying.Futures.Where(x => x.Expiry.Year-Long.YearOffset == y && x.Expiry.Month == (int)Long.Month).FirstOrDefault();
        var conShort = Short.Underlying.Futures.Where(x => x.Expiry.Year-Short.YearOffset == y && x.Expiry.Month == (int)Short.Month).FirstOrDefault();

        if (conLon != null && conShort != null)
        {
          m_contractsLongShort.Add(y, new KeyValuePair<ComFutureMeta, ComFutureMeta>(conLon, conShort));

          // last trade of this pair is the earliest lastTrade date of the two
          var lastTrade = (conLon.LastTrade < conShort.LastTrade) ? conLon.LastLastDate : conShort.LastLastDate;
          var dataStart = lastTrade.AddYears(-1);

          if (MyCalendar.IsWeekend(dataStart)) dataStart = MyCalendar.NextWeekDay(dataStart);

          ConstructGen<double> con = new ConstructGen<double>(new string[] { conLon.Ticker, conShort.Ticker, "Diff", "Normalized" });

          con.SetColumnValues((int)dataColumns.Long, conLon.Prices.GetSubValues(dataStart, lastTrade));
          con.SetColumnValues((int)dataColumns.Short, conShort.Prices.GetSubValues(dataStart, lastTrade));

          if (con.NeedsToSortKeys()) con.SortKeys();

          if (con.Dates.Count == 0)
            continue;

          // calculate differences
          foreach (DateTime date in con.Keys)
          {
            double[] d = con.GetValues(date);

            // if we have a value for both contracts on this day
            if (d[(int)dataColumns.Long] != 0d && d[(int)dataColumns.Short] != 0d)
            {
              // save down the difference
              d[(int)dataColumns.Diff] = d[(int)dataColumns.Long] - d[(int)dataColumns.Short];

              if (date.Year == y)
              {
                pxDates.Add(date);
                pxValues.Add(d[2]);
              }
            }
          }

          // normalize differences
          {
            DatedDataCollectionGen<double> diffs = con.GetColumnValuesAsDDC((int)dataColumns.Diff);

            if (diffs==null || diffs.Length == 0)
              continue;

            var min = diffs.Data.Min();
            var max = diffs.Data.Max();

            var normArr = new double[diffs.Length];

            for (int i = 0; i < normArr.Length; ++i)
              normArr[i] = (diffs.Data[i] - min) / (max - min);

            con.SetColumnValues((int)dataColumns.NormalizedDiff, new DatedDataCollectionGen<double>(diffs.Dates, normArr));
          }


          m_yearToPxs.Add(y, con);
        }
      }
      m_hasBuiltData = true;
    }
Пример #19
0
    public static void Go_ES_NthContract(int contractIndex_ = 1)
    {
      var data = DataRetriever.GetData("ES", "Index", contractIndex_);

      var args = new SI.Research.Technicals.MA3ComplexArgs()
      {
        MA1Win = 10,
        MA2Win = 20,
        MA3Win = 40,
        Long = -1d,
        Long_1MA = -0.5d,
        Long_2MA = 0.5d,
        Short = 1d,
        Short_1MA = 0.5d,
        Short_2MA = -0.5d
      };

      var indic = new SI.Research.Technicals.MA3ComplexIndicator(args);

      var signals = indic.GenerateWeightSeries(data, null);

      signals = CollapseToChanges(signals);

      {
        var con = new ConstructGen<double>(new[] { "Signal", "CleanPrice" });
        con.SetColumnValues(0, signals);

        foreach (var date in con.Dates)
          con.SetValue(date, 1, data.ValueOnExactDate(date));

        //con.DisplayInGrid("changes with price levels");
      }

      //signals.DisplayInGrid("changes");


      var pnl = GeneratePnl(data, signals);

      var chart = pnl.ToCumulative().DisplayLineChart("ES");
      chart.AddSeries(data, "FuturePrice", 80, "#,##0.0");

      //var percentilRankedVol = HelperMethods.GetRollingStat(data, 48, (x) => Statistics.Stdev(x)).ToPercentileRanked(252);

      //for (int i = 0; i < percentilRankedVol.Length; ++i)
      //  percentilRankedVol.Data[i] = percentilRankedVol.Data[i] < 0.5 ? 0d : 1d;

      //chart.AddSeries(percentilRankedVol, "Rolling vol", 120, "#,##0.0%");

    }
Пример #20
0
    public static void Go_multiMA3Complex_MR(string futureStart_, string suffix_, int contractIndex_)
    {
      //var data = DataRetriever.GetData("ES", "Index", contractIndex_);
      var data = DataRetriever.GetData(futureStart_, suffix_, contractIndex_);
      DataRetriever.ChartData(futureStart_, suffix_, contractIndex_);

      //data = Singleton<SI.Data.FXSpots>.Instance.GetData(new DateTime(2003, 1, 1), DateTime.Today).GetColumnValuesAsDDC(SI.Data.Currency.TWD.ArrayIndex);
      //data = BbgTalk.HistoryRequester.GetHistory(new DateTime(2009, 1, 1), "ES1 Index", "PX_LAST", true);

      var listOfEvals = new List<ReturnsEval.DataSeriesEvaluator>();

      var mas = new int[] {5, 10, 15, 20, 25, 30, 35, 40, 45, 50};

      mas = new int[] {15};

      foreach (var firstWindow in mas )
      {
        var args = new SI.Research.Technicals.MA3ComplexArgs()
        {
          MA1Win = firstWindow,
          MA2Win = firstWindow*2,
          MA3Win = firstWindow*4,
          Long = -1d,
          Long_1MA = -0.5d,
          Long_2MA = 0.5d,
          Short = 1d,
          Short_1MA = 0.5d,
          Short_2MA = -0.5d
        };

        var indic = new SI.Research.Technicals.MA3ComplexIndicator(args);

        var signals = indic.GenerateWeightSeries(data, null);

        signals = CollapseToChanges(signals);

        if (true)
        {
          var con = new ConstructGen<double>(new[] { "Signal", "CleanPrice" });
          con.SetColumnValues(0, signals);

          foreach (var date in con.Dates)
            con.SetValue(date, 1, data.ValueOnExactDate(date));

          con.DisplayInGrid("changes with price levels");
        }

        //signals.DisplayInGrid("changes");


        var pnl = GeneratePnl(data, signals);

        var eval = new ReturnsEval.DataSeriesEvaluator(pnl.Dates, pnl.Data, string.Format("{2}_{0}_{1}", contractIndex_, args.ToString(),futureStart_), ReturnsEval.DataSeriesType.Returns);
        listOfEvals.Add(eval);
        //eval.Display(eval.Name);

        //pnl.ToCumulative().DisplayLineChart("ES");
      }
      listOfEvals.Display("blah");
    }
Пример #21
0
    public ChartData GetData()
    {
      var enabled = Components.Where(x => x.IsReady()).ToList();

      if (!enabled.Any())
        return null;


      DateTime[] oldDates, rollDates;
        DatedDataCollectionGen<double> primary, old, oldold, ooo, oooo, smthd, oldsmthd, oosmthd, ooosmthd;
      {
        ConstructGen<double> con = new ConstructGen<double>(enabled.Count());
        ConstructGen<double> conOld = new ConstructGen<double>(enabled.Count());
        ConstructGen<double> conOldOld = new ConstructGen<double>(enabled.Count());
        ConstructGen<double> conOOO = new ConstructGen<double>(enabled.Count());
        ConstructGen<double> conOOOO = new ConstructGen<double>(enabled.Count());
        ConstructGen<double> conSmoothed = new ConstructGen<double>(enabled.Count());
        ConstructGen<double> conOldSmoothed = new ConstructGen<double>(enabled.Count());
        ConstructGen<double> conOOSmoothed = new ConstructGen<double>(enabled.Count());
        ConstructGen<double> conOOOSmoothed = new ConstructGen<double>(enabled.Count());
        ConstructGen<double> conOOOOSmoothed = new ConstructGen<double>(enabled.Count());

        var listofAllRollDates = new List<DateTime>();
        var listOfAllOldDates = new List<DateTime>();

        for (int i = 0; i < con.ArrayLength; ++i)
        {
          var currentTuple = getItems(enabled[i], CTDValueGeneration.Current);
          var oldTuple = getItems(enabled[i], CTDValueGeneration.Old);
          var oldOldTuple = getItems(enabled[i], CTDValueGeneration.OldOld);
          var oooTuple = getItems(enabled[i], CTDValueGeneration.OOO);
          var ooooTuple = getItems(enabled[i], CTDValueGeneration.OOOO);

          con.SetColumnValues(i, currentTuple.Item2);
          conOld.SetColumnValues(i, oldTuple.Item2);
          conOldOld.SetColumnValues(i, oldOldTuple.Item2);
          conOOO.SetColumnValues(i, oooTuple.Item2);
          conOOOO.SetColumnValues(i, ooooTuple.Item2);

          {
            var smoothed = new double[con.Dates.Count];
            var oldSmoothed = new double[con.Dates.Count];
            var ooSmoothed = new double[con.Dates.Count];
            var oooSmoothed = new double[con.Dates.Count];
            var ooooSmoothed = new double[con.Dates.Count];
            smoothed[0] = currentTuple.Item2.Data[0];
            oldSmoothed[0] = oldTuple.Item2.Data[0];
            ooSmoothed[0] = oldOldTuple.Item2.Data[0];
            oooSmoothed[0] = oooTuple.Item2.Data[0];
            ooooSmoothed[0] = ooooTuple.Item2.Data[0];

            for (int j = 1; j < smoothed.Length; ++j)
            {
              // if the bond hasn't changed, then just adjust the previous value by change in the bond
              if (String.CompareOrdinal(currentTuple.Item1.Data[j].SymmetryCode, currentTuple.Item1.Data[j - 1].SymmetryCode) == 0)
              {
                smoothed[j] = smoothed[j - 1] + (currentTuple.Item2.Data[j] - currentTuple.Item2.Data[j - 1]);
                oldSmoothed[j] = oldSmoothed[j - 1] + (oldTuple.Item2.Data[j] - oldTuple.Item2.Data[j - 1]);
                ooSmoothed[j] = ooSmoothed[j - 1] + (oldOldTuple.Item2.Data[j] - oldOldTuple.Item2.Data[j - 1]);
                oooSmoothed[j] = oooSmoothed[j - 1] + (oooTuple.Item2.Data[j] - oooTuple.Item2.Data[j - 1]);                
              }
              // the bond has changed... yesterday's [current bond] has become the new [old bond], so adjust previous value by [old bond] value today - the [current bond] value yesterday
              else
              {
                smoothed[j] = smoothed[j - 1] + (oldTuple.Item2.Data[j] - currentTuple.Item2.Data[j - 1]);
                oldSmoothed[j] = oldSmoothed[j - 1] + (oldOldTuple.Item2.Data[j] - oldTuple.Item2.Data[j - 1]);
                ooSmoothed[j] = ooSmoothed[j - 1] + (oooTuple.Item2.Data[j] - oldOldTuple.Item2.Data[j - 1]);
                oooSmoothed[j] = oooSmoothed[j - 1] + (ooooTuple.Item2.Data[j] - oooTuple.Item2.Data[j - 1]);                
                listofAllRollDates.Add(currentTuple.Item1.Dates[j]);
                listOfAllOldDates.Add(currentTuple.Item1.Dates[j - 1]);
              }
            }
            conSmoothed.SetColumnValues(i, new DatedDataCollectionGen<double>(currentTuple.Item2.Dates, smoothed));
            conOldSmoothed.SetColumnValues(i, new DatedDataCollectionGen<double>(currentTuple.Item2.Dates, oldSmoothed));
            conOOSmoothed.SetColumnValues(i, new DatedDataCollectionGen<double>(currentTuple.Item2.Dates, ooSmoothed));
            conOOOSmoothed.SetColumnValues(i, new DatedDataCollectionGen<double>(currentTuple.Item2.Dates, oooSmoothed));
          }


        }

        primary = con.SumRows();
        old = conOld.SumRows();
        oldold = conOldOld.SumRows();
        ooo = conOOO.SumRows();
        oooo = conOOOO.SumRows();
        smthd = conSmoothed.SumRows();
        oldsmthd = conOldSmoothed.SumRows();
        oosmthd = conOOSmoothed.SumRows();
        ooosmthd = conOOOSmoothed.SumRows();
        

        oldDates = listOfAllOldDates.Distinct().OrderBy(x => x).ToArray();
        rollDates = listofAllRollDates.Distinct().OrderBy(x => x).ToArray();

      }

      return new ChartData()
      {
        OriginalData=primary,
        OldData=old,
        OldOldData = oldold,
        OOOData = ooo,
        OOOOData = oooo,
        SmoothedData=smthd,
        OldSmoothedData=oldsmthd,
        OOSmoothedData = oosmthd,
        OOOSmoothedData = ooosmthd,
        NewDates=rollDates,
        OldDates=oldDates
      };
    }
    public static void Test()
    {
      const int lookback = 5;
      const WeightGeneratorType genType = WeightGeneratorType.LongestZScoreOverThreshold;

      SpreadWeightGenerator[] arr = new[]
      {
        new SpreadWeightGenerator(
          new WeightGeneratorArgs()
          {
            Lookback = lookback,
            WeightGenerationType = genType,
            MinWindowLength = 50,
            ZScoreThreshold = 1.3d
          },
          new SpreadDefinition(
            new MonthYearOffset(ComIDs.Sugar, 0, MonthCode.V),
            new MonthYearOffset(ComIDs.Sugar, 1, MonthCode.K),
            false)),
        //new SpreadWeightGenerator(
        //  new WeightGeneratorArgs()
        //  {
        //    Lookback = lookback,
        //    WeightGenerationType = genType,
        //    MinWindowLength = 40,
        //    ZScoreThreshold = 1d
        //  },
        //  new SpreadDefinition(
        //    new MonthYearOffset(ComIDs.Sugar, 0, MonthCode.V),
        //    new MonthYearOffset(ComIDs.Sugar, 1, MonthCode.K),
        //    false)),
        //new SpreadWeightGenerator(
        //  new WeightGeneratorArgs()
        //  {
        //    Lookback = lookback,
        //    WeightGenerationType = genType,
        //    MinWindowLength = 40,
        //    ZScoreThreshold = 1.5d
        //  },
        //  new SpreadDefinition(
        //    new MonthYearOffset(ComIDs.NatGas, 0, MonthCode.H),
        //    new MonthYearOffset(ComIDs.NatGas, 0, MonthCode.X),
        //    false)),
        new SpreadWeightGenerator(
          new WeightGeneratorArgs()
          {
            Lookback = lookback,
            WeightGenerationType = genType,
            MinWindowLength = 60,
            ZScoreThreshold = 1.2d
          },
          new SpreadDefinition(
            new MonthYearOffset(ComIDs.NymexGas, 0, MonthCode.H),
            new MonthYearOffset(ComIDs.NymexGas, 0, MonthCode.X),
            false)),
        //new SpreadWeightGenerator(
        //  new WeightGeneratorArgs()
        //  {
        //    Lookback = lookback,
        //    WeightGenerationType = genType,
        //    MinWindowLength = 90,
        //    ZScoreThreshold = 1.7d
        //  },
        //  new SpreadDefinition(
        //    new MonthYearOffset(ComIDs.NatGas, 0, MonthCode.H),
        //    new MonthYearOffset(ComIDs.NatGas, 0, MonthCode.X),
        //    false)),
        //new SpreadWeightGenerator(
        //  new WeightGeneratorArgs()
        //  {
        //    Lookback = lookback,
        //    WeightGenerationType = genType,
        //    MinWindowLength = 40,
        //    ZScoreThreshold = 1.6d
        //  },
        //  new SpreadDefinition(
        //    new MonthYearOffset(ComIDs.Corn, 0, MonthCode.U),
        //    new MonthYearOffset(ComIDs.Corn, 0, MonthCode.Z),
        //    false)),
        new SpreadWeightGenerator(
          new WeightGeneratorArgs()
          {
            Lookback = lookback,
            WeightGenerationType = genType,
            MinWindowLength = 60,
            ZScoreThreshold = 1.3d
          },
          new SpreadDefinition(
            new MonthYearOffset(ComIDs.Corn, 0, MonthCode.U),
            new MonthYearOffset(ComIDs.Corn, 0, MonthCode.Z),
            false)),
        //new SpreadWeightGenerator(
        //  new WeightGeneratorArgs()
        //  {
        //    Lookback = lookback,
        //    WeightGenerationType = genType,
        //    MinWindowLength = 90,
        //    ZScoreThreshold = 0.8d
        //  },
        //  new SpreadDefinition(
        //    new MonthYearOffset(ComIDs.Corn, 0, MonthCode.U),
        //    new MonthYearOffset(ComIDs.Corn, 0, MonthCode.Z),
        //    false)),
        new SpreadWeightGenerator(
          new WeightGeneratorArgs()
          {
            Lookback = lookback,
            WeightGenerationType = genType,
            MinWindowLength = 40,
            ZScoreThreshold = 1.5d
          },
          new SpreadDefinition(
            new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.U),
            new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.Z),
            false)),
        //new SpreadWeightGenerator(
        //  new WeightGeneratorArgs()
        //  {
        //    Lookback = lookback,
        //    WeightGenerationType = genType,
        //    MinWindowLength = 50,
        //    ZScoreThreshold = 1.3d
        //  },
        //  new SpreadDefinition(
        //    new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.U),
        //    new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.Z),
        //    false)),
        //new SpreadWeightGenerator(
        //  new WeightGeneratorArgs()
        //  {
        //    Lookback = lookback,
        //    WeightGenerationType = genType,
        //    MinWindowLength = 70,
        //    ZScoreThreshold = 1.1d
        //  },
        //  new SpreadDefinition(
        //    new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.U),
        //    new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.Z),
        //    false)),
        new SpreadWeightGenerator(
          new WeightGeneratorArgs()
          {
            Lookback = lookback,
            WeightGenerationType = genType,
            MinWindowLength = 50,
            ZScoreThreshold = 1.6d
          },
          new SpreadDefinition(
            new MonthYearOffset(ComIDs.RBOB, 0, MonthCode.J),
            new MonthYearOffset(ComIDs.RBOB, 0, MonthCode.U),
            false)),
      };

      var comb = new SpreadWeightGeneratorCombiner(arr) {NumDaysForCovariance = 42, TargetVol = 0.06};
      comb.Go();

      {
        var combinedPnl = new ConstructGen<double>(arr.Length);

        combinedPnl.ColumnHeadings =
          arr.Select(x => string.Format("{0} / {1} / {2}", x.Spread, x.Args.MinWindowLength, x.Args.ZScoreThreshold))
            .ToArray();

        for (int i = 0; i < arr.Length; ++i)
          combinedPnl.SetColumnValues(i, arr[i].GetCombinedPnl());

        if (combinedPnl.NeedsToSortKeys())
          combinedPnl.SortKeys();


        var eval = new ReturnsEval.DataSeriesEvaluator("Combined", ReturnsEval.DataSeriesType.Returns);
        eval.AddInnerSeries(combinedPnl.Dates.ToArray(), combinedPnl.ToArray(), combinedPnl.ColumnHeadings);
        eval.Display("Combined");

        combinedPnl.SumRows().ToCumulative().DisplayLineChart("combined pnl of scaled weights");
      }

    }
Пример #23
0
 public static List<DeMarkMarker> GetSetups(DatedDataCollectionGen<double> prices_, int targetSeriesLength_=9)
 {
   var con = new ConstructGen<double>(1);
   con.SetColumnValues(0,prices_);
   return GetSetups(con, 0, 0, 0, 0, targetSeriesLength_);
 }
Пример #24
0
    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;
    }
Пример #25
0
    public static void Go()
    {
      var yearOfFile = 2015;

      var ricList = new[] {"ED", "FEI", "FGBL", "FGBM", "FGBS", "TY", "FLG", "FSS", "FGB", "FBTP", "FOAT", "ES", "FDX"};

      var contractMonths = (MonthCode[])Enum.GetValues(typeof(MonthCode));

      var sourceDir = @"E:\futuresData\MarkFiles";
      var markDir = @"e:\futuresData\MarkEllis2";

      var dict = new SortedDictionary<string, DatedDataCollectionGen<double>>();
      var keys = new List<string>();

      foreach (var ricStart in ricList)
      {
        foreach (var contractYear in new[] { 2015, 2016, 2017 })
        {
          foreach (var contractMonth in contractMonths)
          {
            var dates = new List<DateTime>();
            var values = new List<double>();

            foreach (var monthOfFile in new[] { 6, 7, 8 })
            {
              var searchString = string.Format("*{0}-{1}-{2}{3}{4}.csv", yearOfFile, monthOfFile.ToString("00"), ricStart, contractMonth, contractYear - 2010);

              var files = Directory.GetFiles(sourceDir, searchString);

              if (files.Length == 0)
                continue;


              foreach (var item in CsvFile.Read<FuturesIntradaySaver.FuturesLineItem>(files[0]))
              {
                if (item.gmtDate.HasValue && (item.gmtDate.Value.Minute == 32 || item.gmtDate.Value.Minute == 2))
                {
                  item.Date = TimeZoneHelper.ConvertGmtTimeToLondon(item.gmtDate.Value);
                  item.Time = string.Empty;

                  if (item.Date.Hour < 8)
                    continue;

                  if (item.Date.Hour > 17)
                    continue;

                  dates.Add(item.Date);
                  values.Add((item.CloseAsk + item.CloseBid) / 2d);
                }
              }

              //list.ToCsv(string.Join("\\", markDir,
              //  string.Format("{0}-{1}-{2}{3}{4}", yearOfFile, monthOfFile.ToString("00"), UpdateStaticDataForFutures.MAPS[ricStart].Item1, contractMonth, contractYear - 2010)));
            }

            if(dates.Count>0)
            {
              try
              {
                var ticker = string.Format("{0}{1}{2}", UpdateStaticDataForFutures.MAPS[ricStart].Item1, contractMonth, contractYear - 2010);
                keys.Add(ticker);
                dict.Add(ticker, new DatedDataCollectionGen<double>(dates.ToArray(), values.ToArray()));
              }
              catch (Exception ex_)
              {
                Console.WriteLine(ex_.ToString());
              }
            }
          }
        }
      }

      var con = new ConstructGen<double>(keys.ToArray());
      for(int i=0;i<keys.Count;++i)
      {
        con.SetColumnValues(i,dict[keys[i]]);
      }

      if (con.NeedsToSortKeys())
        con.SortKeys();

      con.WriteToCSV(@"e:\futuresData\markDataTo1732.csv");
    }
Пример #26
0
    public void PublishHourlyVolumes(RollSet set)
    {
      ReadFromCSV();

      var con = new ConstructGen<double>(new[] { MonthFrom, MonthTo, "Spread" });

      var priorVolume = new DatedDataCollectionGen<double>(Lines.Dates,
        Lines.Data.Select(x => x.PriorContractVolume).ToArray())
        .ToGenPeriod(
          periodDateFunction_: x => x,
          areSamePeriodFunction_: functionForSameVolumeBucketing(),
          collationFunction_: x => x.Sum());

      con.SetColumnValues(0, priorVolume);

      var newVolume = new DatedDataCollectionGen<double>(Lines.Dates,
        Lines.Data.Select(x => x.NewContractVolume).ToArray())
        .ToGenPeriod(
          periodDateFunction_: x=>x,
          areSamePeriodFunction_: functionForSameVolumeBucketing(),
          collationFunction_: x => x.Sum());

      con.SetColumnValues(1, newVolume);

      var spreadVolume = new DatedDataCollectionGen<double>(Lines.Dates,
        Lines.Data.Select(x => x.SpreadVolume).ToArray())
        .ToGenPeriod(
          periodDateFunction_: x => x,
          areSamePeriodFunction_: functionForSameVolumeBucketing(),
          collationFunction_: x => x.Sum());

      con.SetColumnValues(2, spreadVolume);

      con.WriteToCSV(string.Format(@"{4}\{0}_{1}_{2}_{3}_HourlyVolume.csv", Rolldate.ToString("yyyyMMdd"), set,
        MonthFrom, MonthTo,DIR));

    }
Пример #27
0
    private static ConstructGen<double> equityFutureComponentPrices()
    {
      var instruments = Singleton<DBFut_Chains>.Instance.Where(x => x.AssetClass.Equals("Equities")).ToArray();
      var con = new ConstructGen<double>(instruments.Select(x => x.BbgTicker).ToArray());

      for (int i = 0; i < instruments.Length; ++i)
      {
        con.SetColumnValues(i, Singleton<DBFut_ChainGenericCache>.Instance.GetGenericSeries(instruments[i]));
      }
      con.SortKeys();
      return con;
    }
Пример #28
0
    public static void EquityCTAEnviron()
    {
      //var copperIndex = Singleton<ComIDs>.Instance.First(x => x.Name.Equals("Copper")).ArrayIndex;

      //var index =
      //  Singleton<ComIndexPrices>.Instance.GetData(DataConstants.DATA_START, DateTime.Today)
      //    .GetColumnValuesAsDDC(copperIndex);

      //var index = EquityIndexOfSorts();

      //var countries = new[] { "Germany", "US" };
      //var instruments =
      //  Singleton<DBFut_Chains>.Instance.Where(
      //    x => x.AssetClass.Equals("Fixed Income") && countries.Any(y => y.Equals(x.Country))).ToArray();

      var instruments=
        Singleton<DBFut_Chains>.Instance.Where(
          x => x.AssetClass.Equals("Equities")).ToArray();

      foreach (var v in instruments)
      {
        var px = Singleton<DBFut_ChainGenericCache>.Instance.GetGenericSeries(v);
        showCombinedStdevFromMean(px, v.BbgTicker, new[] {21, 42, 63, 89, 100, 126, 150, 189, 252, 512});
      }
      return;

      //var instruments = Singleton<DBFut_Chains>.Instance.Where(x => x.AssetClass.Equals("Equities")).ToArray();

      var con = new ConstructGen<double>(instruments.Select(x => x.BbgTicker).ToArray());

      for(int i=0;i<instruments.Length;++i)
      {
        var index = Singleton<DBFut_ChainGenericCache>.Instance.GetGenericSeries(instruments[i]);
        if (index == null || index.Length == 0) continue;

        var prop = getMADiffPercentiles(index, new PercDiffArgs[]
      {
        //new PercDiffArgs() {MA1 = 21, MA2 = 42, PercWindow = 126},
        //new PercDiffArgs() {MA1 = 21, MA2 = 63, PercWindow = 126},
        //new PercDiffArgs() {MA1 = 21, MA2 = 89, PercWindow = 126},
        new PercDiffArgs() {MA1 = 42, MA2 = 89, PercWindow = 126},
        new PercDiffArgs() {MA1 = 42, MA2 = 126, PercWindow = 126},
        new PercDiffArgs() {MA1 = 63, MA2 = 126, PercWindow = 126},
        new PercDiffArgs() {MA1 = 89, MA2 = 180, PercWindow = 126},
        new PercDiffArgs() {MA1 = 89, MA2 = 252, PercWindow = 126},
        new PercDiffArgs() {MA1 = 126, MA2 = 252, PercWindow = 126},

        //new PercDiffArgs() {MA1 = 21, MA2 = 42, PercWindow = 252},
        //new PercDiffArgs() {MA1 = 21, MA2 = 63, PercWindow = 252},
        //new PercDiffArgs() {MA1 = 21, MA2 = 89, PercWindow = 252},
        new PercDiffArgs() {MA1 = 42, MA2 = 89, PercWindow = 252},
        new PercDiffArgs() {MA1 = 42, MA2 = 126, PercWindow = 252},
        new PercDiffArgs() {MA1 = 63, MA2 = 126, PercWindow = 252},
        new PercDiffArgs() {MA1 = 89, MA2 = 180, PercWindow = 252},
        new PercDiffArgs() {MA1 = 89, MA2 = 252, PercWindow = 252},
        new PercDiffArgs() {MA1 = 126, MA2 = 252, PercWindow = 252},

        new PercDiffArgs() {MA1 = 42, MA2 = 89, PercWindow = 504},
        new PercDiffArgs() {MA1 = 42, MA2 = 126, PercWindow = 504},
        new PercDiffArgs() {MA1 = 63, MA2 = 126, PercWindow = 504},
        new PercDiffArgs() {MA1 = 89, MA2 = 180, PercWindow = 504},
        new PercDiffArgs() {MA1 = 89, MA2 = 252, PercWindow = 504},
        new PercDiffArgs() {MA1 = 126, MA2 = 252, PercWindow = 504},
      });

        //var c = new SI.Controls.LineChartDataDisplay();

        //c.AddSeries(index, "index", 40, "##0.0#");
        //c.AddSeries(dates_: prop.Dates,
        //  values_: prop.Data,
        //  desc_: "prop",
        //  yAxisExtent_: 40,
        //  yLabelFormat_: "##0.0#",
        //  color_: System.Drawing.Color.Orange,
        //  yAxisLeft_: false);

        //c.DisplayInShowForm("blah");

        con.SetColumnValues(i, index.ToReturns().MultiplyBy(prop));
      }
      con.SortKeys();

      var eval = new ReturnsEval.DataSeriesEvaluator("combined", DataSeriesType.Returns);
      eval.AddInnerSeries(con.Dates.ToArray(), con.ToArray(), con.ColumnHeadings);
      eval.Display();

    }
Пример #29
0
    internal static void Go()
    {
      var listOfTenors = new[]
      {
        "1Y",
        "2Y",
        "3Y",
        "4Y",
        "5Y",
        "6Y",
        "7Y",
        "8Y",
        "9Y",
        "10Y",
        "11Y",
        "12Y",
        "15Y",
        "20Y",
        "25Y",
        "30Y",
        "40Y",
        "1Y1Y",
        "1Y2Y",
        "1Y3Y",
        "1Y4Y",
        "1Y5Y",
        "1Y6Y",
        "1Y7Y",
        "1Y8Y",
        "1Y9Y",
        "1Y10Y",
        "1Y11Y",
        "1Y12Y",
        "1Y15Y",
        "1Y20Y",
        "1Y25Y",
        "1Y30Y",
        "1Y40Y",
        "2Y1Y",
        "2Y2Y",
        "2Y3Y",
        "2Y4Y",
        "2Y5Y",
        "2Y6Y",
        "2Y7Y",
        "2Y8Y",
        "2Y9Y",
        "2Y10Y",
        "2Y11Y",
        "2Y12Y",
        "2Y15Y",
        "2Y20Y",
        "2Y25Y",
        "2Y30Y",
        "2Y40Y",
        "3Y1Y",
        "3Y2Y",
        "3Y3Y",
        "3Y4Y",
        "3Y5Y",
        "3Y6Y",
        "3Y7Y",
        "3Y8Y",
        "3Y9Y",
        "3Y10Y",
        "3Y11Y",
        "3Y12Y",
        "3Y15Y",
        "3Y20Y",
        "3Y25Y",
        "3Y30Y",
        "3Y40Y",
        "4Y1Y",
        "4Y2Y",
        "4Y3Y",
        "4Y4Y",
        "4Y5Y",
        "4Y6Y",
        "4Y7Y",
        "4Y8Y",
        "4Y9Y",
        "4Y10Y",
        "4Y12Y",
        "4Y15Y",
        "4Y20Y",
        "4Y25Y",
        "4Y30Y",
        "4Y40Y",
        "5Y1Y",
        "5Y2Y",
        "5Y3Y",
        "5Y4Y",
        "5Y5Y",
        "5Y6Y",
        "5Y7Y",
        "5Y8Y",
        "5Y9Y",
        "5Y10Y",
        "5Y12Y",
        "5Y15Y",
        "5Y20Y",
        "5Y25Y",
        "5Y30Y",
        "5Y40Y",
        "6Y1Y",
        "6Y2Y",
        "6Y3Y",
        "6Y4Y",
        "6Y5Y",
        "6Y6Y",
        "6Y7Y",
        "6Y8Y",
        "6Y9Y",
        "6Y10Y",
        "6Y12Y",
        "6Y15Y",
        "6Y20Y",
        "6Y25Y",
        "6Y30Y",
        "7Y1Y",
        "7Y2Y",
        "7Y3Y",
        "7Y4Y",
        "7Y5Y",
        "7Y6Y",
        "7Y7Y",
        "7Y8Y",
        "7Y9Y",
        "7Y10Y",
        "7Y11Y",
        "7Y12Y",
        "7Y15Y",
        "7Y20Y",
        "7Y25Y",
        "7Y30Y",
        "8Y1Y",
        "8Y2Y",
        "8Y3Y",
        "8Y4Y",
        "8Y5Y",
        "8Y6Y",
        "8Y7Y",
        "8Y8Y",
        "8Y9Y",
        "8Y10Y",
        "8Y12Y",
        "8Y15Y",
        "8Y20Y",
        "8Y25Y",
        "8Y30Y",
        "9Y1Y",
        "9Y2Y",
        "9Y3Y",
        "9Y4Y",
        "9Y5Y",
        "9Y6Y",
        "9Y7Y",
        "9Y8Y",
        "9Y9Y",
        "9Y10Y",
        "9Y11Y",
        "9Y12Y",
        "9Y15Y",
        "9Y20Y",
        "9Y25Y",
        "9Y30Y",
        "10Y1Y",
        "10Y2Y",
        "10Y3Y",
        "10Y4Y",
        "10Y5Y",
        "10Y10Y",
        "10Y15Y",
        "10Y20Y",
        "10Y30Y",
        "11Y1Y",
        "11Y2Y",
        "11Y3Y",
        "11Y4Y",
        "11Y5Y",
        "11Y6Y",
        "11Y7Y",
        "11Y10Y",
        "11Y15Y",
        "11Y20Y",
        "11Y25Y",
        "11Y30Y",
        "12Y1Y",
        "12Y2Y",
        "12Y3Y",
        "12Y4Y",
        "12Y5Y",
        "12Y8Y",
        "12Y10Y",
        "12Y20Y",
        "12Y25Y",
        "15Y1Y",
        "15Y2Y",
        "15Y3Y",
        "15Y4Y",
        "15Y5Y",
        "15Y6Y",
        "15Y7Y",
        "15Y8Y",
        "15Y9Y",
        "15Y10Y",
        "15Y15Y",
        "20Y5Y",
        "20Y10Y",
        "25Y5Y",
        "30Y10Y",

      };

      ProductList.RegisterMongoClasses();

      foreach (var curve in new[] { CurveNames.USD3M, CurveNames.EUR6M} )
      {
        var con = new ConstructGen<double>(listOfTenors);

        for (int i = 0; i < listOfTenors.Length; ++i)
        {
          var split = listOfTenors[i].Trim('Y').Split('Y');

          int start=0, foward=0;

          if (split.Length == 1)
          {
            foward = int.Parse(split[0]);
          }
          else
          {
            start = int.Parse(split[0]);
            foward = int.Parse(split[1]);
          }

          var series = xYyY.Get(curve, start, foward);

          con.SetColumnValues(i, series.A_Prices);
        }

        if (con.NeedsToSortKeys())
          con.SortKeys();

        con.WriteToCSV(string.Format(@"e:\temp\Mark_Swaps_{0}.csv", curve));
      }
      
    }
Пример #30
0
    public ConstructGen<double> AllProductPrices(bool fillInGapsWithPrevious_ = true)
    {
      // start by generating price series

      ConstructGen<double> prices = new ConstructGen<double>(Products.Select(x => x.Name).ToArray());

      for (int i = 0; i < Products.Count; ++i)
        prices.SetColumnValues(i, Products[i].Prices);

      if (prices.NeedsToSortKeys())
        prices.SortKeys();

      // fill in any missing values (holidays)
      if(fillInGapsWithPrevious_)
      {
        double[] yesterday = null;

        foreach (var date in prices.Dates)
        {
          var today = prices.GetValues(date);

          if (yesterday != null)
          {
            for(int i=0;i<today.Length;++i)
              if (today[i] == 0d)
                today[i] = yesterday[i];
          }

          yesterday = today;
        }
      }

      return prices;
    }