Beispiel #1
0
    public static void Go()
    {
      {
        var dailyData = BbgTalk.HistoryRequester.GetHistory(DataRetriever._dataStart, "ES1 Index", "PX_LAST", true);

        var dailyChart = dailyData.DisplayLineChart("Daily ES");

        var firstWindow = 50;

        //dailyChart.AddSeries(HelperMethods.GetRollingStat(dailyData, 21, (x) => HelperMethods.GetK(x)), "K21", 80, "##0.0#");

        //var boll = HelperMethods.CalculateBollingerBands(dailyData, 21, 1.5d);

        //for (int i = 0; i < boll.ArrayLength; ++i)
        //{
        //  dailyChart.AddSeries(boll.GetColumnValuesAsDDC(i), boll.ColumnHeadings[i], 40, "##0.0");
        //}

        dailyChart.AddSeries(HelperMethods.GetRollingStat(dailyData, firstWindow, x => x.Average()), "ma1", 40, "##0.0");
        dailyChart.AddSeries(HelperMethods.GetRollingStat(dailyData, firstWindow*2, x => x.Average()), "ma2", 40, "##0.0");
        dailyChart.AddSeries(HelperMethods.GetRollingStat(dailyData, firstWindow*4, x => x.Average()), "ma3", 40, "##0.0");

        dailyChart.AddSeries(HelperMethods.GetRollingStat(dailyData.ToReturns(),42,x=>Statistics.Stdev(x)*Math.Sqrt(252d)), "vol", 80, "##0.0%");

        var ma3Args = new SI.Research.Technicals.MA3ComplexArgs()
        {
          MA1Win = firstWindow,
          MA2Win = firstWindow*2,
          MA3Win = firstWindow*4
        };

        var signal = new SI.Research.Technicals.MA3ComplexIndicator(ma3Args).GenerateWeightSeries(dailyData,null);
        signal = CollapseToChanges(signal);
        signal.DisplayInGrid("signals");

        var pnl = GeneratePnl(dailyData, signal);

        pnl.ToCumulative().DisplayLineChart("daily ma3 trend");
      }
    }
Beispiel #2
0
    public static void Go()
    {
      var con = DataRetriever.GetData();

      var dailyPrice = con.GetSubsetOnTimespan(con.Dates[0], new TimeSpan(1, 0, 0, 0), false).GetColumnValuesAsDDC(3);
      var dailyMA = HelperMethods.GetMA(dailyPrice, 50);

      var startDate = new DateTime(2014, 2, 1);
      var endDate = new DateTime(2014, 3, 30);
      var doSubset = false;

      if (doSubset)
      {
        con = con.GetSubValues(startDate, endDate);
        dailyMA = dailyMA.GetSubValues(startDate, endDate);
      }

      var frequency = 1;
      con = (frequency == 1) ? con : con.SampleAtFrequency(frequency);

      var closes = con.GetColumnValuesAsDDC(3);


      var m1 = 15;
      var m2 = 30;
      var m3 = 45;

      //chart.AddSeries(HelperMethods.GetMA(closes, m1), "MA"+m1, 40, "###0.0##");
      //chart.AddSeries(HelperMethods.GetMA(closes, m2), "MA"+m2, 40, "###0.0##");
      //chart.AddSeries(HelperMethods.GetMA(closes, m3), "MA"+m3, 40, "###0.0##");
      //chart.AddSeries(HelperMethods.CalculateAO(candlePrices_: con), "OA", 80, "##0.0##");

      if (false) 
      {
        var chart = closes.DisplayLineChart(frequency.ToString());
        chart.SetXAxisFormat("dd-MMM-yyyy HH:mm");
        var pSar = HelperMethods.CalculateParabolicSAR(con);
        var app = chart.AddScatterSeries(pSar.Dates, pSar.Data, "PSar", System.Drawing.Color.Red, 40, "###0.0##");
        ScatterChartAppearance sApp = (ScatterChartAppearance)app.ChartTypeAppearance;
        sApp.IconSize = SymbolIconSize.Small;
        sApp.Icon = SymbolIcon.Triangle;
      }

      //{
      //  var macdLines = HelperMethods.CalcualateMACD(closes);

      //  chart.AddSeries(macdLines.GetColumnValuesAsDDC((int) MACDLines.SignalLine), "Sig", 80, "###0.0###");
      //  chart.AddSeries(macdLines.GetColumnValuesAsDDC((int)MACDLines.MACD1), "MACD1", 80, "###0.0###");
      //}

      // generate a signal
      {
        var ma3args = new SI.Research.Technicals.MA3ComplexArgs
        {
          MA1Win = m1,
          MA2Win = m2,
          MA3Win = m3
        };

        var ma3Indicator = new SI.Research.Technicals.MA3OrderEnforced(ma3args);
        var signals = ma3Indicator.GenerateWeightSeries(closes, null);
        signals = condenseSignals(signals);
        var grid = signals.DisplayInGrid("signals");
        grid.Grid.DisplayLayout.Bands[0].Columns[0].Format = "dd-MMM-yyyy HH:mm";

        var pnl = getPnl(closes, signals);

        pnl.ToCumulative().DisplayLineChart("pnl");
      }
    }
Beispiel #3
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%");

    }
Beispiel #4
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");
    }