Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9176


Ignore:
Timestamp:
01/22/13 13:39:17 (12 years ago)
Author:
gkronber
Message:

#1508 updated trading plugin to work with current trunk version

Location:
branches/HeuristicLab.Problems.DataAnalysis.Trading
Files:
2 added
3 deleted
13 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Calculators/OnlineSharpeRatioCalculator.cs

    r6861 r9176  
    8383          iterationReturn = -actualReturn;
    8484        } else if (p == -1 && signal.IsAlmost(0)) {
    85           iterationReturn = -(actualReturn - transactionCost);
     85          iterationReturn = -actualReturn - transactionCost;
    8686          p = 0;
    8787        } else if (p == -1 && signal.IsAlmost(1)) {
    88           iterationReturn = -(actualReturn - transactionCost);
     88          iterationReturn = -actualReturn - transactionCost;
    8989          p = 1;
    9090        }
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/HeuristicLab.Problems.DataAnalysis.Trading-3.4.csproj

    r6136 r9176  
    4141    <DebugType>full</DebugType>
    4242    <Optimize>false</Optimize>
    43     <OutputPath>bin\Debug\</OutputPath>
     43    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    4444    <DefineConstants>DEBUG;TRACE</DefineConstants>
    4545    <ErrorReport>prompt</ErrorReport>
     
    5858  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    5959    <DebugSymbols>true</DebugSymbols>
    60     <OutputPath>bin\x64\Debug\</OutputPath>
     60    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    6161    <DefineConstants>DEBUG;TRACE</DefineConstants>
    6262    <DebugType>full</DebugType>
     
    7676  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    7777    <DebugSymbols>true</DebugSymbols>
    78     <OutputPath>bin\x86\Debug\</OutputPath>
     78    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    7979    <DefineConstants>DEBUG;TRACE</DefineConstants>
    8080    <DebugType>full</DebugType>
     
    9393  </PropertyGroup>
    9494  <ItemGroup>
    95     <Reference Include="ALGLIB-3.1.0">
    96       <HintPath>c:\Program Files\HeuristicLab 3.3\ALGLIB-3.1.0.dll</HintPath>
     95    <Reference Include="ALGLIB-3.6.0, Version=3.6.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     96      <SpecificVersion>False</SpecificVersion>
     97      <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.6.0.dll</HintPath>
    9798    </Reference>
    9899    <Reference Include="HeuristicLab.Analysis-3.3">
     
    161162    <Reference Include="HeuristicLab.Problems.DataAnalysis.Views-3.4">
    162163      <HintPath>c:\Program Files\HeuristicLab 3.3\HeuristicLab.Problems.DataAnalysis.Views-3.4.dll</HintPath>
     164    </Reference>
     165    <Reference Include="HeuristicLab.Problems.Instances-3.3">
     166      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Problems.Instances-3.3.dll</HintPath>
     167    </Reference>
     168    <Reference Include="HeuristicLab.Problems.Instances.DataAnalysis-3.3">
     169      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances.DataAnalysis-3.3.dll</HintPath>
    163170    </Reference>
    164171    <Reference Include="HeuristicLab.Random-3.3">
     
    185192  </ItemGroup>
    186193  <ItemGroup>
     194    <Compile Include="Calculators\OnlineProfitCalculator.cs" />
    187195    <Compile Include="HeuristicLabProblemsDataAnalysisTradingPlugin.cs" />
    188196    <Compile Include="Interfaces\ITradingEnsembleModel.cs" />
     
    192200    <Compile Include="Interfaces\ITradingSolution.cs" />
    193201    <Compile Include="Calculators\OnlineSharpeRatioCalculator.cs" />
     202    <Compile Include="CSVInstanceProvider.cs" />
    194203    <Compile Include="Symbolic\Interfaces\ISymbolicTradingEvaluator.cs" />
    195204    <Compile Include="Symbolic\Interfaces\ISymbolicTradingModel.cs" />
     
    228237    <None Include="HeuristicLab.snk" />
    229238    <None Include="HeuristicLabProblemsDataAnalysisTradingPlugin.cs.frame" />
    230     <None Include="Properties\AssemblyInfo.frame" />
    231239    <Compile Include="Properties\AssemblyInfo.cs" />
     240    <None Include="Properties\AssemblyInfo.cs.frame" />
    232241  </ItemGroup>
    233242  <ItemGroup>
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/HeuristicLabProblemsDataAnalysisTradingPlugin.cs.frame

    r6126 r9176  
    2828  [Plugin("HeuristicLab.Problems.DataAnalysis.Trading","Provides classes to optimize trading rules (single- or multiobjective).", "3.4.0.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Trading-3.4.dll", PluginFileType.Assembly)]
    30   [PluginDependency("HeuristicLab.ALGLIB", "3.1")]
     30  [PluginDependency("HeuristicLab.ALGLIB", "3.6")]
    3131  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3232  [PluginDependency("HeuristicLab.Common", "3.3")]
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Symbolic/SingleObjective/SymbolicTradingSingleObjectiveProblem.cs

    r6123 r9176  
    5858    }
    5959
    60     public override void ImportProblemDataFromFile(string fileName) {
    61       TradingProblemData problemData = TradingProblemData.ImportFromFile(fileName);
    62       ProblemData = problemData;
    63     }
     60    //public override void ImportProblemDataFromFile(string fileName) {
     61    //  TradingProblemData problemData = TradingProblemData.ImportFromFile(fileName);
     62    //  ProblemData = problemData;
     63    //}
    6464  }
    6565}
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Symbolic/SingleObjective/SymbolicTradingSingleObjectiveSharpeRatioEvaluator.cs

    r6861 r9176  
    6060    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, ITradingProblemData problemData, IEnumerable<int> rows) {
    6161      IEnumerable<double> signals = GetSignals(interpreter, solution, problemData.Dataset, rows);
    62       IEnumerable<double> returns = problemData.Dataset.GetEnumeratedVariableValues(problemData.PriceVariable, rows);
     62      IEnumerable<double> returns = problemData.Dataset.GetDoubleValues(problemData.PriceVariable, rows);
    6363      OnlineCalculatorError errorState;
    6464      double sharpRatio = OnlineSharpeRatioCalculator.Calculate(returns, signals, problemData.TransactionCosts, out errorState);
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Symbolic/SymbolicTradingSolution.cs

    r6126 r9176  
    7070    }
    7171
    72     protected override void OnModelChanged(EventArgs e) {
    73       base.OnModelChanged(e);
     72    protected override void OnModelChanged() {
     73      base.OnModelChanged();
    7474      RecalculateResults();
    7575    }
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/TradingProblem.cs

    r6125 r9176  
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HeuristicLab.Problems.Instances;
    2526
    2627namespace HeuristicLab.Problems.DataAnalysis {
     
    3940      ProblemData = new TradingProblemData();
    4041    }
    41 
    42     public override void ImportProblemDataFromFile(string fileName) {
    43       TradingProblemData problemData = TradingProblemData.ImportFromFile(fileName);
    44       ProblemData = problemData;
    45     }
    4642  }
    4743}
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/TradingProblemData.cs

    r6125 r9176  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Problems.Instances;
     32using HeuristicLab.Problems.Instances.DataAnalysis;
    3133
    3234namespace HeuristicLab.Problems.DataAnalysis {
     
    16481650    }
    16491651
    1650     #region Import from file
    1651     public static TradingProblemData ImportFromFile(string fileName) {
    1652       TableFileParser csvFileParser = new TableFileParser();
    1653       csvFileParser.Parse(fileName);
     1652   
    16541653
    1655       Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
    1656       dataset.Name = Path.GetFileName(fileName);
    16571654
    1658       TradingProblemData problemData = new TradingProblemData(dataset, dataset.VariableNames.Skip(1), dataset.VariableNames.First());
    1659       problemData.Name = "Data imported from " + Path.GetFileName(fileName);
    1660       return problemData;
    1661     }
    1662     #endregion
     1655    //#region Import from file
     1656    //public static TradingProblemData ImportFromFile(string fileName) {
     1657    //  TableFileParser csvFileParser = new TableFileParser();
     1658    //  csvFileParser.Parse(fileName);
     1659
     1660    //  Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
     1661    //  dataset.Name = Path.GetFileName(fileName);
     1662
     1663    //  TradingProblemData problemData = new TradingProblemData(dataset, dataset.VariableNames.Skip(1), dataset.VariableNames.First());
     1664    //  problemData.Name = "Data imported from " + Path.GetFileName(fileName);
     1665    //  return problemData;
     1666    //}
     1667    //#endregion
    16631668  }
    16641669}
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/TradingSolution.cs

    r6937 r9176  
    3636    private const string TrainingSharpeRatioResultName = "Sharpe ratio (training)";
    3737    private const string TestSharpeRatioResultName = "Sharpe ratio (test)";
     38    private const string TrainingProfitResultName = "Profit (training)";
     39    private const string TestProfitResultName = "Profit (test)";
    3840
    3941    public new ITradingModel Model {
     
    5658      private set { ((DoubleValue)this[TestSharpeRatioResultName].Value).Value = value; }
    5759    }
     60    public double TrainingProfit {
     61      get { return ((DoubleValue)this[TrainingProfitResultName].Value).Value; }
     62      private set { ((DoubleValue)this[TrainingProfitResultName].Value).Value = value; }
     63    }
     64
     65    public double TestProfit {
     66      get { return ((DoubleValue)this[TestProfitResultName].Value).Value; }
     67      private set { ((DoubleValue)this[TestProfitResultName].Value).Value = value; }
     68    }
    5869
    5970    [StorableConstructor]
     
    6677      Add(new Result(TrainingSharpeRatioResultName, "Share ratio of the signals of the model on the training partition", new DoubleValue()));
    6778      Add(new Result(TestSharpeRatioResultName, "Sharpe ratio of the signals of the model on the test partition", new DoubleValue()));
     79      Add(new Result(TrainingProfitResultName, "Profit of the model on the training partition", new DoubleValue()));
     80      Add(new Result(TestProfitResultName, "Profit of the model on the test partition", new DoubleValue()));
    6881
    6982      RecalculateResults();
    7083    }
    7184
    72     protected override void OnProblemDataChanged(EventArgs e) {
    73       base.OnProblemDataChanged(e);
     85
     86    protected override void OnModelChanged() {
     87      base.OnModelChanged();
    7488      RecalculateResults();
    7589    }
    76     protected override void OnModelChanged(EventArgs e) {
    77       base.OnModelChanged(e);
     90
     91    protected override void OnProblemDataChanged() {
     92      base.OnProblemDataChanged();
    7893      RecalculateResults();
    7994    }
     
    8196    protected override void RecalculateResults() {
    8297      double[] trainingSignals = TrainingSignals.ToArray(); // cache values
    83       IEnumerable<double> trainingReturns = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.PriceVariable, ProblemData.TrainingIndizes);
     98      IEnumerable<double> trainingReturns = ProblemData.Dataset.GetDoubleValues(ProblemData.PriceVariable, ProblemData.TrainingIndices);
    8499      double[] testSignals = TestSignals.ToArray(); // cache values
    85       IEnumerable<double> testReturns = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.PriceVariable, ProblemData.TestIndizes);
    86    
     100      IEnumerable<double> testReturns = ProblemData.Dataset.GetDoubleValues(ProblemData.PriceVariable, ProblemData.TestIndices);
     101
    87102      OnlineCalculatorError errorState;
    88103      double trainingSharpeRatio = OnlineSharpeRatioCalculator.Calculate(trainingReturns, trainingSignals, ProblemData.TransactionCosts, out errorState);
     
    90105      double testSharpeRatio = OnlineSharpeRatioCalculator.Calculate(testReturns, testSignals, ProblemData.TransactionCosts, out errorState);
    91106      TestSharpeRatio = errorState == OnlineCalculatorError.None ? testSharpeRatio : double.NaN;
     107
     108      double trainingProfit = OnlineProfitCalculator.Calculate(trainingReturns, trainingSignals, ProblemData.TransactionCosts, out errorState);
     109      TrainingProfit = errorState == OnlineCalculatorError.None ? trainingProfit : double.NaN;
     110      double testProfit = OnlineProfitCalculator.Calculate(testReturns, testSignals, ProblemData.TransactionCosts, out errorState);
     111      TestProfit = errorState == OnlineCalculatorError.None ? testProfit : double.NaN;
    92112
    93113    }
     
    101121    public virtual IEnumerable<double> TrainingSignals {
    102122      get {
    103         return GetSignals(ProblemData.TrainingIndizes);
     123        return GetSignals(ProblemData.TrainingIndices);
    104124      }
    105125    }
     
    107127    public virtual IEnumerable<double> TestSignals {
    108128      get {
    109         return GetSignals(ProblemData.TestIndizes);
     129        return GetSignals(ProblemData.TestIndices);
    110130      }
    111131    }
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Views/TradingSolutionLineChartView.cs

    r6861 r9176  
    3333  [View("Line Chart")]
    3434  [Content(typeof(ITradingSolution))]
    35   public partial class TradingSolutionLineChartView : ItemView, ITradingSolutionEvaluationView {
     35  public partial class TradingSolutionLineChartView : DataAnalysisSolutionEvaluationView, ITradingSolutionEvaluationView {
    3636    private const string PRICEVARIABLE_SERIES_NAME = "Price";
    3737    private const string SIGNALS_SERIES_NAME = "Signals";
    3838    private const string ASSET_SERIES_NAME = "Asset";
     39
    3940
    4041    public new ITradingSolution Content {
     
    7273        this.chart.Series[SIGNALS_SERIES_NAME].Tag = Content;
    7374
    74         IEnumerable<double> accumulatedPrice = GetAccumulatedPrices(Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.PriceVariable));
     75        IEnumerable<double> accumulatedPrice = GetAccumulatedPrices(Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.PriceVariable));
    7576        this.chart.Series.Add(PRICEVARIABLE_SERIES_NAME);
    7677        this.chart.Series[PRICEVARIABLE_SERIES_NAME].LegendText = PRICEVARIABLE_SERIES_NAME;
     
    7980        this.chart.Series[PRICEVARIABLE_SERIES_NAME].Tag = Content;
    8081
    81         IEnumerable<double> profit = GetProfits(Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.PriceVariable), Content.Signals, Content.ProblemData.TransactionCosts);
     82        IEnumerable<double> profit = GetProfits(Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.PriceVariable), Content.Signals, Content.ProblemData.TransactionCosts);
    8283        IEnumerable<double> accumulatedProfits = GetAccumulatedPrices(profit);
    8384        this.chart.Series.Add(ASSET_SERIES_NAME);
     
    9495
    9596    private IEnumerable<double> GetProfits(IEnumerable<double> returns, IEnumerable<double> signals, double transactionCost) {
    96       double p = signals.First();
     97      int p = (int)signals.First();
    9798      yield return 0.0;
    9899      foreach (var signalReturn in returns.Skip(1).Zip(signals.Skip(1), (r, s) => new { Return = r, Signal = s })) {
     
    118119          iterationReturn = -actualReturn;
    119120        } else if (p == -1 && signal.IsAlmost(0)) {
    120           iterationReturn = -(actualReturn - transactionCost);
     121          iterationReturn = -actualReturn - transactionCost;
    121122          p = 0;
    122123        } else if (p == -1 && signal.IsAlmost(1)) {
    123           iterationReturn = -(actualReturn - transactionCost);
     124          iterationReturn = -actualReturn - transactionCost;
    124125          p = 1;
    125126        }
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Views/TradingSolutionView.cs

    r6123 r9176  
    3434      var regressionSolutionEvaluationViewTypes = ApplicationManager.Manager.GetTypes(typeof(ITradingSolutionEvaluationView), true);
    3535      foreach (Type viewType in regressionSolutionEvaluationViewTypes)
    36         AddViewListViewItem(viewType);
     36        AddViewListViewItem(viewType, HeuristicLab.Common.Resources.VSImageLibrary.Graph);
    3737    }
    3838
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/Main/Main.csproj

    r6127 r9176  
    4444  </ItemGroup>
    4545  <ItemGroup>
    46     <None Include="CopyAssemblies.cmd" />
    4746    <None Include="CustomPostBuild.cmd" />
    4847  </ItemGroup>
  • branches/HeuristicLab.Problems.DataAnalysis.Trading/PreBuildEvent.cmd

    r6127 r9176  
    1 SubWCRev "%ProjectDir%\" "%ProjectDir%\Properties\AssemblyInfo.frame" "%ProjectDir%\Properties\AssemblyInfo.cs"
     1IF EXIST "%ProjectDir%\Properties\AssemblyInfo.cs.frame" SubWCRev "%ProjectDir%\" "%ProjectDir%\Properties\AssemblyInfo.cs.frame" "%ProjectDir%\Properties\AssemblyInfo.cs"
     2IF EXIST "%ProjectDir%\Plugin.cs.frame" SubWCRev "%ProjectDir%\" "%ProjectDir%\Plugin.cs.frame" "%ProjectDir%\Plugin.cs"
Note: See TracChangeset for help on using the changeset viewer.