Rev | Line | |
---|
[9499] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Problems.DataAnalysis;
|
---|
| 6 |
|
---|
| 7 | namespace HeuristicLab.Problems.TradeRules.Evaluator
|
---|
| 8 | {
|
---|
| 9 | class OnlineHeuristicTradeRulesCalculator
|
---|
| 10 | {
|
---|
| 11 | private static double numberUpDays;
|
---|
| 12 | private static double numberDownDays;
|
---|
| 13 |
|
---|
| 14 | public static double Calculate(IEnumerable<double> estimatedValues, IRegressionProblemData problemData, IEnumerable<int> rows)
|
---|
| 15 | {
|
---|
| 16 | double value = 0.0;
|
---|
| 17 | int position = 1;
|
---|
| 18 | int countUp = 0;
|
---|
| 19 | int countDown = 0;
|
---|
| 20 | numberUpDays=0.0;
|
---|
| 21 | numberDownDays=0.0;
|
---|
| 22 |
|
---|
| 23 | int [] row = rows.ToArray();
|
---|
| 24 | double [] closePrice= problemData.Dataset.GetDoubleValues("\"Close\"").ToArray();
|
---|
| 25 | double[] estimated = estimatedValues.ToArray();
|
---|
| 26 |
|
---|
| 27 | while (position < row.Length)
|
---|
| 28 | {
|
---|
| 29 | if ((closePrice[row[position]] - closePrice[row[(position - 1)]]) > 0)
|
---|
| 30 | {
|
---|
| 31 | countUp++;
|
---|
| 32 | if (estimated[(position - 1)] == 1)
|
---|
| 33 | {
|
---|
| 34 | numberUpDays++;
|
---|
| 35 | value++;
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 | else if ((closePrice[row[position]] - closePrice[row[(position - 1)]]) <= 0)
|
---|
| 39 | {
|
---|
| 40 | countDown++;
|
---|
| 41 | if (estimated[(position - 1)] == -1)
|
---|
| 42 | {
|
---|
| 43 | numberDownDays++;
|
---|
| 44 | value++;
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | position++;
|
---|
| 48 | }
|
---|
| 49 | numberUpDays = numberUpDays / countUp;
|
---|
| 50 | numberDownDays = numberDownDays / countDown;
|
---|
| 51 | return value/(row.Length-2);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | public static double getNumberUpDays()
|
---|
| 55 | {
|
---|
| 56 | return numberUpDays;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | public static double getNumberDownDays()
|
---|
| 60 | {
|
---|
| 61 | return numberDownDays;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.