using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Problems.DataAnalysis; namespace HeuristicLab.Problems.TradeRules.Evaluator { class OnlineHeuristicTradeRulesCalculator { private static double numberUpDays; private static double numberDownDays; public static double Calculate(IEnumerable estimatedValues, IRegressionProblemData problemData, IEnumerable rows) { double value = 0.0; int position = 1; int countUp = 0; int countDown = 0; numberUpDays=0.0; numberDownDays=0.0; int [] row = rows.ToArray(); double [] closePrice= problemData.Dataset.GetDoubleValues("\"Close\"").ToArray(); double[] estimated = estimatedValues.ToArray(); while (position < row.Length) { if ((closePrice[row[position]] - closePrice[row[(position - 1)]]) > 0) { countUp++; if (estimated[(position - 1)] == 1) { numberUpDays++; value++; } } else if ((closePrice[row[position]] - closePrice[row[(position - 1)]]) <= 0) { countDown++; if (estimated[(position - 1)] == -1) { numberDownDays++; value++; } } position++; } numberUpDays = numberUpDays / countUp; numberDownDays = numberDownDays / countDown; return value/(row.Length-2); } public static double getNumberUpDays() { return numberUpDays; } public static double getNumberDownDays() { return numberDownDays; } } }