Esempio n. 1
0
 public static void CommitBacktest(Strat strat_,
   KeyValuePair<ConstructGen<double>, ReturnsEval.DataSeriesEvaluator> kvp_)
 {
   Logger.Debug(string.Format("Commiting {0} backtest to disk", strat_), typeof (BacktestHelper));
   kvp_.WriteToDisk(getPath(strat_));
 }
Esempio n. 2
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;
      }
    }