Changeset 6136
- Timestamp:
- 05/05/11 19:43:53 (14 years ago)
- 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 203 203 <Compile Include="Symbolic\SymbolicTradingModel.cs" /> 204 204 <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> 206 208 <Compile Include="Symbolic\Views\SymbolicTradingSolutionView.Designer.cs"> 207 209 <DependentUpon>SymbolicTradingSolutionView.cs</DependentUpon> … … 218 220 <DependentUpon>TradingSolutionLineChartView.cs</DependentUpon> 219 221 </Compile> 220 <Compile Include="Views\TradingSolutionView.cs" /> 222 <Compile Include="Views\TradingSolutionView.cs"> 223 <SubType>UserControl</SubType> 224 </Compile> 221 225 <Compile Include="Views\TradingSolutionView.Designer.cs"> 222 226 <DependentUpon>TradingSolutionView.cs</DependentUpon> -
branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Views/TradingSolutionLineChartView.cs
r6123 r6136 24 24 using System.Windows.Forms; 25 25 using System.Windows.Forms.DataVisualization.Charting; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core.Views; 27 28 using HeuristicLab.MainForm; 28 29 using HeuristicLab.MainForm.WindowsForms; 30 using System.Collections.Generic; 29 31 30 32 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 32 34 [Content(typeof(ITradingSolution))] 33 35 public partial class TradingSolutionLineChartView : ItemView, ITradingSolutionEvaluationView { 34 private const string PRICEVARIABLE_SERIES_NAME = "Price Variable";36 private const string PRICEVARIABLE_SERIES_NAME = "Price"; 35 37 private const string SIGNALS_SERIES_NAME = "Signals"; 38 private const string ASSET_SERIES_NAME = "Asset"; 36 39 37 40 public new ITradingSolution Content { … … 57 60 this.chart.Series.Clear(); 58 61 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 64 67 65 68 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; 67 70 this.chart.Series[SIGNALS_SERIES_NAME].ChartType = SeriesChartType.FastLine; 68 71 this.chart.Series[SIGNALS_SERIES_NAME].Points.DataBindY(Content.Signals.ToArray()); 69 72 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 //} 84 145 85 146 #region events … … 100 161 101 162 private void Content_ModelChanged(object sender, EventArgs e) { 102 UpdateEstimatedValuesLineChart();163 RedrawChart(); 103 164 } 104 165 … … 106 167 base.OnContentChanged(); 107 168 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 }123 169 } 124 170
Note: See TracChangeset
for help on using the changeset viewer.