A comprehensive system for automated backtesting, real-time analysis, and market trend forecasting (Monte Carlo & Meta Prophet) for Commodities, Stocks, and Forex.
- Install Dependencies:
pip install -r requirements.txt - Launch Dashboard:
streamlit run dashboard.py - Terminal Analysis:
python trading_backtest.py --analyze Gold --interval 1h
The script performs a historical backtest of a combined technical strategy on 15+ assets. The system automatically fetches OHLCV data, calculates indicators, and generates signals based on a voting consensus (at least 3 out of 5 indicators must agree).
Different markets require different approaches. The algorithm utilizes Dynamic Profiles:
- COMMODITY: Wider bands, slower averages (Gold, Oil).
- TECH: Aggressive settings for high-beta stocks (NVDA, AMD).
- DEFENSIVE: Conservative stop-losses for dividend stocks (KO, Moneta).
- FOREX_IDX: Tight bands for low-volatility currency moves (USD Index).
The strategy is built on 5 pillars:
- EMA Crossover (20/50): Trend detection.
- RSI (14): Momentum strength.
- Bollinger Bands: Statistical price volatility.
- MACD: Trend convergence/divergence.
- ATR: Dynamic risk management (Stop-Loss).
No indicator acts alone.
- BUY Signal: Requires a score of ≥ 3/5 (e.g., Rising EMA + RSI < 50 + Bullish MACD).
- Risk Management: Automatic Stop-Loss calculated as
2.0 * ATR.
The system provides professional metrics for objective evaluation:
- Alpha: Excess return over the "Buy & Hold" benchmark.
- Sharpe Ratio: Risk-adjusted return.
- Max Drawdown: Peak-to-trough capital decline.
- Profit Factor: Ratio of gross profits to gross losses.
This section supplements core signals with market conviction data:
- ROC (Rate of Change): Price velocity.
- OBV Divergence: Key institutional accumulation/distribution indicator.
- Candle Body Ratio: Strength of current price action.
Two advanced forecasting methods are integrated:
- Monte Carlo (1000+ Simulations): Probability fans (Random Walk, GARCH for Crypto, Mean Reversion for Commodities).
- Meta Prophet: A robust statistical model capturing seasonality and trend shifts.
--analyze [Asset]: In-depth technical analysis for a single ticker.--signals-hourly: Market-wide signal overview (1h/4h intervals).- Default Mode: Full historical portfolio backtest.
The interactive web UI features:
- Signal Overview: Real-time buy zones and target levels.
- Asset Detail: Interactive Plotly charts & Volume profiles.
- Backtest Summary: Equity curve visualizations and multi-asset comparisons.
This software is for educational purposes only. Trading financial markets involves significant risk. Past performance does not guarantee future results.