Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/19/13 11:47:34 (11 years ago)
Author:
sluengo
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.