Changeset 6861 for branches/HeuristicLab.Problems.DataAnalysis.Trading
- Timestamp:
- 10/03/11 17:51:02 (13 years ago)
- Location:
- branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Calculators/OnlineSharpeRatioCalculator.cs
r6123 r6861 29 29 private int p; 30 30 private double transactionCost; 31 private int c; 31 32 private OnlineMeanAndVarianceCalculator meanAndVarianceCalculator; 32 33 public double SharpeRatio { … … 55 56 public void Reset() { 56 57 p = 0; 58 c = 0; 57 59 meanAndVarianceCalculator.Reset(); 58 60 } … … 60 62 public void Add(double actualReturn, double signal) { 61 63 double iterationReturn = 0.0; 62 if (p == 0 && signal.IsAlmost(0)) { 63 } else if (p == 0 && signal.IsAlmost(1)) { 64 p = 1; 65 } else if (p == 0 && signal.IsAlmost(-1)) { 66 p = -1; 67 } else if (p == 1 && signal.IsAlmost(1)) { 68 iterationReturn = actualReturn; 69 } else if (p == 1 && signal.IsAlmost(0)) { 70 iterationReturn = actualReturn - transactionCost; 71 p = 0; 72 } else if (p == 1 && signal.IsAlmost(-1)) { 73 iterationReturn = actualReturn - transactionCost; 74 p = -1; 75 } else if (p == -1 && signal.IsAlmost(-1)) { 76 iterationReturn = -actualReturn; 77 } else if (p == -1 && signal.IsAlmost(0)) { 78 iterationReturn = -actualReturn - transactionCost; 79 p = 0; 80 } else if (p == -1 && signal.IsAlmost(1)) { 81 iterationReturn = -actualReturn - transactionCost; 82 p = -1; 64 if (c == 0) { 65 p = (int)signal; 66 iterationReturn = 0; 67 c++; 68 } else { 69 if (p == 0 && signal.IsAlmost(0)) { 70 } else if (p == 0 && signal.IsAlmost(1)) { 71 p = 1; 72 } else if (p == 0 && signal.IsAlmost(-1)) { 73 p = -1; 74 } else if (p == 1 && signal.IsAlmost(1)) { 75 iterationReturn = actualReturn; 76 } else if (p == 1 && signal.IsAlmost(0)) { 77 iterationReturn = actualReturn - transactionCost; 78 p = 0; 79 } else if (p == 1 && signal.IsAlmost(-1)) { 80 iterationReturn = actualReturn - transactionCost; 81 p = -1; 82 } else if (p == -1 && signal.IsAlmost(-1)) { 83 iterationReturn = -actualReturn; 84 } else if (p == -1 && signal.IsAlmost(0)) { 85 iterationReturn = -(actualReturn - transactionCost); 86 p = 0; 87 } else if (p == -1 && signal.IsAlmost(1)) { 88 iterationReturn = -(actualReturn - transactionCost); 89 p = 1; 90 } 91 c++; 83 92 } 84 93 meanAndVarianceCalculator.Add(iterationReturn); -
branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Symbolic/SingleObjective/SymbolicTradingSingleObjectiveSharpeRatioEvaluator.cs
r6123 r6861 68 68 69 69 private static IEnumerable<double> GetSignals(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, Dataset dataset, IEnumerable<int> rows) { 70 double signal = 0; 71 double prevSignal = 0; 72 foreach (var x in interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows)) { 73 if (prevSignal == 1) { 74 signal = x > -1 ? 1 : x > -2 ? 0 : -1; // 0, -1, -2 75 } else if (prevSignal == 0) { 76 signal = x > 1 ? 1 : x < -1 ? -1 : 0; // 1, 0 , -1 77 } else if (prevSignal == -1) { 78 signal = x < 1 ? -1 : x < 2 ? 0 : 1; // 2, 1, 0 79 } 80 yield return signal; 81 prevSignal = signal; 82 } 70 return from x in interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows) 71 select x > 0.5 ? 1.0 : x < 0.5 ? -1.0 : 0.0; 83 72 } 84 73 -
branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Symbolic/SymbolicTradingModel.cs
r6126 r6861 20 20 #endregion 21 21 22 using System.Linq; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 48 49 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter = Interpreter; 49 50 ISymbolicExpressionTree tree = SymbolicExpressionTree; 50 double signal = 0; 51 double prevSignal = 0; 52 foreach (var x in interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows)) { 53 if (prevSignal == 1) { 54 signal = x > -1 ? 1 : x > -2 ? 0 : -1; // 0, -1, -2 55 } else if (prevSignal == 0) { 56 signal = x > 1 ? 1 : x < -1 ? -1 : 0; // 1, 0 , -1 57 } else if (prevSignal == -1) { 58 signal = x < 1 ? -1 : x < 2 ? 0 : 1; // 2, 1, 0 59 } 60 yield return signal; 61 prevSignal = signal; 62 } 51 return from x in interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows) 52 select x > 0.5 ? 1.0 : x < 0.5 ? -1.0 : 0.0; 63 53 } 64 54 } -
branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Views/TradingSolutionLineChartView.cs
r6138 r6861 94 94 95 95 private IEnumerable<double> GetProfits(IEnumerable<double> returns, IEnumerable<double> signals, double transactionCost) { 96 double p = 0; 97 foreach (var signalReturn in returns.Zip(signals, (r, s) => new { Return = r, Signal = s })) { 98 double iterationReturn = 0.0; 96 double p = signals.First(); 97 yield return 0.0; 98 foreach (var signalReturn in returns.Skip(1).Zip(signals.Skip(1), (r, s) => new { Return = r, Signal = s })) { 99 double iterationReturn = 0; 99 100 double signal = signalReturn.Signal; 100 101 double actualReturn = signalReturn.Return; 101 102 if (p == 0 && signal.IsAlmost(0)) { 102 103 } else if (p == 0 && signal.IsAlmost(1)) { 104 iterationReturn = 0; 103 105 p = 1; 104 106 } else if (p == 0 && signal.IsAlmost(-1)) { 107 iterationReturn = 0; 105 108 p = -1; 106 109 } else if (p == 1 && signal.IsAlmost(1)) { … … 115 118 iterationReturn = -actualReturn; 116 119 } else if (p == -1 && signal.IsAlmost(0)) { 117 iterationReturn = - actualReturn - transactionCost;120 iterationReturn = -(actualReturn - transactionCost); 118 121 p = 0; 119 122 } else if (p == -1 && signal.IsAlmost(1)) { 120 iterationReturn = - actualReturn - transactionCost;121 p = -1;123 iterationReturn = -(actualReturn - transactionCost); 124 p = 1; 122 125 } 123 126 yield return iterationReturn;
Note: See TracChangeset
for help on using the changeset viewer.