trading.optimizer.analysis.metrics
trading.optimizer.analysis.metrics
DrawdownMetrics
Bases: NamedTuple
The drawdown metrics for a backtest. Holds the worst possible risk and volatility of a strategy.
Attributes:
| Name | Type | Description |
|---|---|---|
max_drawdown |
percent | None
|
The worst single historical loss of the strategy. |
average_drawdown |
percent | None
|
The average of historical losses of the strategy. |
Metrics
Bases: NamedTuple
The metrics of a single backtest, used to identify the effectiveness of a strategy.
Attributes:
| Name | Type | Description |
|---|---|---|
returns |
ReturnMetrics
|
The return (cash, units) metrics for the strategy. |
risk |
RiskMetrics
|
The risk (reliability) metrics for the strategy. |
drawdowns |
DrawdownMetrics
|
The drawdown (losses) metrics for the strategy. |
trades |
TradeMetrics
|
The number of trades made, losses, wins, profits, etc. |
__repr__
__repr__() -> str
Returns a string representation of the metrics.
Source code in src\contango\trading\optimizer\analysis\metrics.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
ReturnMetrics
Bases: NamedTuple
The resulting returns from the backtest. Holds the actual returned property and value from a strategy over time.
Attributes:
| Name | Type | Description |
|---|---|---|
total_return |
percent | None
|
The percent returned from the backtest at the end of execution. |
monthly_returns |
tuple[tuple[time_unix_ms, percent], ...] | None
|
A sequence of the total returns per month of the strategy. |
equity_curve |
tuple[tuple[time_unix_ms, USD], ...]
|
The account value over time (total value of cash + units). |
RiskMetrics
Bases: NamedTuple
The risk factor metrics from a backtest. Determines how reliable a strategy was over the backtest.
Attributes:
| Name | Type | Description |
|---|---|---|
annual_return |
percent | None
|
The CAGR (annualized compound return) for the backtest. |
monthly_volatility |
percent | None
|
Measure of how intensely returns move per month. |
sharpe_ratio |
float | None
|
Measure of how much excess return received per unit of risk taken (annaul). |
calmar_ratio |
float | None
|
Measure of much return an investment has generated relative to its worst possible loss. |
TradeMetrics
Bases: NamedTuple
The basic trading metrics for a backtest. Holds the actual number of trades made, wins, losses, and profits.
Attrubtes
trade_count: The total number of trades the strategy made during the backtest. win_rate: The percent of trades that the strategy was profitable. profit_factor: The gross profit from winning trades to gross losses from losing trades. expectancy: The expected profit per trade with the strategy. average_win: The average percent made per win. average_loss: The average percent lost per loss. average_holding_period: The average amount of time that the strategy holds a trade for.