Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9938


Ignore:
Timestamp:
09/10/13 14:21:27 (11 years ago)
Author:
gkronber
Message:

#1508: renamed variables in ProfitCalculator

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Calculators/OnlineProfitCalculator.cs

    r9744 r9938  
    2828  public class OnlineProfitCalculator : IOnlineCalculator {
    2929
    30     private int p;
     30    private int position; // currently held position: -1: short, 0: out of market, 1: long
    3131    private readonly double transactionCost;
    32     private int c;
    33     private double sum;
     32    private int count; // only necessary to reset position and total profit on the first data point
     33    private double totalProfit;
    3434    public double Profit {
    35       get { return sum; }
     35      get { return totalProfit; }
    3636    }
    3737
     
    4949    }
    5050    public void Reset() {
    51       p = 0;
    52       c = 0;
    53       sum = 0.0;
     51      position = 0;
     52      count = 0;
     53      totalProfit = 0.0;
    5454    }
    5555
    5656    public void Add(double actualReturn, double signal) {
    57       double iterationReturn = 0.0;
    58       if (c == 0) {
    59         p = (int)signal;
    60         iterationReturn = 0;
    61         c++;
     57      double profit = 0.0;
     58      if (count == 0) {
     59        position = (int)signal;
     60        profit = 0;
     61        count++;
    6262      } else {
    63         if (p == 0 && signal.IsAlmost(0)) {
    64         } else if (p == 0 && signal.IsAlmost(1)) {
    65           p = 1;
    66           iterationReturn = -transactionCost;
    67         } else if (p == 0 && signal.IsAlmost(-1)) {
    68           p = -1;
    69           iterationReturn = -transactionCost;
    70         } else if (p == 1 && signal.IsAlmost(1)) {
    71           iterationReturn = actualReturn;
    72         } else if (p == 1 && signal.IsAlmost(0)) {
    73           iterationReturn = actualReturn - transactionCost;
    74           p = 0;
    75         } else if (p == 1 && signal.IsAlmost(-1)) {
    76           iterationReturn = actualReturn - transactionCost;
    77           p = -1;
    78         } else if (p == -1 && signal.IsAlmost(-1)) {
    79           iterationReturn = -actualReturn;
    80         } else if (p == -1 && signal.IsAlmost(0)) {
    81           iterationReturn = -actualReturn - transactionCost;
    82           p = 0;
    83         } else if (p == -1 && signal.IsAlmost(1)) {
    84           iterationReturn = -actualReturn - transactionCost;
    85           p = 1;
     63        if (position == 0 && signal.IsAlmost(0)) {
     64        } else if (position == 0 && signal.IsAlmost(1)) {
     65          position = 1;
     66          profit = -transactionCost;
     67        } else if (position == 0 && signal.IsAlmost(-1)) {
     68          position = -1;
     69          profit = -transactionCost;
     70        } else if (position == 1 && signal.IsAlmost(1)) {
     71          profit = actualReturn;
     72        } else if (position == 1 && signal.IsAlmost(0)) {
     73          profit = actualReturn - transactionCost;
     74          position = 0;
     75        } else if (position == 1 && signal.IsAlmost(-1)) {
     76          profit = actualReturn - transactionCost;
     77          position = -1;
     78        } else if (position == -1 && signal.IsAlmost(-1)) {
     79          profit = -actualReturn;
     80        } else if (position == -1 && signal.IsAlmost(0)) {
     81          profit = -actualReturn - transactionCost;
     82          position = 0;
     83        } else if (position == -1 && signal.IsAlmost(1)) {
     84          profit = -actualReturn - transactionCost;
     85          position = 1;
    8686        }
    87         c++;
     87        count++;
    8888      }
    89       sum += iterationReturn;
     89      totalProfit += profit;
    9090    }
    9191    #endregion
Note: See TracChangeset for help on using the changeset viewer.