Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9499


Ignore:
Timestamp:
05/19/13 11:47:34 (12 years ago)
Author:
sluengo
Message:
 
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  
    1212using HeuristicLab.Problems.DataAnalysis.Symbolic;
    1313using HeuristicLab.Problems.DataAnalysis;
     14using HeuristicLab.Problems.TradeRules.Evaluator;
    1415
    1516namespace HeuristicLab.Problems.TradeRules
     
    5556            double tradingCash = OnlineTradeRulesCalculator.Calculate(estimatedValues, problemData, rows);
    5657           
     58
    5759            return tradingCash;
    5860        }
  • branches/sluengo/HeuristicLab.Problems.TradeRules/Grammar.cs

    r9262 r9499  
    112112        SetSubtreeCount(meanTradeSymbols, 1, 1);
    113113        SetSubtreeCount(macd, 3, 3);
    114         SetSubtreeCount(rsi, 1, 1);
     114        SetSubtreeCount(rsi, 3, 3);
    115115        SetSubtreeCount(comparisonSymbols, 2, 2);
    116116        SetSubtreeCount(and, 2, 2);
  • branches/sluengo/HeuristicLab.Problems.TradeRules/HeuristicLab.Problems.TradeRules-1.0.csproj

    r9386 r9499  
    4242  </ItemGroup>
    4343  <ItemGroup>
     44    <Compile Include="Evaluator\OnlineHeuristicTradeRulesCalculator.cs" />
    4445    <Compile Include="Symbols\AverageTrade.cs" />
    4546    <Compile Include="Symbols\BoolConstant.cs" />
  • branches/sluengo/HeuristicLab.Problems.TradeRules/Interpreter.cs

    r9386 r9499  
    131131
    132132            public const byte Variable = 13;
    133             public const byte Constant = 14;
    134133            public const byte ConstantInt = 16;
    135134            public const byte BoolConstant = 15;
     
    156155      { typeof(Subtraction), OpCodes.Sub },
    157156      { typeof(Multiplication), OpCodes.Mul },
    158       { typeof(Constant), OpCodes.Constant },
    159157      { typeof(BoolConstant), OpCodes.BoolConstant },
    160158      { typeof(ConstantInt), OpCodes.ConstantInt },
     
    306304                        var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode;
    307305                        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;
    313306                    }
    314307                case OpCodes.BoolConstant:
     
    429422                        //Taking the number of the days for EMA
    430423                        double numberOfDays = Evaluate(dataset, ref row, state);
     424                        double upThreshold = Evaluate(dataset, ref row, state);
     425                        double downThreshold = Evaluate(dataset, ref row, state);
    431426
    432427                        double positiveEMA = 0;
     
    477472                                        todayRSI = 100 - (100 / (1 + (positiveEMA / negativeEMA)));
    478473
    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;
    481476                                        yesterdayRSI = todayRSI;
    482477                                    }
     
    502497                                }
    503498                                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;
    506501                            }
    507502
     
    608603            if (RSIOutputCache == null) RSIOutputCache = new Dictionary<ISymbolicExpressionTreeNode, double>();
    609604
    610 
    611605            var state = new InterpreterState(code, necessaryArgStackSize);
    612606            //Evaluate each row of the datase
  • branches/sluengo/HeuristicLab.Problems.TradeRules/Solution/TradeRulesSolutionBase.cs

    r9386 r9499  
    99using HeuristicLab.Optimization;
    1010using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
     11using HeuristicLab.Problems.TradeRules.Evaluator;
    1112
    1213namespace HeuristicLab.Problems.TradeRules
     
    1718        private const string TrainingCashResultName = "Cash after the operation (training)";
    1819        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)";
    1924        private const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)";
    2025        private const string TestMeanSquaredErrorResultName = "Mean squared error (test)";
     
    6368            private set { ((DoubleValue)this[TestCashResultName].Value).Value = value; }
    6469        }
     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
    6594        public double TradeDays
    6695        {
     
    78107            private set { ((DoubleValue)this[TestTotalTradesResultName].Value).Value = value; }
    79108        }
    80         public double TrainingMeanSquaredError
     109       public double TrainingMeanSquaredError
    81110        {
    82111            get { return ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value; }
     
    148177    protected TradeRulesSolutionBase(IRegressionModel model, IRegressionProblemData problemData)
    149178      : 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()));*/
    151180      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     
    152186      Add(new Result(TestTradeDaysResultName, "Number of trading days", new DoubleValue()));
    153187      Add(new Result(TestNumberTradesResultName, "Number of trades", new DoubleValue()));
    154188      Add(new Result(TestTotalTradesResultName, "Total trades", new DoubleValue()));
    155189     }
    156 
    157     [StorableHook(HookType.AfterDeserialization)]
    158     private void AfterDeserialization()
    159     {
    160         // BackwardsCompatibility3.4
    161 
    162         #region Backwards compatible code, remove with 3.5
    163 
    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         #endregion
    195     }
    196 
    197 
    198190    protected void CalculateResults()
    199191    {
     
    203195        IEnumerable<double> estimatedTestValues = EstimatedTestValues; // cache values
    204196        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
    208211        double testCTR = OnlineTradeRulesCalculator.Calculate(estimatedTestValues, ProblemData, ProblemData.TestIndices);
    209212        TestCash = testCTR;
  • branches/sluengo/HeuristicLab.Problems.TradeRules/Symbols/ConstantIntTreeNode.cs

    r9262 r9499  
    5151            base.ResetLocalParameters(random);
    5252           
    53             Value = random.Next(25)+1;
     53            Value = random.Next(100)+1;
    5454        }
    5555
  • branches/sluengo/HeuristicLab.Problems.TradeRules/Symbols/RSI.cs

    r9262 r9499  
    1111    class RSI: Symbol
    1212    {
    13         private const int minimumArity = 1;
    14         private const int maximumArity = 1;
     13        private const int minimumArity = 3;
     14        private const int maximumArity = 3;
    1515
    1616        public override int MinimumArity
Note: See TracChangeset for help on using the changeset viewer.