Skip to content

Alqama-svg/Quant_Strategy_Backtester

Repository files navigation

Quant Strategy Backtester — DD < 2% RoI > 40% Sharpe 2.36

1. Overview

The complete backtest analysis for the strategy has been published using QuantStats, providing a deep dive into performance, risk, and return metrics. Click below to explore the full institutional-style interactive report (Sharpe, Sortino, Drawdowns, Rolling Returns, and much more): Click here to view the full QuantStats backtest report


2. Results Summary (QuantX V4.9 Full-Year 2024 Backtest)

Date Range: 2024-01-02 → 2024-12-31
Tickers: 32 (Dow 30 + additional large-cap stocks)

Metric Value
Initial Capital $1,000,000
Final Capital $1,401,058
Total Return +40.11%
Annualized Return 26.30%
Max Drawdown –1.91%
Sharpe Ratio (annualized) 2.36
Trades Executed 3,308
Win Rate 66.63%
Avg Win / Loss +$480.21 / –$345.07
Volatility (annualized) 11.13%
Profit Factor 1.72

Diagnostics Summary:

  • Entries: 3,308
  • Intraday exits: 55
  • EOD closes: 3,253
  • Z-score invalids (fails): 1,234,512
  • Volatility filter fails: 27
  • Trend filter fails: 568,989
  • Position size fails: 48,938
  • Cash availability fails: 353

3. Analytical Outputs

The following analytical components are provided as part of the QuantX V4.9 backtest package:

  1. Equity Curve

    • Cumulative balance over time, starting from $1M base.
    • Equity initialization begins on 8 Jan 2024 after the first valid signal post warm-up period.
  2. PnL Distribution

    • Histogram of per-trade profits/losses showing slight right-skew and light tails, consistent with mean-reversion payoff distribution.
  3. Monthly Return Distribution

    • 11 out of 12 months were profitable; the worst drawdown was under 2%.
  4. QuantStats Tear Sheet

    • Detailed return statistics, monthly returns, drawdown table, and benchmark-relative plots.
    • File: QuantX_V4.9_QuantStats_Report_Full.pdf.
  5. Ticker Trade Charts

    • 32 individual PNGs showing price action with trade markers ( entries, exits).
    • Cleaned from zero-value anomalies.
  6. Trade Log

    • QuantX_V4.9_Trades_Report.csv and .xlsx contain:
      • Time of Signal
      • Ticker
      • Entry/Exit prices
      • PnL
      • Z-score at signal
      • Position size
  7. Equity Curve Data

    • QuantX_V4.9_EquityCurve.csv for custom analysis in Python or Excel.

4. Interpretation of Results

  • The framework generated consistent low-drawdown performance, achieving ~26% annualized return with sub-2% drawdown.
  • High trade frequency implies strong statistical validity and robustness of Z-score thresholds.
  • Limited correlation with SPY confirms mean-reversion’s market-neutral nature.
  • Drawdowns remain shallow, suggesting effective volatility-normalized position sizing and proper intraday stop management.

5. Future Scope and Expansion

  1. Multi-Asset Extension:
    Expand universe to include ETFs, futures, or FX pairs with synchronized tick data for cross-asset mean reversion.

  2. Machine Learning Enhancements:
    Integrate adaptive thresholding via regime detection (Hidden Markov Models or clustering-based volatility state identification).

  3. Transaction Cost Modeling:
    Include realistic limit order fills using LOB simulation or dynamic spread modeling.

  4. Execution Optimization:
    Test VWAP and TWAP-based execution for partial fill simulation.

  5. Portfolio Optimization:
    Introduce dynamic capital allocation across tickers based on rolling Sharpe or drawdown-adjusted return.

  6. Live Deployment:
    Integrate with broker APIs (e.g., Interactive Brokers) for paper/live trading environment.


6. Reproducibility

Environment

Tool Version
Python 3.10
Pandas 2.1.1
NumPy 1.26
Matplotlib 3.8
QuantStats 0.0.60
pdfkit 1.0.0
wkhtmltopdf 0.12.6
Conda Environment quantx_v49

Data

  • Source: Proprietary minute-level OHLCV data for Dow 30 equities.
  • Location: Data/1 Min Data/OHLC/
  • Cached path (if using joblib): notebooks/cache_minute_data/joblib/__main__...

Reproduction Steps

  1. Activate environment:
    conda activate quantx_v49

  2. Run backtest notebook:
    notebooks/run_backtest.ipynb

  3. Generate reports:
    notebooks/analysis.ipynb

  4. Convert QuantStats HTML to PDF using pdfkit or browser print.


7. Repository Structure

Quant_Strategy_Backtester/
├── README.md
├── environment.yml
├── requirements.txt
├── data/
│ └── 1 Min Data/OHLC/
├── notebooks/
│ ├── run_backtest.ipynb
│ ├── analysis.ipynb
│ └── cache_minute_data/
├── src/
│ ├── strategy.py
│ ├── backtest.py
│ ├── execution.py
│ ├── reporting.py
│ └── utils.py
├── outputs/
│ ├── QuantX_Final_Backtest_Results.pdf
│ ├── QuantX_V4.9_QuantStats_Report_Full.pdf
│ ├── QuantX_V4.9_Trades_Report.xlsx
│ ├── QuantX_V4.9_EquityCurve.xlsx
│ ├── QuantX_V4.9_EquityCurve.png
│ ├── QuantX_V4.9_PnL_Hist.png
│ └── charts/
│ ├── chart_AAPL_all_trades.png
│ ├── chart_MSFT_all_trades.png
│ └── ...
└── docs/
└── backtest_performance_template.pdf

8. Conclusion

Strategy demonstrates the efficacy of a statistically disciplined, volatility-adjusted intraday mean-reversion framework.
The backtest confirms that a properly parameterized short-horizon strategy can achieve superior risk-adjusted returns while maintaining minimal drawdowns.

This repository serves as a complete and reproducible record of the strategy’s design, assumptions, implementation, and results, suitable for internal audit, investment committee review, or further research development.


9. License

Released under the MIT License.
Copyright © 2025 Alqama Ansari.


10. Citation

If referencing or using this codebase in research:

Ansari, A. (2025). QuantX V4.9: Intraday Mean-Reversion Strategy Backtest. GitHub Repository. https://github.com/ /Quant_Strategy_Backtester

About

A systematic intraday mean reversion strategy framework built for multi-asset execution and backtesting. Implements z-score-based signal generation, position sizing, and portfolio-level risk controls. Includes complete research pipeline, performance reporting, and QuantStats analytics.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors