#Technology #Machine learning #Finance

Forecasting Profits Direction: Weekly Stop-Loss and Stop-Gain

In a previous post we backtested our logistic model with walk-forward and we found two useful trading configurations, one for Monday-Wednesday and the other for Tuesday-Thursday-Friday. They are reported hereafter.

Now, a question we could have is, do there is any way to improve our pnl ? We know that we could try a different machine learning paradigm in order to improve our training metrics (i.e. accuracy, sensitivity and specificity) but, assuming we don’t want to go to this direction, we can still try to improve our pnl by reducing our losses. So the key question is how much we could gain if we could “guess” which among the selected trades will eventually result on a loss.

A rough way to do such estimation is to compute for each configuration and for each week of backtesting its maximum pnl, the result is in the following two images. We can see that there is a lot of space of pnl improvement in both configurations. However, it is fair to recognize that the values reported on such images are the “ideal” case which can only be reached by a golden oracle, we can only hope to gain some fraction of such values. Instead, it is extremely interesting to remark how the maximum pnl shapes are independent from the chosen time frame. This is really important because it tells us that our forecasting model has a stationary behavior versus the time frame parameter, i.e. we are not expected to gain or lose anything choosing a time frame instead of another one. And, therefore, we can have more confidence on the long-term reliability of our model.

Of course, we can also compute the minimum pnl. As we can see there is also much room to loose money instead of gaining. This is to remember us that improving our pnl is not a free lunch, we need to find the right metrics and the right algorithms. Still, they confirm our previous remark on the stationary behavior of our model. In addition, we can see that maximum and minimal values of pnl are on the same absolute range for each configuration and for each year (for example, max for dow13 2019 is around 1500-2000 and the same is for the min but with negatives values).

A possible way to improve our pnl is to set a stop-loss and a stop-gain on a given period of time. In order to validate such idea, we have backtested the pnl by adding a weekly stop-loss (WSL) and a weekly stop-gain (WSG). Stops are checked at the end of each trade, when one is hit the trading is stop for the actual day and the coming days of the week. The backstesting was done for several levels, positive for the stop-gain and negative for the stop-loss: 5, 10, 15, 20, 25, 30, 35 and 100.

The following picture shows the total pnl at the end of the five years for each couple <WSG, WSL> and each timeframe in the case of DOW245. The yellow point is the optimal pnl without stop-loss or stop-gain, so for example in the timeframe 0.5 we get the original optimal pnl just over 800. Instead, the orange point is the global optimal for the given timeframe considering all the possible couples <WSG, WSL>. In this case, we can see that applying stop-gain and stop-loss to the timeframes 1.0 and 1.5 can result on an improved pnl. Actually, considering the timeframe 1.5 the improvement is extremely important, from pnl around 0 to around 500. However, considering all the three timeframes, the optimal configuration is still in the timeframe 0.5 and the global optimal (orange point) is basically at the same level of pnl of the original optimal. So, overall there is no gain in pnl by applying weekly stop-loss and stop-gain to DOW245 configuration.

The result is quite different for the case DOW13, like we can see in the following picture. The pnl can be improved of around 200 points, reaching around 900 points in timeframe 1.0 and 1.5 by applying <WSG, WSL>=<+20, -35>.

We can analyse the configuration DOW13 in mode details by checking the contribution of each single day. If we do this we will discover that most of the pnl contribution belong to Wednesday alone where there is an optimal global configuration of <WSG, WSL>=<nolimit, -5> for timeframe 1.0, resulting on a total pnl of around 700 in 5 years. Doing the same for Monday we discover that its total contribution is around 200 points which are gained the first year and then there is no major gain. So, the conclusion is that it is more interesting to trade only Wednesday with <WSG, WSL>=<nolimit, -5> and to avoid the trading fees for Monday.

In summary, we can gain something by applying a weekly stop-loss and stop-gain but not much and, in any case, very far from the potential gains we expected. The final trading strategy is:

  • DOW245: baseline strategy with timeframe 0.5

  • DOW3: baseline strategy time frame 1.0 and weekly stop-loss of -5

  • DOW1: no trades