[7860] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9456] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[7860] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[8598] | 23 | using System.Collections;
|
---|
[7860] | 24 | using System.Collections.Generic;
|
---|
[8180] | 25 | using System.IO;
|
---|
[8192] | 26 | using System.Linq;
|
---|
[8566] | 27 | using HeuristicLab.Common;
|
---|
[9989] | 28 | using HeuristicLab.Problems.Instances;
|
---|
| 29 | using HeuristicLab.Problems.Instances.DataAnalysis;
|
---|
[8192] | 30 |
|
---|
[9989] | 31 | namespace HeuristicLab.Problems.DataAnalysis.Trading {
|
---|
| 32 | public class CsvProblemInstanceProvider : ProblemInstanceProvider<IProblemData> {
|
---|
[7860] | 33 | public override string Name {
|
---|
[8211] | 34 | get { return "CSV File"; }
|
---|
[7860] | 35 | }
|
---|
| 36 | public override string Description {
|
---|
| 37 | get {
|
---|
[9989] | 38 | return "Comma separated values file importer";
|
---|
[7860] | 39 | }
|
---|
| 40 | }
|
---|
| 41 | public override Uri WebLink {
|
---|
| 42 | get { return new Uri("http://dev.heuristiclab.com/trac/hl/core/wiki/UsersFAQ#DataAnalysisImportFileFormat"); }
|
---|
| 43 | }
|
---|
| 44 | public override string ReferencePublication {
|
---|
| 45 | get { return ""; }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[8192] | 48 | public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
|
---|
| 49 | return new List<IDataDescriptor>();
|
---|
| 50 | }
|
---|
[9989] | 51 | public override IProblemData LoadData(IDataDescriptor descriptor) {
|
---|
[8192] | 52 | throw new NotImplementedException();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public override bool CanImportData {
|
---|
[8180] | 56 | get { return true; }
|
---|
| 57 | }
|
---|
[9989] | 58 | public override IProblemData ImportData(string path) {
|
---|
[8192] | 59 | TableFileParser csvFileParser = new TableFileParser();
|
---|
[9608] | 60 | csvFileParser.Parse(path, csvFileParser.AreColumnNamesInFirstLine(path));
|
---|
[8180] | 61 |
|
---|
[8192] | 62 | Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
|
---|
[9989] | 63 | string targetVar = (from v in dataset.DoubleVariables
|
---|
| 64 | where dataset.GetReadOnlyDoubleValues(v).Min() <= 0
|
---|
| 65 | where dataset.GetReadOnlyDoubleValues(v).Max() >= 0
|
---|
| 66 | select v).LastOrDefault();
|
---|
| 67 | if (targetVar == null) throw new ArgumentException("The target variable must contain changes (deltas) of the asset price over time.");
|
---|
[8192] | 68 |
|
---|
[9989] | 69 | // turn off input variables that are constant in the training partition
|
---|
[8566] | 70 | var allowedInputVars = new List<string>();
|
---|
| 71 | var trainingIndizes = Enumerable.Range(0, (csvFileParser.Rows * 2) / 3);
|
---|
[8877] | 72 | if (trainingIndizes.Count() >= 2) {
|
---|
| 73 | foreach (var variableName in dataset.DoubleVariables) {
|
---|
[9995] | 74 | if (dataset.GetDoubleValues(variableName, trainingIndizes).Range() > 0)
|
---|
[8877] | 75 | allowedInputVars.Add(variableName);
|
---|
| 76 | }
|
---|
| 77 | } else {
|
---|
[9995] | 78 | allowedInputVars.AddRange(dataset.DoubleVariables);
|
---|
[8566] | 79 | }
|
---|
[8192] | 80 |
|
---|
[9989] | 81 | IProblemData problemData = new ProblemData(dataset, allowedInputVars, targetVar);
|
---|
[8192] | 82 |
|
---|
[8566] | 83 | var trainingPartEnd = trainingIndizes.Last();
|
---|
[9989] | 84 | problemData.TrainingPartition.Start = trainingIndizes.First();
|
---|
| 85 | problemData.TrainingPartition.End = trainingPartEnd;
|
---|
| 86 | problemData.TestPartition.Start = trainingPartEnd;
|
---|
| 87 | problemData.TestPartition.End = csvFileParser.Rows;
|
---|
[8192] | 88 |
|
---|
[9989] | 89 | problemData.Name = Path.GetFileName(path);
|
---|
[8566] | 90 |
|
---|
[9989] | 91 | return problemData;
|
---|
[7860] | 92 | }
|
---|
| 93 | }
|
---|
| 94 | }
|
---|