Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6136


Ignore:
Timestamp:
05/05/11 19:43:53 (14 years ago)
Author:
gkronber
Message:

#1508 improved view for trading solutions.

Location:
branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/HeuristicLab.Problems.DataAnalysis.Trading-3.4.csproj

    r6131 r6136  
    203203    <Compile Include="Symbolic\SymbolicTradingModel.cs" />
    204204    <Compile Include="Symbolic\SymbolicTradingSolution.cs" />
    205     <Compile Include="Symbolic\Views\SymbolicTradingSolutionView.cs" />
     205    <Compile Include="Symbolic\Views\SymbolicTradingSolutionView.cs">
     206      <SubType>UserControl</SubType>
     207    </Compile>
    206208    <Compile Include="Symbolic\Views\SymbolicTradingSolutionView.Designer.cs">
    207209      <DependentUpon>SymbolicTradingSolutionView.cs</DependentUpon>
     
    218220      <DependentUpon>TradingSolutionLineChartView.cs</DependentUpon>
    219221    </Compile>
    220     <Compile Include="Views\TradingSolutionView.cs" />
     222    <Compile Include="Views\TradingSolutionView.cs">
     223      <SubType>UserControl</SubType>
     224    </Compile>
    221225    <Compile Include="Views\TradingSolutionView.Designer.cs">
    222226      <DependentUpon>TradingSolutionView.cs</DependentUpon>
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Views/TradingSolutionLineChartView.cs

    r6123 r6136  
    2424using System.Windows.Forms;
    2525using System.Windows.Forms.DataVisualization.Charting;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core.Views;
    2728using HeuristicLab.MainForm;
    2829using HeuristicLab.MainForm.WindowsForms;
     30using System.Collections.Generic;
    2931
    3032namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    3234  [Content(typeof(ITradingSolution))]
    3335  public partial class TradingSolutionLineChartView : ItemView, ITradingSolutionEvaluationView {
    34     private const string PRICEVARIABLE_SERIES_NAME = "PriceVariable";
     36    private const string PRICEVARIABLE_SERIES_NAME = "Price";
    3537    private const string SIGNALS_SERIES_NAME = "Signals";
     38    private const string ASSET_SERIES_NAME = "Asset";
    3639
    3740    public new ITradingSolution Content {
     
    5760      this.chart.Series.Clear();
    5861      if (Content != null) {
    59         this.chart.Series.Add(PRICEVARIABLE_SERIES_NAME);
    60         this.chart.Series[PRICEVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.PriceVariable;
    61         this.chart.Series[PRICEVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    62         this.chart.Series[PRICEVARIABLE_SERIES_NAME].Points.DataBindY(Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.PriceVariable));
    63         this.UpdateStripLines();
     62        //this.chart.Series.Add(PRICEVARIABLE_SERIES_NAME);
     63        //this.chart.Series[PRICEVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.PriceVariable;
     64        //this.chart.Series[PRICEVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
     65        //this.chart.Series[PRICEVARIABLE_SERIES_NAME].Points.DataBindY(Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.PriceVariable));
     66
    6467
    6568        this.chart.Series.Add(SIGNALS_SERIES_NAME);
    66         this.chart.Series[SIGNALS_SERIES_NAME].LegendText = Content.ItemName;
     69        this.chart.Series[SIGNALS_SERIES_NAME].LegendText = SIGNALS_SERIES_NAME;
    6770        this.chart.Series[SIGNALS_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    6871        this.chart.Series[SIGNALS_SERIES_NAME].Points.DataBindY(Content.Signals.ToArray());
    6972        this.chart.Series[SIGNALS_SERIES_NAME].Tag = Content;
    70         UpdateCursorInterval();
    71       }
    72     }
    73 
    74     private void UpdateCursorInterval() {
    75       var estimatedValues = this.chart.Series[SIGNALS_SERIES_NAME].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0);
    76       var targetValues = this.chart.Series[PRICEVARIABLE_SERIES_NAME].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0);
    77       double estimatedValuesRange = estimatedValues.Max() - estimatedValues.Min();
    78       double targetValuesRange = targetValues.Max() - targetValues.Min();
    79       double interestingValuesRange = Math.Min(Math.Max(targetValuesRange, 1.0), Math.Max(estimatedValuesRange, 1.0));
    80       double digits = (int)Math.Log10(interestingValuesRange) - 3;
    81       double yZoomInterval = Math.Max(Math.Pow(10, digits), 10E-5);
    82       this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval;
    83     }
     73
     74        IEnumerable<double> accumulatedPrice = GetAccumulatedPrices(Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.PriceVariable));
     75        this.chart.Series.Add(PRICEVARIABLE_SERIES_NAME);
     76        this.chart.Series[PRICEVARIABLE_SERIES_NAME].LegendText = PRICEVARIABLE_SERIES_NAME;
     77        this.chart.Series[PRICEVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
     78        this.chart.Series[PRICEVARIABLE_SERIES_NAME].Points.DataBindY(accumulatedPrice.ToArray());
     79        this.chart.Series[PRICEVARIABLE_SERIES_NAME].Tag = Content;
     80
     81        IEnumerable<double> profit = GetProfits(Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.PriceVariable), Content.Signals, Content.ProblemData.TransactionCosts);
     82        IEnumerable<double> accumulatedProfits = GetAccumulatedPrices(profit);
     83        this.chart.Series.Add(ASSET_SERIES_NAME);
     84        this.chart.Series[ASSET_SERIES_NAME].LegendText = ASSET_SERIES_NAME;
     85        this.chart.Series[ASSET_SERIES_NAME].ChartType = SeriesChartType.FastLine;
     86        this.chart.Series[ASSET_SERIES_NAME].Points.DataBindY(accumulatedProfits.ToArray());
     87        this.chart.Series[ASSET_SERIES_NAME].Tag = Content;
     88
     89        this.UpdateStripLines();
     90
     91        // UpdateCursorInterval();
     92      }
     93    }
     94
     95    private IEnumerable<double> GetProfits(IEnumerable<double> returns, IEnumerable<double> signals, double transactionCost) {
     96      double p = 0;
     97      double iterationReturn = 0.0;
     98      foreach (var signalReturn in returns.Zip(signals, (r, s) => new { Return = r, Signal = s })) {
     99        double signal = signalReturn.Signal;
     100        double actualReturn = signalReturn.Return;
     101        if (p == 0 && signal.IsAlmost(0)) {
     102        } else if (p == 0 && signal.IsAlmost(1)) {
     103          p = 1;
     104        } else if (p == 0 && signal.IsAlmost(-1)) {
     105          p = -1;
     106        } else if (p == 1 && signal.IsAlmost(1)) {
     107          iterationReturn = actualReturn;
     108        } else if (p == 1 && signal.IsAlmost(0)) {
     109          iterationReturn = actualReturn - transactionCost;
     110          p = 0;
     111        } else if (p == 1 && signal.IsAlmost(-1)) {
     112          iterationReturn = actualReturn - transactionCost;
     113          p = -1;
     114        } else if (p == -1 && signal.IsAlmost(-1)) {
     115          iterationReturn = -actualReturn;
     116        } else if (p == -1 && signal.IsAlmost(0)) {
     117          iterationReturn = -actualReturn - transactionCost;
     118          p = 0;
     119        } else if (p == -1 && signal.IsAlmost(1)) {
     120          iterationReturn = -actualReturn - transactionCost;
     121          p = -1;
     122        }
     123        yield return iterationReturn;
     124      }
     125    }
     126
     127    private IEnumerable<double> GetAccumulatedPrices(IEnumerable<double> xs) {
     128      double sum = 0;
     129      foreach (var x in xs) {
     130        sum += x;
     131        yield return sum;
     132      }
     133    }
     134
     135    //private void UpdateCursorInterval() {
     136    //  var estimatedValues = this.chart.Series[SIGNALS_SERIES_NAME].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0);
     137    //  var targetValues = this.chart.Series[PRICEVARIABLE_SERIES_NAME].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0);
     138    //  double estimatedValuesRange = estimatedValues.Max() - estimatedValues.Min();
     139    //  double targetValuesRange = targetValues.Max() - targetValues.Min();
     140    //  double interestingValuesRange = Math.Min(Math.Max(targetValuesRange, 1.0), Math.Max(estimatedValuesRange, 1.0));
     141    //  double digits = (int)Math.Log10(interestingValuesRange) - 3;
     142    //  double yZoomInterval = Math.Max(Math.Pow(10, digits), 10E-5);
     143    //  this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval;
     144    //}
    84145
    85146    #region events
     
    100161
    101162    private void Content_ModelChanged(object sender, EventArgs e) {
    102       UpdateEstimatedValuesLineChart();
     163      RedrawChart();
    103164    }
    104165
     
    106167      base.OnContentChanged();
    107168      RedrawChart();
    108     }
    109 
    110     private void UpdateEstimatedValuesLineChart() {
    111       if (InvokeRequired) Invoke((Action)UpdateEstimatedValuesLineChart);
    112       else {
    113         if (this.chart.Series.Count > 0) {
    114           Series s = this.chart.Series.SingleOrDefault(x => x.Tag == Content);
    115           if (s != null) {
    116             s.Points.DataBindY(Content.Signals.ToArray());
    117             s.LegendText = Content.ItemName;
    118             this.UpdateStripLines();
    119             UpdateCursorInterval();
    120           }
    121         }
    122       }
    123169    }
    124170
Note: See TracChangeset for help on using the changeset viewer.