Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9386


Ignore:
Timestamp:
04/20/13 14:08:49 (11 years ago)
Author:
sluengo
Message:
 
Location:
branches/sluengo/HeuristicLab.Problems.TradeRules
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/sluengo/HeuristicLab.Problems.TradeRules/Evaluator/EvaluatorTradeRules.cs

    r9325 r9386  
    4444            double quality = Calculate((ITradeRulesExpresionTree) SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
    4545            QualityParameter.ActualValue = new DoubleValue(quality);
    46             ITradeRulesExpresionTree interpreter = (ITradeRulesExpresionTree)SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
    47             interpreter.clearVariables();
    4846            return base.Apply();
    4947        }
     
    5250        {
    5351            interpreter.setInitialTraining(initialTraining);
    54             interpreter.setInitialTest(initialTest);
     52            interpreter.setInitialTest(rows.ToArray()[0]);
    5553            IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
     54            interpreter.clearVariables();
     55            double tradingCash = OnlineTradeRulesCalculator.Calculate(estimatedValues, problemData, rows);
    5656           
    57             double tradingCash = OnlineTradeRulesCalculator.Calculate(estimatedValues, problemData, problemData.TrainingIndices);
    58 
    5957            return tradingCash;
    6058        }
     
    6967            EstimationLimitsParameter.ExecutionContext = null;
    7068         
    71 
    7269            return r2;
    7370        }
  • branches/sluengo/HeuristicLab.Problems.TradeRules/Evaluator/OnlineTradeRulesCalculator.cs

    r9262 r9386  
    44using System.Text;
    55using HeuristicLab.Problems.DataAnalysis;
     6using HeuristicLab.Core;
     7using HeuristicLab.Data;
     8using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    69
    710namespace HeuristicLab.Problems.TradeRules
     
    912    class OnlineTradeRulesCalculator
    1013    {
     14        private static int numberTrades;
     15        private static int tradeDays;
     16        private static int totalTradeDays;
     17
    1118        public static double Calculate(IEnumerable<double> estimatedValues, IRegressionProblemData problemData, IEnumerable<int> rows)
    12         {/*
    13             const double commission = 0.25;
    14             const double EAR = 4.00;  //Effective Anual Rate
     19        {
     20            double[] arrayOpen = problemData.Dataset.GetDoubleValues("\"Open\"").ToArray(); //Array with all Open prices
     21            int[] tick = rows.ToArray();
     22            double[] arrayIO = estimatedValues.ToArray();
     23            double[] arrayDate = problemData.Dataset.GetDoubleValues("\"Date\"").ToArray(); //Array with all dates
     24           
     25            const double COMISSION = 0.25;
     26            const double EAR = 5.00;  //Effective Anual Rate
     27            const double CASHINI = 10000.00;
     28            int tickIni = tick[0];
     29            int tickEnd = tick[tick.Length-1];
     30            const double DAYSYEAR = 365.00;
    1531
    16             double DayRat = 0; //One day interest
     32            double DayRat = 0.0; //One day interest
    1733            double interest = 0.0; // Interest for one day
    18             double[] arrayDate = problemData.Dataset.GetDoubleValues("\"Date\"").ToArray(); //Array with all dates in UNIX format
     34            int nDias1 = 0;
     35            int nDias2 = 0;
     36            int dayBefore=0;
     37            int yesterday=0;
    1938
    20             //int count = rows.ToList()[0];
    21  
     39            int actualRow = 0;
     40            int nData = tick.Length;
     41
    2242            bool intoMarket = false;//Equivalent to be into the market
    23             int totalTradeDays = 0;
    24             int numberTrades = 0;
    25             int tradeDays = 0;
    26             double dayBefore = 0.0;
    27             double yesterday = 0.0;
     43            numberTrades = 0;
     44            tradeDays = 0;
     45            totalTradeDays = 0;
    2846            double buyPrice = 0.0;
    2947            double sellPrice = 0.0;
    30             string stringPrice = "";
    3148            int nShares = 0;
    32             double cash = 10000.00;
     49
     50            double cash = CASHINI;
    3351            double expend = 0.0;
    34             double equity = 0.0;
    35             double profit1 = 0.0;
     52            double profitTrade = 0.0;
    3653            double charged = 0.0;
    3754
    38             IEnumerator<int> initialRow = rows.GetEnumerator();
    39             initialRow.MoveNext();
    40             int numDays1 = (int)arrayDate[initialRow.Current-1];
    41             int numDays2 = (int) arrayDate[(initialRow.Current)];
    42             int count = initialRow.Current + 1;
    43            
    44             IEnumerator<double> enumerator = estimatedValues.GetEnumerator();
    45             enumerator.MoveNext();
    46             dayBefore = enumerator.Current;
    47             enumerator.MoveNext();
    48             yesterday = enumerator.Current;
     55            double [] equity = new double [nData];
     56            DayRat = DAYSYEAR * (Math.Pow((1.0 + (EAR/100)), (1.0/ DAYSYEAR)) - 1.0);
    4957
    50             DayRat = 360 * (Math.Pow((1 + (EAR / 100)), (1 / 360)) - 1);
     58            //First Day
     59            equity[0] = CASHINI;
     60            actualRow++;
     61            nDias2 = Convert.ToInt32(arrayDate[tick[1]] - arrayDate[tick[0]]);
     62            //Second day in the marquet. -----------------------------------------
     63            cash = CASHINI * Math.Pow((1.0 + DayRat / DAYSYEAR), nDias2);
     64            equity[1] = cash;
     65            nDias2 = Convert.ToInt32(arrayDate[tick[2]] - arrayDate[tick[1]]);
     66            interest = cash * Math.Pow((1.0 + DayRat / DAYSYEAR), nDias2) - cash;
     67            dayBefore = Convert.ToInt32(arrayIO[0]);
     68            yesterday = Convert.ToInt32(arrayIO[1]);
     69            //Earnings computation -----------------------------------------------
     70            actualRow = 2;
    5171
    52             while (enumerator.MoveNext())
     72            while (actualRow<(nData-1))
    5373            {
    5474                if (!intoMarket)
     
    5777                    {
    5878                        intoMarket = true;
    59                         stringPrice = problemData.Dataset.GetValue(count, 0); //Extracting Open values
    60                         buyPrice = Convert.ToDouble(stringPrice);
    61                         totalTradeDays++; numberTrades++; tradeDays++; //Increasing trading variables
    62                         nShares = (int)Math.Floor(cash / (buyPrice * (1.0 + commission / 100)));
    63                         expend = buyPrice * nShares * (1 + commission / 100);
    64                         cash = cash - expend + interest;
    65                         equity = cash + nShares * buyPrice * (1 - commission / 100);
    66                         interest = cash * Math.Pow((1 + DayRat / 360), numDays2) - cash;
     79                        buyPrice = arrayOpen[tick[actualRow]];
     80                        totalTradeDays++; numberTrades++; tradeDays=1; //Increasing trading variables
     81                        nShares = Convert.ToInt32(Math.Floor(cash / (buyPrice * (1.0 + COMISSION / 100))));
     82                        expend = buyPrice * nShares * (1.0 + COMISSION / 100);
     83                        cash = cash + interest - expend;
     84                        equity[actualRow] = cash + nShares * (buyPrice * (1.0 - COMISSION / 100));
    6785                    }
    6886                    else  //Dia normal fuera del mercado
    6987                    {
    7088                        cash = cash + interest;
    71                         equity = equity + cash;
    72                         interest = cash * Math.Pow((1 + DayRat / 360), numDays2) - cash;
    73                     }
    74 
    75                 }
    76                 else if (dayBefore == 1 && yesterday == -1)
    77                 {
    78                     intoMarket = false;
    79                     stringPrice = problemData.Dataset.GetValue(count, 0); //Extracting Open values
    80                     sellPrice = Convert.ToDouble(stringPrice);
    81                     profit1 += sellPrice - buyPrice;
    82                     charged = sellPrice * nShares * (1 - commission / 100);
    83                     cash = cash + charged + interest;
    84                     equity = cash;
    85                     interest = cash * Math.Pow((1 + DayRat / 360), numDays2) - cash;
    86                     nShares = 0;
    87                 }
    88                 else
    89                 {
    90                     cash = cash + interest;
    91                     tradeDays += numDays1;
    92                     totalTradeDays += numDays1;
    93                     equity = cash + nShares * Convert.ToDouble(problemData.Dataset.GetValue(count, 0)) * (1 - commission / 100);
    94                     interest = cash * Math.Pow((1 + DayRat / 360), numDays2) - cash;
    95                 }
    96 
    97                 dayBefore = yesterday;
    98                 yesterday = enumerator.Current;
    99                 numDays1 = numDays2;
    100                 numDays2 = (int) arrayDate[count];
    101                 count++;
    102             }
    103             if (intoMarket)
    104             {
    105                 intoMarket = false;
    106                 stringPrice = problemData.Dataset.GetValue(count, 0); //Extracting Open values
    107                 sellPrice = Convert.ToDouble(stringPrice);
    108                 profit1 += sellPrice - buyPrice;
    109                 charged = sellPrice * nShares * (1 - commission / 100);
    110                 cash = cash + charged + interest;
    111                 equity = cash;
    112                 nShares = 0;
    113             }
    114             return numDays1;*/
    115 
    116             const double commission = 0.25;
    117             const double EAR = 4.00;  //Effective Anual Rate
    118 
    119             double DayRat = 0; //One day interest
    120             double interest = 0.0; // Interest for one day
    121             double[] arrayDate = problemData.Dataset.GetDoubleValues("\"Date\"").ToArray(); //Array with all dates in UNIX format
    122             int nDias1 = 0;
    123             int nDias2 = 0;
    124 
    125 
    126             bool intoMarket = false;//Equivalent to be into the market
    127             int totalTradeDays = 0;
    128             int numberTrades = 0;
    129             int tradeDays = 0;
    130             double buyPrice = 0.0;
    131             double sellPrice = 0.0;
    132             string stringPrice = "";
    133             int nShares = 0;
    134             double cash = 10000.00;
    135             double expend = 0.0;
    136             double equity = 0.0;
    137             double profit1 = 0.0;
    138             double charged = 0.0;
    139 
    140             //SECOND EVALUATOR
    141             var enumerator = estimatedValues.GetEnumerator();
    142             int count = rows.ToList()[2];
    143             int count2 = 2;
    144             int date1 = (int)arrayDate[rows.ToList()[0]];
    145             int date2 = (int)arrayDate[rows.ToList()[1]];
    146 
    147             enumerator.MoveNext();
    148             double dayBefore = enumerator.Current;
    149             enumerator.MoveNext();
    150             double yesterday = enumerator.Current;
    151            
    152             DayRat = 268 * (Math.Pow((1 + (EAR / 100)),(1 / 268)) - 1);
    153             nDias2 = date2 - date1;
    154            
    155             while (enumerator.MoveNext())
    156             {
    157                 if (!intoMarket)
    158                 {
    159                     if (dayBefore == -1 && yesterday == 1)
    160                     {
    161                         intoMarket = true;
    162                         stringPrice = problemData.Dataset.GetValue(count, 1); //Extracting Open values
    163                         buyPrice = Convert.ToDouble(stringPrice);
    164                         totalTradeDays++; numberTrades++; tradeDays++; //Increasing trading variables
    165                         nShares = (int)Math.Floor(cash / (buyPrice * (1.0 + commission / 100)));
    166                         expend = buyPrice * nShares * (1 + commission / 100);
    167                         cash = cash - expend + interest;
    168                         equity = cash + nShares * buyPrice * (1 - commission / 100);
    169                         interest = cash * Math.Pow((1 + DayRat / 268), nDias2) - cash;
    170                     }
    171                     else  //Dia normal fuera del mercado
    172                     {
    173                         tradeDays++;
    174                         totalTradeDays++;
    175                         cash = cash + interest;
    176                         equity = equity+cash;
    177                         interest = cash * Math.Pow((1 + DayRat / 268), nDias2) - cash;
     89                        equity[actualRow] = cash;
    17890                    }
    17991                }
     
    18193                {
    18294                    intoMarket = false;
    183                     stringPrice = problemData.Dataset.GetValue(count, 1); //Extracting Open values
    184                     sellPrice = Convert.ToDouble(stringPrice);
    185                     profit1 += sellPrice - buyPrice;
    186                     charged = sellPrice * nShares * (1 - commission / 100);
    187                     cash = cash + charged+interest;
    188                     equity = cash;
    189                     interest = cash + Math.Pow((1 + DayRat / 268), nDias2) - cash;
     95                    sellPrice = Convert.ToDouble(arrayOpen[tick[actualRow]]);
     96                    profitTrade = profitTrade + sellPrice - buyPrice;
     97                    charged = nShares * sellPrice * (1.0 - COMISSION / 100);
     98                    cash = cash + interest + charged;
     99                    equity[actualRow] = cash;
    190100                    nShares = 0;
     101                    totalTradeDays = totalTradeDays + nDias1 - 1;
     102                    tradeDays = tradeDays + nDias1 - 1;
     103                    tradeDays = 0;
    191104                }
    192105                else
    193106                {
     107                    totalTradeDays = totalTradeDays + nDias1;
     108                    tradeDays = tradeDays + nDias1;
    194109                    cash = cash + interest;
    195                     tradeDays++;
    196                     totalTradeDays++;
    197                     equity = cash + nShares * Convert.ToDouble(problemData.Dataset.GetValue(count,1)) * (1 - commission / 100);
    198                     interest = cash * Math.Pow((1 + DayRat / 268), nDias2) - cash;
     110                    equity[actualRow] = cash + nShares * arrayOpen[tick[actualRow]] * (1.0 - COMISSION / 100);
     111                   
    199112                }
    200113
    201                 dayBefore = yesterday;
    202                 yesterday = enumerator.Current;
    203                 date1 = date2;
    204                 date2 = (int)arrayDate[rows.ToList()[count2]];
    205                
    206                 int nDiasAux = nDias1;
     114                nDias2 = Convert.ToInt32(arrayDate[tick[(actualRow + 1)]] - arrayDate[tick[actualRow]]);
     115                interest = cash * Math.Pow((1.0 + DayRat / DAYSYEAR), nDias2) - cash;
     116                actualRow++;
    207117                nDias1 = nDias2;
    208                 nDias2 = date2-date1;
    209 
    210                 count++;
    211                 count2++;
     118                dayBefore = Convert.ToInt32(arrayIO[(actualRow - 2)]);
     119                yesterday = Convert.ToInt32(arrayIO[(actualRow - 1)]);
     120               
    212121            }
    213 
    214122            if (intoMarket)
    215123            {
    216124                intoMarket = false;
    217                 stringPrice = problemData.Dataset.GetValue((count-1), 1); //Extracting Open values
    218                 sellPrice = Convert.ToDouble(stringPrice);
    219                 profit1 += sellPrice - buyPrice;
    220                 charged = sellPrice * nShares * (1 - commission / 100);
    221                 cash = cash + charged + interest;
    222                 equity = cash;
     125                sellPrice = Convert.ToDouble(arrayOpen[tick[actualRow]]);
     126                profitTrade = profitTrade + sellPrice - buyPrice;
     127                charged = nShares * sellPrice * (1.0 - COMISSION / 100);
     128                cash = cash + interest + charged;
     129                equity[actualRow] = cash;
    223130                nShares = 0;
     131                totalTradeDays = totalTradeDays + nDias1 - 1;
     132                tradeDays = tradeDays + nDias1 - 1;
    224133            }
     134            else
     135            {
     136                cash = cash + interest;
     137                equity[actualRow] = cash;
     138            }
     139           
    225140            return cash;
     141        }
     142
     143        public static int getNumberTrades()
     144        {
     145            return numberTrades;
     146        }
     147        public static int getTradeDays()
     148        {
     149            return tradeDays;
     150        }
     151        public static int getTotalTradesDays()
     152        {
     153            return totalTradeDays;
    226154        }
    227155    }
  • branches/sluengo/HeuristicLab.Problems.TradeRules/HeuristicLab.Problems.TradeRules-1.0.csproj

    r9325 r9386  
    5656    <Compile Include="Symbols\Lag.cs" />
    5757    <Compile Include="Symbols\MACD.cs" />
    58     <Compile Include="Symbols\MACDTreeNode.cs" />
    5958    <Compile Include="Symbols\Max.cs" />
    6059    <Compile Include="Symbols\Min.cs" />
     
    6261    <Compile Include="Plugin.cs" />
    6362    <Compile Include="Properties\HeuristicLab.Problems.TradeRules-1.0.cs" />
    64     <Compile Include="Symbols\RSI.cs" />
    6563    <Compile Include="Evaluator\TradeRulesAnalysisEvaluator.cs" />
    6664    <Compile Include="Evaluator\TradeRulesAnalysisSingleObjectiveEvaluator.cs" />
     
    6967    <Compile Include="Problem\TradeRulesAbstractProblem.cs" />
    7068    <Compile Include="Problem\TradeRulesProblem.cs" />
     69    <Compile Include="Symbols\RSI.cs" />
    7170    <Compile Include="TradeRulesSingleObjectiveTrainingBestSolutionAnalyzer.cs" />
    7271    <Compile Include="TradeRulesSingleObjectiveValidationBestSolutionAnalyzer.cs" />
  • branches/sluengo/HeuristicLab.Problems.TradeRules/Interpreter.cs

    r9325 r9386  
    1212using HeuristicLab.Problems.DataAnalysis;
    1313using System.Threading;
    14 using HeuristicLab.Problems.TradeRules.Symbols;
    1514
    1615namespace HeuristicLab.Problems.TradeRules
     
    268267                        double result2 = Evaluate(dataset, ref row, state);
    269268                        double total = result + result2;
    270                         return total < 2 ? -1.0 : 1.0;
     269                        return total < 2.0 ? -1.0 : 1.0;
    271270                    }
    272271                case OpCodes.OR:
     
    275274                        double result2 = Evaluate(dataset, ref row, state);
    276275                        double total = result + result2;
    277                         return total > -2 ? 1.0 : -1.0;
     276                        return total > -2.0 ? 1.0 : -1.0;
    278277                    }
    279278                case OpCodes.NOT:
    280279                    {
    281                         return Evaluate(dataset, ref row, state) > 0.0 ? -1.0 : 1.0;
     280                        return Evaluate(dataset, ref row, state) > -1.0 ? -1.0 : 1.0;
    282281                    }
    283282
     
    373372                        double signalValue = -100000;
    374373                        double macd = 0;
    375                         double longitud = 0;
    376374
    377375                        //Check if this MACD has previous values and retrieve them
     
    381379
    382380               
    383                             //Calculating the factor for each EMA
    384                             double factor = 2.0 / (firstEMA + 1.0);
    385                             double factor2 = 2.0 / (secondEMA + 1.0);
    386                             double factor3 = 2.0 / (signal + 1.0);
     381                        //Calculating the factor for each EMA
     382                        double factor = 2.0 / (firstEMA + 1.0);
     383                        double factor2 = 2.0 / (secondEMA + 1.0);
     384                        double factor3 = 2.0 / (signal + 1.0);
    387385
    388386                            //Calculate the first value in the training for the two EMAs and the signal.
    389                             if (row <= initialTraining || row == initialTest)
     387                            if (row == initialTest)
    390388                            {
    391389                                double [] meanValues = dataset.GetDoubleValues("\"Close\"", Enumerable.Range(0, row+1)).ToArray();
     
    424422                            secondEMACache[currentInstr.dynamicNode] = secondElementEMA;
    425423                            signalCache[currentInstr.dynamicNode] = signalValue;
    426 
     424                           
    427425                        return macd > signalValue ? 1.0 : -1.0;
    428426                    }
     
    447445                            double factor = 1.0 / numberOfDays;
    448446
    449                             if (row == initialTraining || row == initialTest)
     447                            if (row == initialTest)
    450448                            {
    451449                                double[] closeValues = dataset.GetDoubleValues("\"Close\"", Enumerable.Range(0, (row + 1))).ToArray();
     
    573571        public void clearVariables()
    574572        {
    575             signalCache.Clear();
    576             firstEMACache.Clear();
    577             secondEMACache.Clear();
    578             RSIPositiveCache.Clear();
    579             RSINegativeCache.Clear();
    580             RSICache.Clear();
    581             RSIOutputCache.Clear();
     573            if (signalCache != null) signalCache.Clear();
     574            if (firstEMACache != null) firstEMACache.Clear();
     575            if (secondEMACache != null) secondEMACache.Clear();
     576            if (RSIPositiveCache != null) RSIPositiveCache.Clear();
     577            if (RSINegativeCache != null) RSINegativeCache.Clear();
     578            if (RSICache != null) RSICache.Clear();
     579            if (RSIOutputCache != null) RSIOutputCache.Clear();
    582580        }
    583581
     
    617615                int row = rowEnum;
    618616                state.Reset();
    619                 if (row < initialTraining) yield return -1;
     617                if (row < initialTest) yield return -1;
    620618                else yield return Evaluate(dataset, ref row, state);
    621619            }
  • branches/sluengo/HeuristicLab.Problems.TradeRules/Solution/TradeRulesSolutionBase.cs

    r9262 r9386  
    2929        private const string TrainingMeanErrorResultName = "Mean error (training)";
    3030        private const string TestMeanErrorResultName = "Mean error (test)";
     31        private const string TestTradeDaysResultName = "Trade days";
     32        private const string TestNumberTradesResultName = "Number of trades";
     33        private const string TestTotalTradesResultName = "Total trades";
     34
    3135
    3236        public new IRegressionModel Model
     
    5862            get { return ((DoubleValue)this[TestCashResultName].Value).Value; }
    5963            private set { ((DoubleValue)this[TestCashResultName].Value).Value = value; }
     64        }
     65        public double TradeDays
     66        {
     67            get { return ((DoubleValue)this[TestTradeDaysResultName].Value).Value; }
     68            private set { ((DoubleValue)this[TestTradeDaysResultName].Value).Value = value; }
     69        }
     70        public double NumberTrades
     71        {
     72            get { return ((DoubleValue)this[TestNumberTradesResultName].Value).Value; }
     73            private set { ((DoubleValue)this[TestNumberTradesResultName].Value).Value = value; }
     74        }
     75        public double TotalTrades
     76        {
     77            get { return ((DoubleValue)this[TestTotalTradesResultName].Value).Value; }
     78            private set { ((DoubleValue)this[TestTotalTradesResultName].Value).Value = value; }
    6079        }
    6180        public double TrainingMeanSquaredError
     
    129148    protected TradeRulesSolutionBase(IRegressionModel model, IRegressionProblemData problemData)
    130149      : base(model, problemData) {
    131           Add(new Result(TrainingCashResultName, "Cash obtained after training period in the stock market", new DoubleValue()));
     150      Add(new Result(TrainingCashResultName, "Cash obtained after training period in the stock market", new DoubleValue()));
    132151      Add(new Result(TestCashResultName, "Cash obtained after test period in the stock market", new DoubleValue()));
    133       Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleValue()));
    134       Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleValue()));
    135       Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleValue()));
    136       Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleValue()));
    137       Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue()));
    138       Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue()));
    139       Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new PercentValue()));
    140       Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new PercentValue()));
    141       Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleValue()));
    142       Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleValue()));
    143       Add(new Result(TrainingMeanErrorResultName, "Mean of errors of the model on the training partition", new DoubleValue()));
    144       Add(new Result(TestMeanErrorResultName, "Mean of errors of the model on the test partition", new DoubleValue()));
    145     }
     152      Add(new Result(TestTradeDaysResultName, "Number of trading days", new DoubleValue()));
     153      Add(new Result(TestNumberTradesResultName, "Number of trades", new DoubleValue()));
     154      Add(new Result(TestTotalTradesResultName, "Total trades", new DoubleValue()));
     155     }
    146156
    147157    [StorableHook(HookType.AfterDeserialization)]
     
    194204        IEnumerable<double> originalTestValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices);
    195205
    196         OnlineCalculatorError errorState;
    197         double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    198         TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMSE : double.NaN;
    199         double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    200         TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN;
    201 
    202         double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    203         TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN;
    204         double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    205         TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN;
    206 
    207         double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    208         TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN;
    209         double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    210         TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN;
    211 
    212         double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    213         TrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN;
    214         double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    215         TestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN;
    216 
    217         double trainingNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    218         TrainingNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingNMSE : double.NaN;
    219         double testNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    220         TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNMSE : double.NaN;
    221 
    222         double trainingME = OnlineMeanErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    223         TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN;
    224         double testME = OnlineMeanErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    225         TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN;
    226 
    227206        double trainingCTR = OnlineTradeRulesCalculator.Calculate(estimatedTrainingValues, ProblemData, ProblemData.TrainingIndices);
    228207        TrainingCash = trainingCTR;
    229208        double testCTR = OnlineTradeRulesCalculator.Calculate(estimatedTestValues, ProblemData, ProblemData.TestIndices);
    230209        TestCash = testCTR;
     210        double testTradeDays = OnlineTradeRulesCalculator.getTradeDays();
     211        TradeDays = testTradeDays;
     212        double testNumberTrades = OnlineTradeRulesCalculator.getNumberTrades();
     213        NumberTrades = testNumberTrades;
     214        double testTotalTradeDays = OnlineTradeRulesCalculator.getTotalTradesDays();
     215        TotalTrades = testTotalTradeDays;
     216
    231217    }
    232218
  • branches/sluengo/HeuristicLab.Problems.TradeRules/Symbols/MACD.cs

    r9262 r9386  
    77using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    88using HeuristicLab.Common;
    9 using HeuristicLab.Problems.TradeRules.Symbols;
    109
    1110namespace HeuristicLab.Problems.TradeRules
     
    3837        }
    3938
    40         public override ISymbolicExpressionTreeNode CreateTreeNode()
    41         {
    42             return new MACDTreeNode(this);
    43         }
    44 
    4539        public override IDeepCloneable Clone(Cloner cloner)
    4640        {
Note: See TracChangeset for help on using the changeset viewer.