Performance Analytics
The system provides a comprehensive performance analytics suite to evaluate trading strategies against historical data. These metrics are calculated server-side during the backtesting process and are accessible via the Dashboard UI, the REST API, or the CLI-based trade viewer.
Core Performance Metrics
The performance engine tracks several key indicators to help differentiate between raw profitability and risk-adjusted performance.
Sharpe Ratio
The Sharpe Ratio measures the risk-adjusted return of the strategy. It is calculated by taking the average excess return of the portfolio over the risk-free rate and dividing it by the standard deviation of those returns.
- Interpretation: A higher Sharpe Ratio (typically > 1.0) indicates that the strategy's returns are not merely a result of high volatility or excessive risk-taking.
- Calculation Scope: Calculated based on the daily returns of the total portfolio value throughout the backtest period.
Maximum Drawdown (Max DD)
Max Drawdown represents the largest peak-to-trough decline in the portfolio's equity curve, expressed as a percentage.
- Logic: It identifies the highest point the portfolio reached and calculates the percentage loss to the lowest point before a new peak was achieved.
- Significance: This is a critical metric for understanding the "worst-case scenario" and the potential psychological stress of running the strategy.
Alpha vs. Hold
This metric compares the strategy's total return against a benchmark "Buy and Hold" strategy for the same asset (typically Bitcoin) over the same timeframe.
- Formula:
Strategy Return (%) - Benchmark Return (%) - Interpretation: A positive Alpha indicates that the Multi-Agent system outperformed a passive investment in the underlying asset.
Win Rate
The Win Rate is the percentage of closed trades that resulted in a positive return.
- Formula:
(Profitable Trades / Total Closed Trades) * 100 - Usage: While a high win rate is desirable, it is analyzed in conjunction with the Profit Factor (the ratio of gross profits to gross losses) to ensure that a few large losses do not outweigh many small wins.
Accessing Analytics Data
Performance data is stored in the local database after every backtest and can be retrieved through multiple interfaces.
Dashboard API
The FastAPI backend exposes structured performance metrics through the /api/backtests/{backtest_id} endpoint.
Schema: MetricsResponse
{
"total_return_pct": 15.5,
"sharpe_ratio": 1.25,
"max_drawdown_pct": -8.2,
"win_rate": 62.5,
"total_trades": 24,
"profit_factor": 1.8,
"alpha_vs_hold": 5.3
}
CLI Trade Viewer
For a quick inspection of trade-level performance without launching the web dashboard, use the view_trades.py utility. This script parses the most recent backtest report and prints a detailed log of entry/exit prices and the resulting P/L for each trade.
# View the most recent backtest report
python view_trades.py
# View a specific report file
python view_trades.py logs/backtest_report_20231027.json
Example Output:
======================================================================
TRADE LOG
======================================================================
# 1 | 2023-10-01 | BUY @ $42,500
# 2 | 2023-10-05 | SELL @ $44,200 | P/L: +4.00%
# 3 | 2023-10-10 | BUY @ $43,800
# 4 | 2023-10-12 | SELL @ $43,100 | P/L: -1.60%
======================================================================
Equity Curve Data
The system generates a full equity curve for every backtest, mapping the portfolio value and the underlying asset price at every timestamp. This data is used by the frontend to render the interactive performance charts, allowing users to visualize where the strategy's "Alpha" was generated relative to market movements.