Strategy Validation Through Historical Simulation -- Test Before You Trade
Trading Backtest Optimizer 是一套交易策略回測與驗證框架,將歷史模擬、績效評估與參數探索整合為可重複的研究流程。適合量化交易者在進入實盤前做策略篩選與風險檢視,也可作為回測工程實作的參考。
Trading Backtest Optimizer is a strategy validation framework that combines historical simulation, performance analytics, and parameter search. It helps quantitative traders evaluate robustness before deploying to live markets.
📈 Trading Backtest Optimizer 是一套完整的交易策略回測與驗證框架,解決量化交易者最痛的問題:策略在紙上漂亮,實戰卻虧錢。💹 系統整合 Binance 與 dYdX 雙交易所數據源,支援從 2020 到 2025 年的歷史數據回測。🔄 核心功能包含 Walk-Forward 前進式最佳化、網格搜索參數調優、六維度評分系統(OBI 訂單簿失衡、資金流向、時機分析等)、零手續費模擬、以及 24 小時即時模擬交易分析。🤖 機器學習層整合 XGBoost、LightGBM、Optuna 超參數優化、SHAP 可解釋性分析與 Prophet 時間序列預測。🛠️ 技術棧涵蓋 Python + pandas + TA-Lib 技術分析 + FastAPI 即時 API + Celery 任務佇列 + Prometheus 監控。📊 已累積數百份回測結果檔案,適合嚴肅看待策略驗證的量化交易者與研究人員。
Every trading strategy looks brilliant on paper. The question is whether it survives contact with real market data. Most traders skip rigorous backtesting because the tooling is fragmented: you need one tool to fetch data, another to run simulations, another to analyze results, and another to optimize parameters. By the time the pipeline is assembled, the market has moved.
Trading Backtest Optimizer provides a unified framework for the full validation cycle. Fetch historical data from Binance and dYdX. Run walk-forward optimizations across multi-year windows. Analyze real paper trading sessions with six-dimensional scoring (OBI, order flow, timing). Compare strategies with zero-fee simulations. Validate everything against real exchange data before committing capital.
The system has been battle-tested with extensive backtesting runs spanning 2020-2025, producing hundreds of result files across grid search optimizations, walk-forward analyses, and real-time 24-hour trading simulations.
+-------------------------------------------------------------------+
| Trading Backtest Optimizer |
+-------------------------------------------------------------------+
| |
| Data Sources Analysis Tools Output |
| +----------------+ +------------------+ +--------------+ |
| | Binance API |------->| analyze_trades |->| JSON Results | |
| | (python-binance| | _with_binance.py | | | |
| | + ccxt) | +------------------+ | Markdown | |
| +----------------+ | Reports | |
| | dYdX Indexer |------->+------------------+ | | |
| | (v4 REST API) | | analyze_dydx | | Walk-Forward | |
| +----------------+ | _real.py | | Reports | |
| +------------------+ +--------------+ |
| Strategy Engine |
| +-------------------------------------------------------------+ |
| | Hybrid Paper Trading System | |
| | - Multi-strategy execution - Real-time signal generation | |
| | - Six-dimensional scoring - Order book imbalance (OBI) | |
| | - Walk-forward optimization - Grid search parameter tuning | |
| +-------------------------------------------------------------+ |
| |
| ML / Optimization |
| +-------------------------------------------------------------+ |
| | XGBoost | LightGBM | Optuna | SHAP | Prophet | Statsmodels | |
| +-------------------------------------------------------------+ |
+-------------------------------------------------------------------+
| Script | Purpose |
|---|---|
analyze_dydx_real.py |
Connects to dYdX mainnet, fetches real fill data, computes paired trade PnL, daily statistics, and win rates |
analyze_paper_trades_24h.py |
Comprehensive 24h paper trading analysis with six-dimensional scoring, OBI metrics, and order flow data |
analyze_trades_with_binance.py |
Cross-references trade executions against Binance market data for price accuracy validation |
analyze_recent_sessions.py |
Aggregates and compares multiple recent trading sessions |
analyze_zero_fee.py |
Simulates strategy performance under zero-fee conditions to isolate edge from fee impact |
run_trading_test.py |
Launches the hybrid paper trading system for controlled test runs |
test_multi_bot.py |
Multi-bot concurrent execution testing |
test_ai_integration.sh |
End-to-end AI integration validation |
The backtest_results/ directory contains validated output from production runs:
- Walk-forward optimizations (2020-2025 full period)
- Grid search parameter optimization
- Dynamic optimization with rolling windows
- Real funding rate analysis
- HFT and hybrid strategy variants
- Scalping strategy walk-forward optimization
- Real-time 24h simulation snapshots
| Layer | Technology |
|---|---|
| Language | Python 3 |
| Exchange APIs | python-binance, ccxt, aiohttp (dYdX v4) |
| Data Processing | pandas, NumPy, SciPy, PyArrow |
| Technical Analysis | TA-Lib |
| Machine Learning | XGBoost, LightGBM, scikit-learn |
| Hyperparameter Optimization | Optuna |
| Explainability | SHAP |
| Time Series | Prophet, statsmodels |
| Visualization | Plotly, Matplotlib, Seaborn |
| Web API | FastAPI, uvicorn, WebSockets |
| Task Queue | Celery + Flower |
| Monitoring | Prometheus client |
| Testing | pytest, pytest-cov, pytest-asyncio |
| Code Quality | Black, Flake8, mypy, pre-commit |
# Clone the repo
git clone <repo-url>
cd trading-backtest-optimizer
# Create virtual environment and install
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Configure API keys
cp .env.example .env
# Fill in: Binance API keys, dYdX address
# Analyze dYdX real trades
python analyze_dydx_real.py --address dydx1... --limit 500
# Analyze paper trading session
python analyze_paper_trades_24h.py
# Run a short paper trading test (0.05 hours = 3 minutes)
python run_trading_test.py 0.05Huang Akai (Kai) -- Founder @ Universal FAW Labs | Creative Technologist | Ex-Ogilvy | 15+ years in digital creative and marketing technology.