Changeset 9938 for trunk/sources
- Timestamp:
- 09/10/13 14:21:27 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Calculators/OnlineProfitCalculator.cs
r9744 r9938 28 28 public class OnlineProfitCalculator : IOnlineCalculator { 29 29 30 private int p ;30 private int position; // currently held position: -1: short, 0: out of market, 1: long 31 31 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; 34 34 public double Profit { 35 get { return sum; }35 get { return totalProfit; } 36 36 } 37 37 … … 49 49 } 50 50 public void Reset() { 51 p = 0;52 c = 0;53 sum= 0.0;51 position = 0; 52 count = 0; 53 totalProfit = 0.0; 54 54 } 55 55 56 56 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++; 62 62 } 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; 86 86 } 87 c ++;87 count++; 88 88 } 89 sum += iterationReturn;89 totalProfit += profit; 90 90 } 91 91 #endregion
Note: See TracChangeset
for help on using the changeset viewer.