NEW+--
Min 75% OFF | Pay Day Sale Extended till 3rd June
Move Left Complete list

What is Walk-Forward Optimisation and How to Implement It?

 

In this post, you will learn to realistically backtest the LSTM neural network created to calculate the optimum weights of assets in the portfolio using the walk-forward optimisation method. 

 

The following is the performance of a portfolio based on the LSTM network backtested using the walk-forward optimisation method.

It is important to note that backtesting results do not guarantee future performance. The presented strategy results are intended solely for educational purposes and should not be interpreted as investment advice. A comprehensive evaluation of the strategy across multiple parameters is necessary to assess its effectiveness.

All the concepts covered in this post are taken from section 14 of the Quantra course on 

AI for Portfolio Management: LSTM Networks. You can preview the concepts taught in this course by clicking on the free preview button.

Note: The links in this tutorial will be accessible only after logging into quantra.quantinsti.com and enrolling for the free preview of the course.


 

What is walk-forward optimisation?

Walk-forward optimisation is a technique used in portfolio management to improve the robustness of a trading strategy by simulating its performance in real-time. 

Instead of optimising a strategy using the entire historical dataset and then assessing its performance on a separate out-of-sample dataset, walk-forward optimisation continuously updates the strategy as new data becomes available.

 

How to perform walk-forward optimisation?

Here are the steps involved in a walk-forward optimisation process for portfolio management:

Initial optimisation:

  • Begin by optimising your trading strategy using a historical dataset.
  • Select parameters, indicators, and other elements of your strategy based on historical data to maximise performance.

 

In-Sample Period:

  • Apply the optimised strategy to a specific in-sample period, typically a segment of historical data.
  • Evaluate the performance metrics during this in-sample period.

 

Out-of-Sample Period:

  • After the in-sample period, apply the strategy to a subsequent out-of-sample period that was not used during the initial optimisation.
  • Evaluate the performance during this out-of-sample period to ensure the strategy generalizes well to new data.

 

Re-optimisation:

  • After the out-of-sample period, re-optimise the strategy using an extended dataset that includes both the in-sample and out-of-sample periods.
  • Adjust parameters or retrain models as needed to adapt to evolving market conditions.

 

Repeat:

  • Repeat steps 2-4 iteratively as new data becomes available.
  • Continuously update and re-optimise the strategy using the latest data.

 

The walk-forward optimisation approach helps to adapt the strategy to changing market conditions and ensures that it remains effective over time. It also reduces the risk of overfitting to specific historical patterns that may not persist in the future.

 

It's important to note that while walk-forward optimisation can enhance the robustness of a strategy, it doesn't guarantee future performance. Regular monitoring, evaluation, and adaptation are crucial to maintaining the effectiveness of the portfolio management strategy in dynamic market environments.

To summarise, walk-forward optimisation is used for the practical evaluation of trading or investment strategies. The walk-forward optimisation Iteratively trains and tests a model or strategy as new data becomes available

For WFO, a window size is defined to represent the size of the train/test set and a step size is defined to represent the size of the walk-forward step.

 


 

Walk-Forward Optimisation of LSTM Network

 

To perform WFO for an LSTM network created to calculate the optimum weights of assets in a portfolio, the LSTM network is initialised only once at the beginning. The weights of the LSTM network are updated in each WFO cycle.

 

Consider this example data of 20 days.

Initialise the WFO with:

 

  • Window size = 5 days (Size of train/test data)
  • Step size = 3 days forward (Size of walk forward step)

 

Also, initialise the LSTM model with random weights. 

 

Iteration-1:

 

In the first iteration,

  • In-sample training: Train the LSTM model on day 1 to 5 data. The weights are updated in the in-sample training step.
  • Out-of-sample testing: Test the performance of the LSTM model on day 6-10 data and save the results. 


 

Iteration-2:

In the second iteration,

  • In-sample training: Train the LSTM model on days 4 to 8 data. The weights are updated in the in-sample training step.
  • Out-of-sample testing: Test the performance of the LSTM model on days 9-13 data and save results

 

Similarly, the in-sample training and out-of-sample testing are done in iterations 3 and 4.

 

Iteration-3:

  • In-sample training: Train the LSTM model on days 7 to 11 data. 
  • Out-of-sample testing: Test the performance of the LSTM model on days 12-16 data and save results

 

Iteration-4:

  • In-sample training: Train the LSTM model on days 10 to 14 data. 
  • Out-of-sample testing: Test the performance of the LSTM model on days 15-19 data and save results

 

It should be noted that the LSTM weights are updated in multiple training periods i.e. different market conditions. The performance of the test period gives backtest results of the portfolio created using the weights calculated by the LSTM model.

 

The following is the performance plot generated by applying the walk-forward optimisation on the LSTM network created on the assets AAPL, IBM, AMZN, and CSCO from December 31, 2009, to December 31, 2020, with a step size of 180 and a window size of 180.

 

It is important to note that backtesting results do not guarantee future performance. The presented strategy results are intended solely for educational purposes and should not be interpreted as investment advice. A comprehensive evaluation of the strategy across multiple parameters is necessary to assess its effectiveness.

For Python implementation of the walk-forward optimisation method for the LSTM network in the context of portfolio management, check out the section Walk Forward Optimisation With LSTM.

 


 

What to do next? 

  • Go to this course 
  • Click on
  • Go through 10-15% of course content 

Drop us your comments and queries on the community

 


 

IMPORTANT DISCLAIMER: This post is for educational purposes only and is not a solicitation or recommendation to buy or sell any securities. Investing in financial markets involves risks and you should seek the advice of a licensed financial advisor before making any investment decisions. Your investment decisions are solely your responsibility. The information provided is based on publicly available data and our own analysis, and we do not guarantee its accuracy or completeness. By no means is this communication sent as the licensed equity analysts or financial advisors and it should not be construed as professional advice or a recommendation to buy or sell any securities or any other kind of asset.

RELATED KEYWORDS