- Python 62.8%
- MQL5 36.2%
- MQL4 1%
| BeyondGARCH | ||
| Experts/MMAR | ||
| Include/MMAR | ||
| Scripts/MMAR | ||
| LICENSE.md | ||
| README.md | ||
MMAR Volatility Forecasting
Multifractal Model of Asset Returns (MMAR) implementation for volatility forecasting, based on the work of Mandelbrot, Calvet, and Fisher (1997) and the empirical methodology of Zhang (2017).
This project accompanies the MQL5 article series:
- Part 1: Mandelbrot vs. Engle
- Part 2: Measuring the Fractal Dimension of Markets
- Part 3: Building the MMAR and the Verdict
- Part 4: Partition Analysis in MQL5
- Part 5: Fitting the Multifractal Spectrum in MQL5
- Part 6: Fractional Brownian Motion And The Multiplicative Cascade in MQL5
- Part 7: Monte Carlo Volatility Forecasting in MQL5
- Part 8: The MMAR Library And Putting it to Work in an Expert Advisor
Overview
The MMAR models financial returns as a Fractional Brownian Motion compounded by multifractal trading time:
X(t) = B_H[theta(t)]
Where:
- B_H(t) is a Fractional Brownian Motion with Hurst exponent H, capturing long memory and persistence in returns.
- theta(t) is multifractal trading time (the CDF of a multifractal measure constructed via multiplicative cascade), capturing volatility clustering and fat tails.
This compound process produces long memory, fat tails, volatility clustering, and scale consistency simultaneously — not as separate patches, but as natural consequences of a single generative mechanism.
The 7-Step Pipeline
| Step | Module | Purpose |
|---|---|---|
| 1 | step1_check_fractality.py |
Partition function analysis — tests whether moment scaling exists |
| 2 | step2_extract_scaling.py |
Extract scaling function tau(q) and estimate Hurst exponent H |
| 3 | step3_fit_spectrum.py |
Legendre transform to f(alpha), fit four theoretical distributions |
| 4 | step4_generate_cascade.py |
Multiplicative cascade to produce multifractal trading time |
| 5 | step5_generate_fbm.py |
Davies-Harte FBM generation with Cholesky fallback |
| 6 | step6_combine_model.py |
Compound process X(t) = B_H[theta(t)] via linear interpolation |
| 7 | step7_monte_carlo.py |
1,000 Monte Carlo simulations for volatility forecasting |
Each step produces serialized output consumed by subsequent steps, allowing any individual step to be re-run without repeating the entire pipeline.
Quick Start
Prerequisites
- Python 3.9+
- MetaTrader 5 terminal (for live data; CSV fallback available)
Installation
python -m venv .venv
.venv\Scripts\activate # Windows
pip install -r requirements.txt
Configuration
Edit config.py:
SYMBOL = "EURUSD"
TIMEFRAME_MT5 = "M5"
TIMEFRAME_MINUTES = 5
START_DATE = "2024-08-03"
END_DATE = "2026-03-01"
FORECAST_DAYS = 25
Running the Pipeline
python run_step1.py # Check fractality
python run_step2.py # Extract scaling function and Hurst exponent
python run_step3.py # Fit multifractal spectrum
python run_step4.py # Generate cascade / trading time
python run_step5.py # Generate FBM
python run_step6.py # Combine into MMAR process
python run_step7.py # Monte Carlo forecast
Comparison with GARCH
python run_garch_comparison.py # Head-to-head: MMAR vs GARCH(1,1)
python run_comparison.py # MMAR vs realized volatility
References
- Mandelbrot, B. B., Calvet, L., Fisher, A. (1997). "The Multifractal Model of Asset Returns." Cowles Foundation Discussion Paper No. 1164.
- Calvet, L., Fisher, A. (2002). "Multifractality in Asset Returns: Theory and Evidence." Review of Economics and Statistics, 84(3), 381-406.
- Zhang, Y. T. (2017). "Volatility Forecasting with the Multifractal Model of Asset Returns." University of Florida.
- Engle, R. F. (1982). "Autoregressive Conditional Heteroscedasticity with Estimates of the Variance of United Kingdom Inflation." Econometrica, 50(4), 987-1007.
- Bollerslev, T. (1986). "Generalized Autoregressive Conditional Heteroskedasticity." Journal of Econometrics, 31(3), 307-327.
License
This project is licensed under CC BY-NC 4.0. Free for academic and personal use. Commercial use requires permission. See LICENSE.md for details.
Disclaimer
This code implements academic research for educational purposes. It is not financial advice. Volatility forecasting carries inherent uncertainty. Always validate on out-of-sample data and test on demo accounts before risking live capital.