Algorithmic Trading Python

LSTM Long Regression Strategy for Algorithmic Trading

After my first video on LSTM’s long strategy on algorithmic trading, i got a feedback to try out the regression instead of classification. In this tutorial, i will show the result of experiment with LSTM regression loing strategy. I also found that the rolling scaling has a big impact on the performance. Increasing the rolling window seem to increase more trades in the testing data.
The first few steps are identical to my previous video, so I will not repeat there here.
I have increased  the rolling scaling window to 8 months to take in account of the non-stationary nature of the time series. Let me know if this make sense. 
Since this is the regression model, my target is not categorical labels of 1 and 0, but instead my target is the next day returns.
To change to a regression model, i change the output layer to a linear activation function and the loss function to mse. 
I trained the model with 200 epochs and got a decent loss vs epochs curve showing the LSTM model is learning from the data. 
I compute the signal to be taking a long position  if the predicted return is positive and no position if the predicted return is negative. 
I am able to get a lot more trades in the training and testing dataset.
I have a comparable equity curve as compared to bnh benchmark. The Sharpe ratio has improved to 0.89 and a max drawdown of -49%. 

The code can be downloaded below

Recommended trading platforms


Recommended courses on Algorithmic Trading

1. Basic Algorithmic Trading with Python

2. Machine Learning for Algorithmic Trading

Other training courses from Tertiary Courses

June 12, 2022