public static SI.Controls.ShowForm DisplayEvals(string[] argsList_)
    {
      List<ReturnsEval.DataSeriesEvaluator> list = GetEvalListFromArgs(argsList_);

      if (list.Count == 0) return null;

      List<KeyValuePair<string, Control>> controlList = new List<KeyValuePair<string, Control>>();

      foreach (ReturnsEval.DataSeriesEvaluator eval in list)
      {
        ReturnsEvalDisplay.ReturnsDisplay rd = new ReturnsDisplay();
        rd.Bind(eval);
        controlList.Add(new KeyValuePair<string, Control>(eval.Name, rd));
      }

      return controlList.DisplayInShowForm("Returns Analysis");
    }
Example #2
0
    public static void Go()
    {
      var list = new List<KeyValuePair<string, Control>>();
      

      foreach (var comid in Singleton<ComIDs>.Instance)
      {
        var items =
          Singleton<ComFuturesMetas>.Instance.Where(x => x.ComID == comid.ID)
            .OrderBy(x => x.LastTrade)
            .Select(x => new FutureItem(x))
            .ToList();

        list.Add(new KeyValuePair<string, Control>(comid.Name, items.DisplayInBoundGrid(showInForm_: false)));
      }

      list.DisplayInShowForm("Contracts");
    }
    private void btnRunStratAgainstEnvironment_Click(object sender, EventArgs e)
    {
      var kvp = SI.Research.FXStrat.BacktestHelper.getWE(m_calc.Strat);
      var cum = new DatedDataCollectionGen<double>(kvp.Value.All.Dates, kvp.Value.All.CumulativeReturnSeries);
      var result = m_calc.Run_newPnl_changes(kvp);

      var newDaily = result.Item1;
      var multChanges = result.Item2;

      lineChartDataDisplayBottom.ClearSeries();

      lineChartDataDisplayBottom.AddSeries(cum, "Original", 40, "##0.0#%");
      lineChartDataDisplayBottom.AddSeries(newDaily.ToCumulative(), "New", 40, "##0.0#%");

      var newWts = m_calc.GiveMeProcessedWeights();


      var listOfControls = new List<KeyValuePair<string, Control>>();

      if (cbShowAfterTransformStats.Checked)
      {
        listOfControls.Add(new KeyValuePair<string, Control>(
          "New performance stats",
          new ReturnsEval.DataSeriesEvaluator(newDaily.Dates, newDaily.Data, "New", ReturnsEval.DataSeriesType.Returns)
            .GetReturnsDisplay()
          ));
      }

      if (cbShowBeforeEval.Checked)
      {
        listOfControls.Add(new KeyValuePair<string, Control>(
          "Original performance stats",
          kvp.Value.GetReturnsDisplay()
          ));
      }

      if (cbShowNewWeights.Checked)
      {
        listOfControls.Add(new KeyValuePair<string, Control>(
          "New weights",
          newWts.DisplayInGrid("New weights", false)
          ));
      }

      if (cbShowNewWeightsAnalysis.Checked)
      {
        var contr = new WtsAnalysisCompareControl();
        var listOfWts = new List<WtsSeriesAnalyzer>();

        //listOfWts.Add(new Strategy.WtsAnalysis.WtsSeriesAnalyzer("Original", kvp.Key,
        //  kvp.Value.GetInnerDailyAsConstruct(), x=>Singleton<CovarianceSource>.Instance.GetCovarianceForDateElesePrevious(x)));

        //listOfWts.Add(new Strategy.WtsAnalysis.WtsSeriesAnalyzer("New", newWts,
        //  ReturnsFromFXWeights.DoIt_DailyWeights(newWts).CombinedPnl,
        //  x => Singleton<CovarianceSource>.Instance.GetCovarianceForDateElesePrevious(x)));

        listOfWts.Add(new WtsSeriesAnalyzer("Original", kvp.Key,
  kvp.Value.GetInnerDailyAsConstruct(), null));

        listOfWts.Add(new WtsSeriesAnalyzer("New", newWts,
          ReturnsFromFXWeights.DoIt_DailyWeights(newWts).CombinedPnl, null));

        contr.Create(listOfWts);

        listOfControls.Add(new KeyValuePair<string, Control>("Weights analysis", contr));

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

        //{
        //  var oldFlow = BacktestHelper.GetFlow(kvp.Key);
        //  var eval = new ReturnsEval.DataSeriesEvaluator("Original flow", ReturnsEval.DataSeriesType.Returns);
        //  eval.AddInnerSeries(oldFlow.Dates.ToArray(), oldFlow.ToArray(), oldFlow.ColumnHeadings);
        //  listOfEvals.Add(eval);
        //}

        //{
        //  var newFlow = BacktestHelper.GetFlow(newWts);
        //  var eval = new ReturnsEval.DataSeriesEvaluator("New flow", ReturnsEval.DataSeriesType.Returns);
        //  eval.AddInnerSeries(newFlow.Dates.ToArray(), newFlow.ToArray(), newFlow.ColumnHeadings);
        //  listOfEvals.Add(eval);
        //}
        //listOfControls.Add(new KeyValuePair<string, Control>(
        //  "Before/After Flow comparison",
        //  listOfEvals.GetComparerDisplay()
        //  ));
      }

      if (cbShowInComparer.Checked)
      {
        var listOfEvals = new List<ReturnsEval.DataSeriesEvaluator>();
        kvp.Value.Name = "Original";
        listOfEvals.Add(kvp.Value);
        listOfEvals.Add(new ReturnsEval.DataSeriesEvaluator(newDaily.Dates, newDaily.Data, "New",
          ReturnsEval.DataSeriesType.Returns));

        listOfControls.Add(new KeyValuePair<string, Control>(
          "Before/After Performance Comparison", 
          listOfEvals.GetComparerDisplay()
          ));
      }

      if (listOfControls.Count > 0)
        listOfControls.DisplayInShowForm("Results");

      //if ((ModifierKeys & Keys.Shift) != 0 && (ModifierKeys & Keys.Control) != 0)
      //{
      //  BacktestHelper.DisplayAvgFlow(kvp.Key, "Before - Average Flow");
      //  BacktestHelper.DisplayAvgFlow(m_calc.GiveMeProcessedWeights(), "After - Average Flow");
      //  return;
      //}

      //if ((ModifierKeys & Keys.Shift) != 0)
      //{
      //  kvp.Value.Display("Original");
      //  new ReturnsEval.DataSeriesEvaluator(newDaily.Dates, newDaily.Data, "New", ReturnsEval.DataSeriesType.Returns).Display("New");
      //  return;
      //}

      //if ((ModifierKeys & Keys.Control) != 0)
      //{
      //  var listOfEvals = new List<ReturnsEval.DataSeriesEvaluator>();
      //  kvp.Value.Name = "Original";
      //  listOfEvals.Add(kvp.Value);
      //  listOfEvals.Add(new ReturnsEval.DataSeriesEvaluator(newDaily.Dates, newDaily.Data, "New",
      //    ReturnsEval.DataSeriesType.Returns));

      //  listOfEvals.Display("Comparison");
      //  return;
      //}
    }
Example #4
0
    private void btnTrade_Click(object sender, EventArgs e)
    {
      try
      {
        TraderArgs args = buildArgs();

        if (args == null) return;

        ReturnsEval.DataSeriesEvaluator eval = null;
        ConstructGen<double> wts = null;
        Trader trader = null;

        if (m_model.ProductType == ProductType.FX)
          trader = Singleton<TraderFX>.Instance;
        else if (m_model.ProductType == ProductType.Commods)
          trader = Singleton<TraderGen>.Instance;
        else if (m_model.ProductType == ProductType.Dynamic || m_model.ProductType==ProductType.EquityFutures || m_model.ProductType==ProductType.FIFutures)
          trader = Singleton<TraderGen>.Instance;
        //else if (m_model.ProductType == ProductType.ComSpread)
        //  trader = Singleton<TraderComSpread>.Instance;
        //else if (m_model.ProductType == ProductType.FXCross)
        //  trader = Singleton<TraderFXCross>.Instance;
        //else
        //  throw new Exception("Trader not set in btnTrade_Click");

        wts = trader.GetWeights(args);

        bool writeToDisk = string.Compare(tbSavePath.Text.Trim(), string.Empty) != 0;

        if ((writeToDisk || cbShowPnl.Checked || cbShowWtsPnlDetail.Checked || cbShowInWeightsComparer.Checked ) && args.RebalFrequency != RebalFreq.JustNow)
          eval = trader.DoPnl(args, wts);

        if (writeToDisk)
        {
          KeyValuePair<ConstructGen<double>, ReturnsEval.DataSeriesEvaluator> kvp = new KeyValuePair<ConstructGen<double>, ReturnsEval.DataSeriesEvaluator>(
            wts,
            eval);
          kvp.Key.ColumnHeadings = args.Products.Select(x => x.ToString()).ToArray<string>();
          kvp.Value.Name = (tbSavePath.Text.Contains(@"\")) ? tbSavePath.Text.Trim().Split('\\').Last<string>() : tbSavePath.Text.Trim();
          kvp.WriteToDisk(@"c:\temp\", string.Format("{0}.we", tbSavePath.Text.Trim()));
        }

        if (cbShowPnl.Checked && eval != null)
        {
          if (cbClearCache.Checked)
          {
            Singleton<SI.Data.CentralEvents>.Instance.FireClearCached();
            System.GC.WaitForPendingFinalizers();
            System.GC.Collect();
            System.GC.WaitForFullGCComplete();
          }

          eval.Display(eval.Name);
        }

        //if (cbShowInWeightsComparer.Checked)
        //{
        //  QC.Common.WtsAnalysis.WtsAnalysisCompareControl wtsComp = new QC.Common.WtsAnalysis.WtsAnalysisCompareControl();
        //  wtsComp.Create(new QC.Common.WtsAnalysis.WtsSeriesAnalyzer(eval.Name, FXStrat.Backtests.expandToFullUniverse(args, wts).ToGenContruct(), eval.GetInnerDailyAsConstruct(),
        //            delegate(DateTime date_)
        //            {
        //              DateTime covDate = date_;
        //              FX.Data.CovarianceItem cov;
        //              while ((cov = Singleton<FX.Data.FXCovarianceSource>.Instance[covDate, false]) == null)
        //                covDate = MyCalendar.PrevWeekDay(covDate);
        //              return cov;
        //            })
        //  );
        //  wtsComp.DisplayInShowForm(string.Format("wts / perf analysis of result ({0})", eval.Name));
        //}

        if (cbShowWeights.Checked)
        {
          wts.DisplayInGrid("Weights");
          //if (trader is TraderFXCross)
          //  ConstructDisplay.Show(TraderFXCross.getInTermsOfUSD(args, wts), Singleton<FX.Data.FXIDs>.Instance.Headings, "In terms of usd");
          //SaveWeightsFX(args, wts, "MA3T_BT");
        }

        if (cbShowOrigScores.Checked)
        {
          var list = new List<KeyValuePair<string, Control>>();
          foreach (var product in args.Products)
          {
            foreach (var indic in args.WtIndicators)
            {
              string key = string.Format("{0}_{1}", product, indic);
              var chart = indic.ChartSignal(product, false);

              list.Add(new KeyValuePair<string, Control>(key, chart));
            }
          }
          list.DisplayInShowForm("indicators");
        }

        //if (cbShowNetExposure.Checked)
        //  DisplayExposure.DoIt(wts, args);

        ////if (cbGenFXIntraDayConfig.Checked)
        ////  FXIntraDayConfigGen.Generator.Gen(args.Products.ToArray(), wts.GetValues(wts.Dates[0]));

        //if (cbShowTradingFreq.Checked)
        //{
        //  //DisplayTradingFrequency.DoItPerWeek(wts.Dates);
        //  DisplayTradingFrequency.DoIt(wts.ToGenContruct());
        //}

        //if (cbShowWtsPnlDetail.Checked && eval != null)
        //{
        //  PnlPosControl ppc = new PnlPosControl();
        //  List<Data.DatedDataCollection2> pxs = new List<FX.Data.DatedDataCollection2>();
        //  foreach (Technicals.ProductBase pb in args.Products)
        //    pxs.Add(pb.GetHistData().Close_Series);
        //  ppc.Create(wts, eval, pxs);
        //  FX.Controls.ShowForm.Show(ppc, "Wts Pnl Detail");
        //}

        //if (cbShowDistScores.Checked)
        //{
        //  FX.Controls.ConstructKernelDistributionChart ckdc = new FX.Controls.ConstructKernelDistributionChart();
        //  ckdc.Create(wts.ToGenContruct(),args.Products.ToArray(),m_distScoresParams.Rows,m_distScoresParams.Cols,30);
        //  FX.Controls.ShowForm.Show(ckdc,"Distribution of scores");
        //}

        //if (cbShowScoresOnZones.Checked)
        //{
        //  for (int i = 0; i < args.Products.Count; ++i)
        //  {
        //    Technicals.ProductBase product = args.Products[i];

        //    QC.Common.CycleAttribPnl.FundWtsAllocationStudyChart chart = new QC.Common.CycleAttribPnl.FundWtsAllocationStudyChart();
        //    chart.Create(
        //      product.GetHistData().Close_Series.ToGen(),
        //      new Data.DatedDataCollectionGen<double>(wts.Dates.ToArray(), wts.GetColumnValues(i)),
        //      wts.Dates[0],
        //      wts.Dates[wts.Dates.Count - 1],
        //      1D);
        //    FX.Controls.ShowForm.Show(chart, string.Format("Scores for '{0}'", product.ToString()));
        //  }

        //}

        //// show number of zero scores?
        //if (cbShowNumZeroScores.Checked)
        //{
        //  ConstructGen<double> d = new ConstructGen<double>(args.Products.Count);
        //  double[] zeroCount = new double[wts.Dates.Count];
        //  for (int i = 0; i < args.Products.Count; ++i)
        //  {
        //    Data.DatedDataCollection2 w = args.WtIndicators[0].GenerateWeightSeries(args.Products[i],args.WtsMinDate);

        //    for (int j = 0; j < wts.Dates.Count; ++j)
        //      if (w.ValueOnDate(wts.Dates[j], args.DayOffset) == 0D)
        //        zeroCount[j] += 1D;
        //  }

        //  FX.Controls.SimpleWtsColumnChart ccc = new FX.Controls.SimpleWtsColumnChart();
        //  string[] headings = wts.Dates.Select<DateTime, string>(x => x.ToString("dd-MMM-yyyy")).ToArray<string>();
        //  ccc.Create(headings, zeroCount);
        //  FX.Controls.ShowForm.Show(ccc, "Zero Score Count");

        //  //AverageZeroWeightsPerMonthChart azwpmc = new AverageZeroWeightsPerMonthChart();
        //  //azwpmc.CreateMonthly(wts,args.Products.ToArray());
        //  //FX.Controls.ShowForm.Show(azwpmc, "Average zero weights per month");
        //}
      }
      finally
      {
        btnTrade.Enabled = true;
        //cmbFxFixType.Enabled = false;
      }
    }