Changeset 9499
- Timestamp:
- 05/19/13 11:47:34 (11 years ago)
- Location:
- branches/sluengo/HeuristicLab.Problems.TradeRules
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/sluengo/HeuristicLab.Problems.TradeRules/Evaluator/EvaluatorTradeRules.cs
r9386 r9499 12 12 using HeuristicLab.Problems.DataAnalysis.Symbolic; 13 13 using HeuristicLab.Problems.DataAnalysis; 14 using HeuristicLab.Problems.TradeRules.Evaluator; 14 15 15 16 namespace HeuristicLab.Problems.TradeRules … … 55 56 double tradingCash = OnlineTradeRulesCalculator.Calculate(estimatedValues, problemData, rows); 56 57 58 57 59 return tradingCash; 58 60 } -
branches/sluengo/HeuristicLab.Problems.TradeRules/Grammar.cs
r9262 r9499 112 112 SetSubtreeCount(meanTradeSymbols, 1, 1); 113 113 SetSubtreeCount(macd, 3, 3); 114 SetSubtreeCount(rsi, 1, 1);114 SetSubtreeCount(rsi, 3, 3); 115 115 SetSubtreeCount(comparisonSymbols, 2, 2); 116 116 SetSubtreeCount(and, 2, 2); -
branches/sluengo/HeuristicLab.Problems.TradeRules/HeuristicLab.Problems.TradeRules-1.0.csproj
r9386 r9499 42 42 </ItemGroup> 43 43 <ItemGroup> 44 <Compile Include="Evaluator\OnlineHeuristicTradeRulesCalculator.cs" /> 44 45 <Compile Include="Symbols\AverageTrade.cs" /> 45 46 <Compile Include="Symbols\BoolConstant.cs" /> -
branches/sluengo/HeuristicLab.Problems.TradeRules/Interpreter.cs
r9386 r9499 131 131 132 132 public const byte Variable = 13; 133 public const byte Constant = 14;134 133 public const byte ConstantInt = 16; 135 134 public const byte BoolConstant = 15; … … 156 155 { typeof(Subtraction), OpCodes.Sub }, 157 156 { typeof(Multiplication), OpCodes.Mul }, 158 { typeof(Constant), OpCodes.Constant },159 157 { typeof(BoolConstant), OpCodes.BoolConstant }, 160 158 { typeof(ConstantInt), OpCodes.ConstantInt }, … … 306 304 var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode; 307 305 return ((IList<double>)currentInstr.iArg0)[row] * variableTreeNode.Weight; 308 }309 case OpCodes.Constant:310 {311 var constTreeNode = currentInstr.dynamicNode as ConstantTreeNode;312 return constTreeNode.Value;313 306 } 314 307 case OpCodes.BoolConstant: … … 429 422 //Taking the number of the days for EMA 430 423 double numberOfDays = Evaluate(dataset, ref row, state); 424 double upThreshold = Evaluate(dataset, ref row, state); 425 double downThreshold = Evaluate(dataset, ref row, state); 431 426 432 427 double positiveEMA = 0; … … 477 472 todayRSI = 100 - (100 / (1 + (positiveEMA / negativeEMA))); 478 473 479 if ((yesterdayRSI < 30) && (todayRSI > 30)) outputRSI = 1.0;480 else if ((yesterdayRSI > 70) && (todayRSI < 70)) outputRSI = -1.0;474 if ((yesterdayRSI < downThreshold) && (todayRSI > downThreshold)) outputRSI = 1.0; 475 else if ((yesterdayRSI > upThreshold) && (todayRSI < upThreshold)) outputRSI = -1.0; 481 476 yesterdayRSI = todayRSI; 482 477 } … … 502 497 } 503 498 todayRSI = 100 - (100 / (1 + (positiveEMA / negativeEMA))); 504 if ((yesterdayRSI < 30) && (todayRSI > 30)) outputRSI = 1.0;505 else if ((yesterdayRSI > 70) && (todayRSI < 70)) outputRSI = -1.0;499 if ((yesterdayRSI < downThreshold) && (todayRSI > downThreshold)) outputRSI = 1.0; 500 else if ((yesterdayRSI > upThreshold) && (todayRSI < upThreshold)) outputRSI = -1.0; 506 501 } 507 502 … … 608 603 if (RSIOutputCache == null) RSIOutputCache = new Dictionary<ISymbolicExpressionTreeNode, double>(); 609 604 610 611 605 var state = new InterpreterState(code, necessaryArgStackSize); 612 606 //Evaluate each row of the datase -
branches/sluengo/HeuristicLab.Problems.TradeRules/Solution/TradeRulesSolutionBase.cs
r9386 r9499 9 9 using HeuristicLab.Optimization; 10 10 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 11 using HeuristicLab.Problems.TradeRules.Evaluator; 11 12 12 13 namespace HeuristicLab.Problems.TradeRules … … 17 18 private const string TrainingCashResultName = "Cash after the operation (training)"; 18 19 private const string TestCashResultName = "Cash after the operation (test)"; 20 private const string TrainingUpDaysResultName = "Number of days that stock market goes up (training)"; 21 private const string TrainingDownDaysResultName = "Number of days that stock market goes down (training)"; 22 private const string TrainingHeuristicResultName = "Percentage of right actions after the operation (training)"; 23 private const string TestHeuristicResultName = "Percentage of right actions after the operation (test)"; 19 24 private const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)"; 20 25 private const string TestMeanSquaredErrorResultName = "Mean squared error (test)"; … … 63 68 private set { ((DoubleValue)this[TestCashResultName].Value).Value = value; } 64 69 } 70 71 public double TrainingHeuristic 72 { 73 get { return ((DoubleValue)this[TrainingHeuristicResultName].Value).Value; } 74 private set { ((DoubleValue)this[TrainingHeuristicResultName].Value).Value = value; } 75 } 76 public double TestHeuristic 77 { 78 get { return ((DoubleValue)this[TestHeuristicResultName].Value).Value; } 79 private set { ((DoubleValue)this[TestHeuristicResultName].Value).Value = value; } 80 } 81 82 public double NumberUpDays 83 { 84 get { return ((DoubleValue)this[TrainingUpDaysResultName].Value).Value; } 85 private set { ((DoubleValue)this[TrainingUpDaysResultName].Value).Value = value; } 86 } 87 88 public double NumberDownDays 89 { 90 get { return ((DoubleValue)this[TrainingDownDaysResultName].Value).Value; } 91 private set { ((DoubleValue)this[TrainingDownDaysResultName].Value).Value = value; } 92 } 93 65 94 public double TradeDays 66 95 { … … 78 107 private set { ((DoubleValue)this[TestTotalTradesResultName].Value).Value = value; } 79 108 } 80 109 public double TrainingMeanSquaredError 81 110 { 82 111 get { return ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value; } … … 148 177 protected TradeRulesSolutionBase(IRegressionModel model, IRegressionProblemData problemData) 149 178 : base(model, problemData) { 150 Add(new Result(TrainingCashResultName, "Cash obtained after training period in the stock market", new DoubleValue()));179 /*Add(new Result(TrainingCashResultName, "Cash obtained after training period in the stock market", new DoubleValue()));*/ 151 180 Add(new Result(TestCashResultName, "Cash obtained after test period in the stock market", new DoubleValue())); 181 Add(new Result(TrainingHeuristicResultName, "Percentage of right actions after training period in the stock market", new DoubleValue())); 182 Add(new Result(TestHeuristicResultName, "Percentage of right actions after test period in the stock market", new DoubleValue())); 183 Add(new Result(TrainingUpDaysResultName, "Number of days actions go up in the stock market", new DoubleValue())); 184 Add(new Result(TrainingDownDaysResultName, "Number of days actions down up in the stock market", new DoubleValue())); 185 152 186 Add(new Result(TestTradeDaysResultName, "Number of trading days", new DoubleValue())); 153 187 Add(new Result(TestNumberTradesResultName, "Number of trades", new DoubleValue())); 154 188 Add(new Result(TestTotalTradesResultName, "Total trades", new DoubleValue())); 155 189 } 156 157 [StorableHook(HookType.AfterDeserialization)]158 private void AfterDeserialization()159 {160 // BackwardsCompatibility3.4161 162 #region Backwards compatible code, remove with 3.5163 164 if (!ContainsKey(TrainingMeanAbsoluteErrorResultName))165 {166 OnlineCalculatorError errorState;167 Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleValue()));168 double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices), out errorState);169 TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN;170 }171 172 if (!ContainsKey(TestMeanAbsoluteErrorResultName))173 {174 OnlineCalculatorError errorState;175 Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleValue()));176 double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices), out errorState);177 TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN;178 }179 180 if (!ContainsKey(TrainingMeanErrorResultName))181 {182 OnlineCalculatorError errorState;183 Add(new Result(TrainingMeanErrorResultName, "Mean of errors of the model on the training partition", new DoubleValue()));184 double trainingME = OnlineMeanErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices), out errorState);185 TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN;186 }187 if (!ContainsKey(TestMeanErrorResultName))188 {189 OnlineCalculatorError errorState;190 Add(new Result(TestMeanErrorResultName, "Mean of errors of the model on the test partition", new DoubleValue()));191 double testME = OnlineMeanErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices), out errorState);192 TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN;193 }194 #endregion195 }196 197 198 190 protected void CalculateResults() 199 191 { … … 203 195 IEnumerable<double> estimatedTestValues = EstimatedTestValues; // cache values 204 196 IEnumerable<double> originalTestValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices); 205 206 double trainingCTR = OnlineTradeRulesCalculator.Calculate(estimatedTrainingValues, ProblemData, ProblemData.TrainingIndices); 207 TrainingCash = trainingCTR; 197 198 /*double trainingCTR = OnlineTradeRulesCalculator.Calculate(estimatedTrainingValues, ProblemData, ProblemData.TrainingIndices); 199 TrainingCash = trainingCTR;*/ 200 201 double trainingHTR = OnlineHeuristicTradeRulesCalculator.Calculate(estimatedTrainingValues, ProblemData, ProblemData.TrainingIndices); 202 TrainingHeuristic = trainingHTR; 203 double trainingUpDays = OnlineHeuristicTradeRulesCalculator.getNumberUpDays(); 204 NumberUpDays = trainingUpDays; 205 double trainingDownDays = OnlineHeuristicTradeRulesCalculator.getNumberDownDays(); 206 NumberDownDays = trainingDownDays; 207 208 double testHTR = OnlineHeuristicTradeRulesCalculator.Calculate(estimatedTestValues, ProblemData, ProblemData.TestIndices); 209 TestHeuristic = testHTR; 210 208 211 double testCTR = OnlineTradeRulesCalculator.Calculate(estimatedTestValues, ProblemData, ProblemData.TestIndices); 209 212 TestCash = testCTR; -
branches/sluengo/HeuristicLab.Problems.TradeRules/Symbols/ConstantIntTreeNode.cs
r9262 r9499 51 51 base.ResetLocalParameters(random); 52 52 53 Value = random.Next( 25)+1;53 Value = random.Next(100)+1; 54 54 } 55 55 -
branches/sluengo/HeuristicLab.Problems.TradeRules/Symbols/RSI.cs
r9262 r9499 11 11 class RSI: Symbol 12 12 { 13 private const int minimumArity = 1;14 private const int maximumArity = 1;13 private const int minimumArity = 3; 14 private const int maximumArity = 3; 15 15 16 16 public override int MinimumArity
Note: See TracChangeset
for help on using the changeset viewer.