|
1 | 1 | # Backtest Results & Metrics |
2 | 2 |
|
3 | | -This document details the performance metrics in AKQuant backtest results (`metrics_df`), including their meanings, units, and calculation methods. |
| 3 | +This document details the performance metrics in AKQuant backtest results (`metrics_df`), including their meanings, units, and calculation methods. It also covers the visualization capabilities for analyzing these results. |
| 4 | + |
| 5 | +## Visualization (Plotting) |
| 6 | + |
| 7 | +AKQuant provides a comprehensive visualization module to analyze backtest results. You can generate professional-grade interactive HTML reports or individual plots directly from the `BacktestResult` object. |
| 8 | + |
| 9 | +### Quick Start |
| 10 | + |
| 11 | +The easiest way to visualize your backtest results is using the `report()` method: |
| 12 | + |
| 13 | +```python |
| 14 | +# Generate a full HTML report |
| 15 | +result.report( |
| 16 | + title="My Strategy Report", |
| 17 | + filename="report.html", |
| 18 | + show=True # Set to True to open in browser automatically (default is False) |
| 19 | +) |
| 20 | +``` |
| 21 | + |
| 22 | +This generates a consolidated dashboard including: |
| 23 | +- **Equity Curve**: Interactive chart of account equity over time. |
| 24 | +- **Drawdown**: Historical drawdown analysis. |
| 25 | +- **Monthly Heatmap**: Monthly return performance grid. |
| 26 | +- **Key Metrics**: A summary of important performance statistics. |
| 27 | + |
| 28 | +### Intraday Support (New) |
| 29 | + |
| 30 | +The plotting module automatically detects and adapts to intraday (minute-level) backtests: |
| 31 | +- **Smart Downsampling**: For large datasets (>10k points), it switches to WebGL rendering (`Scattergl`) for high performance. |
| 32 | +- **Adaptive X-Axis**: Automatically formats time labels (e.g., `%Y-%m-%d %H:%M`) and prevents label overlap. |
| 33 | +- **Adaptive Duration Units**: Trade duration analysis automatically switches units (Days, Hours, or Minutes) based on the strategy's average holding period. |
| 34 | + |
| 35 | +### Advanced Plotting |
| 36 | + |
| 37 | +You can also access individual plotting functions for more granular control: |
| 38 | + |
| 39 | +```python |
| 40 | +import akquant.plot as aqp |
| 41 | + |
| 42 | +# 1. Plot Dashboard (Equity, Drawdown, Heatmap) |
| 43 | +aqp.plot_dashboard(result) |
| 44 | + |
| 45 | +# 2. Analyze Trade Distribution (PnL vs Duration) |
| 46 | +aqp.plot_trades_distribution(result.trades_df) |
| 47 | + |
| 48 | +# 3. Analyze PnL vs Duration |
| 49 | +aqp.plot_pnl_vs_duration(result.trades_df) |
| 50 | +``` |
4 | 51 |
|
5 | 52 | ## Metrics Overview |
6 | 53 |
|
|
0 commit comments