Backtesting Cointegration Portfolio Weight Updates with RWEC
Summary
This installment explains how to simulate changing portfolio weights for a cointegrated stock basket in MetaTrader 5 backtests. Since the live Expert Advisor reads strategy parameters from a database but the Tester cannot access that database directly, the article exports the strategy table to a tab-separated file and loads updates from it during the test. A Python script runs Rolling Windows Eigenvector Comparison (RWEC), stores the resulting cointegration vectors, and supplies the changing weights for the backtest.
The article describes sequentially reading the file with timestamps aligned to the backtest to mimic live updates. It discusses how the evaluation period, cointegration window length and forward step affect the analysis, and says parameter backtests can help assess signal stability and rebalancing behavior. It provides example scripts and file-handling guidance, but the supplied text does not give detailed performance results or prove that rebalancing improves returns. Cointegration can break, and the method’s usefulness depends on adequate historical data and parameter choices.
Key ideas
- Cointegration vectors can be translated into relative portfolio weights for a basket.
- RWEC supplies updated eigenvectors that can be used to revise those weights.
- A Tester-accessible TSV file can simulate database-fed strategy updates in backtests.
- Update timestamps should align with the simulated trading timeline.
- Backtests can examine the effects of the analysis window and rolling step, but cannot guarantee that cointegration persists.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.