Changeset 9989
- Timestamp:
- 09/19/13 10:16:25 (11 years ago)
- Location:
- trunk/sources
- Files:
-
- 7 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Trading/3.4/CsvProblemInstanceProvider.cs
r9987 r9989 26 26 using System.Linq; 27 27 using HeuristicLab.Common; 28 using HeuristicLab.Problems.DataAnalysis; 28 using HeuristicLab.Problems.Instances; 29 using HeuristicLab.Problems.Instances.DataAnalysis; 29 30 30 namespace HeuristicLab.Problems. Instances.DataAnalysis{31 public class RegressionCSVInstanceProvider : RegressionInstanceProvider{31 namespace HeuristicLab.Problems.DataAnalysis.Trading { 32 public class CsvProblemInstanceProvider : ProblemInstanceProvider<IProblemData> { 32 33 public override string Name { 33 34 get { return "CSV File"; } … … 35 36 public override string Description { 36 37 get { 37 return " ";38 return "Comma separated values file importer"; 38 39 } 39 40 } … … 48 49 return new List<IDataDescriptor>(); 49 50 } 50 public override I RegressionProblemData LoadData(IDataDescriptor descriptor) {51 public override IProblemData LoadData(IDataDescriptor descriptor) { 51 52 throw new NotImplementedException(); 52 53 } … … 55 56 get { return true; } 56 57 } 57 public override I RegressionProblemData ImportData(string path) {58 public override IProblemData ImportData(string path) { 58 59 TableFileParser csvFileParser = new TableFileParser(); 59 60 csvFileParser.Parse(path, csvFileParser.AreColumnNamesInFirstLine(path)); 60 61 61 62 Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values); 62 string targetVar = dataset.DoubleVariables.Last(); 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."); 63 68 64 // turn of input variables that are constant in the training partition69 // turn off input variables that are constant in the training partition 65 70 var allowedInputVars = new List<string>(); 66 71 var trainingIndizes = Enumerable.Range(0, (csvFileParser.Rows * 2) / 3); … … 75 80 } 76 81 77 I RegressionProblemData regressionData = new RegressionProblemData(dataset, allowedInputVars, targetVar);82 IProblemData problemData = new ProblemData(dataset, allowedInputVars, targetVar); 78 83 79 84 var trainingPartEnd = trainingIndizes.Last(); 80 regressionData.TrainingPartition.Start = trainingIndizes.First();81 regressionData.TrainingPartition.End = trainingPartEnd;82 regressionData.TestPartition.Start = trainingPartEnd;83 regressionData.TestPartition.End = csvFileParser.Rows;85 problemData.TrainingPartition.Start = trainingIndizes.First(); 86 problemData.TrainingPartition.End = trainingPartEnd; 87 problemData.TestPartition.Start = trainingPartEnd; 88 problemData.TestPartition.End = csvFileParser.Rows; 84 89 85 regressionData.Name = Path.GetFileName(path);90 problemData.Name = Path.GetFileName(path); 86 91 87 return regressionData; 88 } 89 90 protected override IRegressionProblemData ImportData(string path, RegressionImportType type, TableFileParser csvFileParser) { 91 List<IList> values = csvFileParser.Values; 92 if (type.Shuffle) { 93 values = Shuffle(values); 94 } 95 Dataset dataset = new Dataset(csvFileParser.VariableNames, values); 96 97 // turn of input variables that are constant in the training partition 98 var allowedInputVars = new List<string>(); 99 int trainingPartEnd = (csvFileParser.Rows * type.TrainingPercentage) / 100; 100 trainingPartEnd = trainingPartEnd > 0 ? trainingPartEnd : 1; 101 var trainingIndizes = Enumerable.Range(0, trainingPartEnd); 102 if (trainingIndizes.Count() >= 2) { 103 foreach (var variableName in dataset.DoubleVariables) { 104 if (dataset.GetDoubleValues(variableName, trainingIndizes).Range() > 0 && 105 variableName != type.TargetVariable) 106 allowedInputVars.Add(variableName); 107 } 108 } else { 109 allowedInputVars.AddRange(dataset.DoubleVariables.Where(x => !x.Equals(type.TargetVariable))); 110 } 111 112 RegressionProblemData regressionData = new RegressionProblemData(dataset, allowedInputVars, type.TargetVariable); 113 114 regressionData.TrainingPartition.Start = 0; 115 regressionData.TrainingPartition.End = trainingPartEnd; 116 regressionData.TestPartition.Start = trainingPartEnd; 117 regressionData.TestPartition.End = csvFileParser.Rows; 118 119 regressionData.Name = Path.GetFileName(path); 120 121 return regressionData; 92 return problemData; 122 93 } 123 94 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Trading/3.4/EcbProblemInstanceProvider.cs
r9987 r9989 29 29 30 30 namespace HeuristicLab.Problems.DataAnalysis.Trading { 31 32 31 public class EcbProblemInstanceProvider : ProblemInstanceProvider<IProblemData> { 33 32 private class EcbDataDescriptor : IDataDescriptor { -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Trading/3.4/HeuristicLab.Problems.DataAnalysis.Trading-3.4.csproj
r9964 r9989 103 103 <Compile Include="Calculators\OnlineProfitCalculator.cs" /> 104 104 <Compile Include="Calculators\OnlineSharpeRatioCalculator.cs" /> 105 <Compile Include="CsvProblemInstanceProvider.cs" /> 106 <Compile Include="EcbProblemInstanceProvider.cs" /> 105 107 <Compile Include="Interfaces\IModel.cs" /> 106 108 <Compile Include="Interfaces\IProblem.cs" /> … … 109 111 <Compile Include="Plugin.cs" /> 110 112 <Compile Include="ProblemData.cs" /> 111 <Compile Include="ProblemInstanceProvider.cs" />112 113 <Compile Include="Solution.cs" /> 113 114 <Compile Include="Symbolic\Interfaces\IEvaluator.cs" /> … … 205 206 <Name>HeuristicLab.Problems.DataAnalysis-3.4</Name> 206 207 <Private>False</Private> 208 </ProjectReference> 209 <ProjectReference Include="..\..\HeuristicLab.Problems.Instances.DataAnalysis\3.3\HeuristicLab.Problems.Instances.DataAnalysis-3.3.csproj"> 210 <Project>{94C7714E-29D4-4D6D-B213-2C18D627AB75}</Project> 211 <Name>HeuristicLab.Problems.Instances.DataAnalysis-3.3</Name> 207 212 </ProjectReference> 208 213 <ProjectReference Include="..\..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj"> -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Interfaces/IProblemData.cs
r9745 r9989 22 22 namespace HeuristicLab.Problems.DataAnalysis.Trading { 23 23 public interface IProblemData : IDataAnalysisProblemData { 24 string Price Variable { get; }24 string PriceChangeVariable { get; } 25 25 double TransactionCosts { get; } 26 26 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Trading/3.4/ProblemData.cs
r9812 r9989 33 33 [Item("TradingProblemData", "Represents an item containing all data defining a trading problem.")] 34 34 public sealed class ProblemData : DataAnalysisProblemData, IProblemData { 35 private const string Price VariableParameterName = "PriceVariable";35 private const string PriceChangeVariableParameterName = "PriceChangeVariable"; 36 36 private const string TransactionCostsParameterName = "TransactionCosts"; 37 37 … … 1589 1589 1590 1590 static ProblemData() { 1591 defaultDataset = new Dataset(new string[] { " AUD" }, audInUsdDiff);1591 defaultDataset = new Dataset(new string[] { "d(AUD/USD)/dt" }, audInUsdDiff); 1592 1592 defaultDataset.Name = "AUD in USD"; 1593 defaultDataset.Description = " Price ofAustralian dollar in US dollar.";1594 defaultAllowedInputVariables = new List<string>() { " AUD" };1595 defaultPriceVariable = " AUD";1593 defaultDataset.Description = "Australian dollar in US dollar."; 1594 defaultAllowedInputVariables = new List<string>() { "d(AUD/USD)/dt" }; 1595 defaultPriceVariable = "d(AUD/USD)/dt"; 1596 1596 } 1597 1597 #endregion 1598 1598 1599 public IConstrainedValueParameter<StringValue> Price VariableParameter {1600 get { return (IConstrainedValueParameter<StringValue>)Parameters[Price VariableParameterName]; }1599 public IConstrainedValueParameter<StringValue> PriceChangeVariableParameter { 1600 get { return (IConstrainedValueParameter<StringValue>)Parameters[PriceChangeVariableParameterName]; } 1601 1601 } 1602 1602 public IValueParameter<DoubleValue> TransactionCostsParameter { 1603 1603 get { return (IValueParameter<DoubleValue>)Parameters[TransactionCostsParameterName]; } 1604 1604 } 1605 public string Price Variable {1606 get { return Price VariableParameter.Value.Value; }1605 public string PriceChangeVariable { 1606 get { return PriceChangeVariableParameter.Value.Value; } 1607 1607 } 1608 1608 public double TransactionCosts { … … 1630 1630 : base(dataset, allowedInputVariables) { 1631 1631 var variables = InputVariables.Select(x => x.AsReadOnly()).ToList(); 1632 Parameters.Add(new ConstrainedValueParameter<StringValue>(Price VariableParameterName, new ItemSet<StringValue>(variables), variables.First(x => x.Value == targetVariable)));1632 Parameters.Add(new ConstrainedValueParameter<StringValue>(PriceChangeVariableParameterName, new ItemSet<StringValue>(variables), variables.First(x => x.Value == targetVariable))); 1633 1633 Parameters.Add(new FixedValueParameter<DoubleValue>(TransactionCostsParameterName, "The absolute cost of on buy/sell transaction (assumed to be constant and independent of transaction volume)", new DoubleValue(0.0002))); 1634 1635 if (dataset.GetReadOnlyDoubleValues(targetVariable).Min() >= 0) throw new ArgumentException("The target variable must contain changes (deltas) of the asset price over time."); 1636 1634 1637 RegisterParameterEvents(); 1635 1638 } 1636 1639 1637 1640 private void RegisterParameterEvents() { 1638 Price VariableParameter.ValueChanged += new EventHandler(PriceVariableParameter_ValueChanged);1641 PriceChangeVariableParameter.ValueChanged += new EventHandler(PriceVariableParameter_ValueChanged); 1639 1642 TransactionCostsParameter.Value.ValueChanged += new EventHandler(TransactionCostsParameter_ValueChanged); 1640 1643 } … … 1644 1647 } 1645 1648 private void PriceVariableParameter_ValueChanged(object sender, EventArgs e) { 1649 if (Dataset.GetReadOnlyDoubleValues(PriceChangeVariable).Min() >= 0) throw new ArgumentException("The target variable must contain changes (deltas) of the asset price over time."); 1646 1650 OnChanged(); 1647 1651 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Solution.cs
r9928 r9989 86 86 protected void CalculateTradingResults() { 87 87 double[] trainingSignals = TrainingSignals.ToArray(); // cache values 88 IEnumerable<double> trainingReturns = ProblemData.Dataset.GetDoubleValues(ProblemData.Price Variable, ProblemData.TrainingIndices);88 IEnumerable<double> trainingReturns = ProblemData.Dataset.GetDoubleValues(ProblemData.PriceChangeVariable, ProblemData.TrainingIndices); 89 89 double[] testSignals = TestSignals.ToArray(); // cache values 90 IEnumerable<double> testReturns = ProblemData.Dataset.GetDoubleValues(ProblemData.Price Variable, ProblemData.TestIndices);90 IEnumerable<double> testReturns = ProblemData.Dataset.GetDoubleValues(ProblemData.PriceChangeVariable, ProblemData.TestIndices); 91 91 92 92 OnlineCalculatorError errorState; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Symbolic/SingleObjective/ProfitEvaluator.cs
r9825 r9989 59 59 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, IProblemData problemData, IEnumerable<int> rows) { 60 60 IEnumerable<double> signals = GetSignals(interpreter, solution, problemData.Dataset, rows); 61 IEnumerable<double> returns = problemData.Dataset.GetDoubleValues(problemData.Price Variable, rows);61 IEnumerable<double> returns = problemData.Dataset.GetDoubleValues(problemData.PriceChangeVariable, rows); 62 62 OnlineCalculatorError errorState; 63 63 double profit = OnlineProfitCalculator.Calculate(returns, signals, problemData.TransactionCosts, out errorState); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Symbolic/SingleObjective/SharpeRatioEvaluator.cs
r9825 r9989 59 59 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, IProblemData problemData, IEnumerable<int> rows) { 60 60 IEnumerable<double> signals = GetSignals(interpreter, solution, problemData.Dataset, rows); 61 IEnumerable<double> returns = problemData.Dataset.GetDoubleValues(problemData.Price Variable, rows);61 IEnumerable<double> returns = problemData.Dataset.GetDoubleValues(problemData.PriceChangeVariable, rows); 62 62 OnlineCalculatorError errorState; 63 63 double sharpRatio = OnlineSharpeRatioCalculator.Calculate(returns, signals, problemData.TransactionCosts, out errorState); -
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/CSV/RegressionCSVInstanceProvider.cs
r9608 r9989 62 62 string targetVar = dataset.DoubleVariables.Last(); 63 63 64 // turn of input variables that are constant in the training partition64 // turn off input variables that are constant in the training partition 65 65 var allowedInputVars = new List<string>(); 66 66 var trainingIndizes = Enumerable.Range(0, (csvFileParser.Rows * 2) / 3);
Note: See TracChangeset
for help on using the changeset viewer.