A quantitative trading strategy backtester with an interactive dashboard. Enables users to implement, test, and visualise trading strategies using historical market data, featuring customisable parameters and key performance metrics. Developed with Python.
Try the deployed app here!
- Buy and Hold
- Mean Reversion
- Moving Average Crossover
- Pairs Trading
- Interactive web-based dashboard using Streamlit
- Efficient data processing using Polars for improved performance
- Support for multiple trading strategies with customisable parameters
- Real-time data fetching from Yahoo Finance
- Automatic optimisation of strategy parameters and stock selection from S&P 500
- Visualisation of equity curves and strategy returns
- Performance metrics including Total Return, Sharpe Ratio, and Max Drawdown
- Monthly performance table with rolling returns
I originally implemented the backtester and optimiser using pandas, but I wanted to explore the performance benefits of using Polars.
After refactoring the code to use Polars, I manually benchmarked the two implementations on my local machine (Apple M1 Max with 10 CPU cores and 32 GPU cores, 32 GB unified memory) and on the deployed Streamlit instance. Each run was a backtest from 2020/01/01 to 2023/12/31 for the pairs trading strategy, with ticker-pair optimisation amongst the top 20 S&P 500 stocks and parameter optimisation enabled.
Polars was faster by 2.1x on average compared to pandas on my local machine, and faster by 1.8x on average on the Streamlit instance.
The full benchmark results can be found in the CSV files in the resources folder.
Run the following command from the project root directory:
uv sync --all-extras --dev
Run the following command from the project root directory:
poe app
Alternatively, run it directly with uv (skipping the Poe alias):
uv run streamlit run src/quant_trading_strategy_backtester/app.py