public void Display(string txt_)
    {
      var lcd = new SI.Controls.LineChartDataDisplay();

      lcd.AddSeries(Scores.Dates, Scores.Data, "Scores", 40, "##0.0");

      DatedDataCollectionGen<double> stdev = HelperMethods.GetRollingStdev(Pxs.ToReturns(), NumDays);
      lcd.AddSeries(stdev.Dates, stdev.Data, "Stdev", 80, "#0.0%");

      DatedDataCollectionGen<double> ma = HelperMethods.GetMA(Pxs, NumDays);
      lcd.AddSeries(Pxs.Dates, Pxs.Data, "Index", 120, "##0.0");
      lcd.AddSeries(ma.Dates, ma.Data, "MA_{0}", 120, "##0.0");

      lcd.DisplayInShowForm(txt_);
    }
示例#2
0
    public static void Go(ComID[] commodities_, bool dispBW_=false)
    {
      var wts = CalculateWeights(commodities_);
      //wts.DisplayInGrid("weightings");
      var pnl = DoPnl(commodities_, wts);
      //pnl.DisplayInGrid("pnl");
      //return;

      var eval = new ReturnsEval.DataSeriesEvaluator("blah", ReturnsEval.DataSeriesType.Returns);

      var weightedBW = !dispBW_ ? null : DoBW(commodities_, wts);

      for (int i = 0; i < pnl.ArrayLength; ++i)
      {
        var comPnl = pnl.GetColumnValuesAsDDC(i);
        eval.AddInnerSeries(comPnl.Dates, comPnl.Data, pnl.ColumnHeadings[i]);

        if (weightedBW != null)
        {
          var chart = new SI.Controls.LineChartDataDisplay();
          chart.AddSeries(
            dates_: comPnl.Dates,
            values_: comPnl.ToCumulative().Data,
            desc_: "pnl",
            yAxisExtent_: 40,
            yLabelFormat_: "##0.0#%",
            yAxisLeft_: true);

          var com = weightedBW.GetColumnValuesAsDDC(i);

          com = new DatedDataCollectionGen<double>(wts.Dates.ToArray(), wts.Dates.Select(x => com.ValueOnDate(x)).ToArray());

          chart.AddSeries(
            dates_: com.Dates,
            values_: com.Data,
            desc_: "bw",
            yAxisExtent_: 40,
            yLabelFormat_: "##0.0###%",
            yAxisLeft_: false);

          chart.DisplayInShowForm(commodities_[i].Mnemonic);
        }
      }

      eval.Evaluate();

      eval.Display();
    }
示例#3
0
    public SI.Controls.LineChartDataDisplay CreateChart()
    {
      var chart = new SI.Controls.LineChartDataDisplay();

      var series = getStructureValues();

      chart.AddSeries(series, DisplayName, 40, "##0.0");



      return chart;
    }
    internal static void Go()
    {

      DatedDataCollectionGen<double> stratReturns = null;

      {
        var pathToReturns = @"e:\stratReturnsSeries.csv";

        var dates = new List<DateTime>();
        var data = new List<double>();
        foreach (var v in CsvFile.Read<LineItem>(pathToReturns))
        {
          dates.Add(v.Date);
          data.Add(v.Return);
        }
        stratReturns = new DatedDataCollectionGen<double>(dates.ToArray(), data.ToArray());
      }

      var stratEval = new ReturnsEval.DataSeriesEvaluator(stratReturns.Dates, stratReturns.Data, "strat", ReturnsEval.DataSeriesType.Returns);


      var spx = BbgTalk.HistoryRequester.GetHistory(stratReturns.Dates[0], "SPX INDEX", "PX_CLOSE_1D", false);

      {
        for (int i = 1; i < spx.Length; ++i)
        {
          spx.Data[i - 1] = spx.Data[i];
        }
      }

      var spxR = spx.ToReturns();
      var spxEval = new ReturnsEval.DataSeriesEvaluator(spxR.Dates, spxR.Data, "SPX", ReturnsEval.DataSeriesType.Returns);
      spxEval.Evaluate();
      spxEval.Display("spx");

      double[] perfDuringDrawdown = new double[stratReturns.Length];

      var listOfRecords = new List<DrawdownItem>();

      foreach (var dd in spxEval.Daily.DrawDowns)
      {
        if (Math.Abs(dd.ValueDown) > 0.03)
        {
          double perf = 0d;
          for (int i = 0; i < stratReturns.Length; ++i)
          {
            if (stratReturns.Dates[i] >= dd.StartDate && stratReturns.Dates[i] <= dd.LowDate)
            {
              perfDuringDrawdown[i] = stratReturns.Data[i];
              perf += stratReturns.Data[i];
            }
          }

          if (perf != 0d)
          {
            stratEval.Evaluate(dd.StartDate, dd.LowDate);
            listOfRecords.Add(new DrawdownItem()
            {
              DateStart = dd.StartDate,
              DateBottomOut = dd.LowDate,
              ChangeInSPX = -dd.ValueDown,
              StrategyPerformance = perf,
              TopStratDrawdown = stratEval.Daily.DrawDowns.Count()==0 ? 0d : -stratEval.Daily.DrawDowns.OrderByDescending(x=>x.ValueDown).First().ValueDown
            });
          }
        }
      }


      {
        var origStratCumulative = stratReturns.ToCumulative();
        var perDuringDrawdownCumulative = new DatedDataCollectionGen<double>(stratReturns.Dates, perfDuringDrawdown).ToCumulative();
        var spxCumulative = spxEval.Daily.ToCumulative();

        var linechart = new SI.Controls.LineChartDataDisplay();

        linechart.AddSeries(origStratCumulative.Dates, origStratCumulative.Data, "Original strategy");
        linechart.AddSeries(perDuringDrawdownCumulative.Dates, perDuringDrawdownCumulative.Data, "Strat during SPX drawdown");

        linechart.AddSeries(spxCumulative.Dates, spxCumulative.Data, "SPX cumulative return", 80, "####0.0");

        {
          var legend =  linechart.AddCompositeLegendForAllLayers();
          legend.Bounds = new System.Drawing.Rectangle(30, 0, 20, 30);
          legend.BoundsMeasureType = Infragistics.UltraChart.Shared.Styles.MeasureType.Percentage;

          legend.PE.ElementType = PaintElementType.Gradient;
          legend.PE.FillGradientStyle = GradientStyle.ForwardDiagonal;
          legend.PE.Fill = Color.DarkGray;
          legend.PE.FillStopColor = Color.DarkGray;
          legend.Border.CornerRadius = 10;
          legend.Border.Color = Color.White;
          legend.Border.Thickness = 1;
        }

        linechart.DisplayInShowForm("Strat analysis during >3% SPX drawdowns");
      }

      var g = listOfRecords.DisplayInGrid("Records");
      g.SetHeaderClickSort();
    }
示例#5
0
    public void ShowPortfolioPnlProgression()
    {
      var pnl = new ConstructGen<double>(Positions.Select(x=>x.Security).ToArray());

      var flp = new System.Windows.Forms.FlowLayoutPanel();

      var listOfInfraBoxes = new List<Infragistics.Win.Misc.UltraGroupBox>();

      for (int i = 0; i < pnl.ArrayLength; ++i)
      {
        var posPnl = Positions[i].GeneratePnlSinceFix();

        for (int d = 0; d < posPnl.Length; ++d)
        {
          pnl.SetValue(posPnl.Dates[d], i, posPnl.Data[d].Close);
        }

        {
          Infragistics.Win.Misc.UltraGroupBox box = new Infragistics.Win.Misc.UltraGroupBox();
          box.Text = string.Format("{0} {1}", Positions[i].Security, Positions[i].Pnl.ToString("###0.0#;(###0.0#);-"));
          box.Tag = Positions[i].Pnl;
          box.Size = new System.Drawing.Size(250, 250);

          var chart = new SI.Controls.BarDataPointChart();
          chart.SetYAxisFormat("##0.0#");
          chart.Dock = System.Windows.Forms.DockStyle.Fill;
          chart.Create(posPnl);
          box.Controls.Add(chart);
          listOfInfraBoxes.Add(box);
        }
      }

      Infragistics.Win.Misc.UltraGroupBox[] boxArr = listOfInfraBoxes.OrderByDescending(x => (double)x.Tag).ToArray();

      {
        double max = 0d;
        foreach (Infragistics.Win.Misc.UltraGroupBox box in boxArr)
        {
          max = Math.Max(max, ((SI.Controls.BarDataPointChart)box.Controls[0]).YAxisAbsoluteMax);
        }

        foreach (Infragistics.Win.Misc.UltraGroupBox box in boxArr)
        {
          ((SI.Controls.BarDataPointChart)box.Controls[0]).SetMaxMinYAxisRange(max);
        }
      }

      foreach (Infragistics.Win.Misc.UltraGroupBox box in boxArr)
      {
        flp.Controls.Add(box);
      }


      pnl.SortKeys();

      for (int i = 0; i < pnl.ArrayLength; ++i)
      {
        DatedDataCollectionGen<double> col = pnl.GetColumnValuesAsDDC(i);
        double last = col.Data[0];

        for (int j = 1; j < col.Length; ++j)
        {
          double val = col.Data[j];

          if (val == 0d)
          {
            if (last != 0d)
            {
              pnl.SetValue(col.Dates[j], i, last);
            }
          }
          else
            last = val;
        }
      }

      DatedDataCollectionGen<double> total = pnl.SumRows();

      KeyValuePair<string, System.Windows.Forms.Control>[] cons = new KeyValuePair<string, System.Windows.Forms.Control>[3];

      var stack = new Controls.SimpleStackedColumnChart();

      stack.Create<string, string>(
        pnl.Dates.Select(x => x.ToString("HH:mm")).ToArray(),
        Positions.Select(x => x.Security).ToArray(),
        pnl.ToArray());
      cons[0] = new KeyValuePair<string, System.Windows.Forms.Control>("position attributed", stack);


      //stack.DisplayInShowForm(string.Format("{0} pnl progression, position attributed", this.Name));

      var lcdd = new SI.Controls.LineChartDataDisplay();
      lcdd.AddSeries(total.Dates, total.Data, Name, 40, "#0.0#");
      lcdd.SetXAxisFormat("HH:mm");
      //lcdd.DisplayInShowForm(string.Format("{0} total pnl progression", m_p.DisplayName));
      cons[1] = new KeyValuePair<string, Control>("total", lcdd);

      cons[2] = new KeyValuePair<string, Control>("comp", flp);

      cons.DisplayInShowForm(string.Format("{0} pnl progression", Name));

    }
示例#6
0
    private static void showCombinedStdevFromMean(DatedDataCollectionGen<double> prices_, string name_, int[] means_)
    {
      var combined =
        HelperMethods.CalculateStdevFromMean(prices_, means_[0], 500).ProcessEachValue(x => x/Math.Sqrt(means_[0]));

      for (int i = 1; i < means_.Length; ++i)
      {
        combined =
          combined.Plus(
            HelperMethods.CalculateStdevFromMean(prices_, means_[i], 500).ProcessEachValue(x => x/Math.Sqrt(means_[i])));
      }

      combined = combined.ProcessEachValue(x => x / Convert.ToDouble(means_.Length));

      if (false)
      {
        var c = new SI.Controls.LineChartDataDisplay();
        c.AddSeries(prices_.Dates, prices_.Data, name_);

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

        c.DisplayInShowForm(name_);
      }

      combined.LagValues(1).MultiplyBy(prices_.ToReturns()).GetEvalAssumeDailyReturns(name_).Display();
    }