backtrader.reports.performance module

Performance metrics calculator.

Extracts and calculates all performance metrics from strategies and analyzers.

class backtrader.reports.performance.PerformanceCalculator[源代码]

基类:object

Unified performance metrics calculator.

Extracts and calculates all performance metrics from strategies and analyzers, including: - PnL metrics: total return, annual return, cumulative return - Risk metrics: max drawdown, Sharpe ratio, SQN, Calmar ratio - Trade statistics: win rate, profit/loss ratio, average profit/loss

strategy

Strategy instance

Usage example:

calc = PerformanceCalculator(strategy) metrics = calc.get_all_metrics() print(f"Sharpe ratio: {metrics['sharpe_ratio']}") print(f"SQN rating: {metrics['sqn_human']}")

__init__(strategy)[源代码]

Initialize the performance calculator.

参数:

strategy -- backtrader strategy instance (result from run())

get_all_metrics()[源代码]

Return dictionary of all performance metrics.

返回:

Dictionary containing all performance metrics

返回类型:

dict

get_pnl_metrics()[源代码]

Get profit and loss related metrics.

返回:

PnL metrics dictionary

返回类型:

dict

get_risk_metrics()[源代码]

Get risk-related metrics.

返回:

Risk metrics dictionary

返回类型:

dict

get_trade_metrics()[源代码]

Get trade statistics metrics.

返回:

Trade statistics dictionary

返回类型:

dict

get_kpi_metrics()[源代码]

Get key performance indicators.

返回:

KPI metrics dictionary

返回类型:

dict

get_equity_curve()[源代码]

Get equity curve data.

返回:

(dates, values) Lists of dates and equity values

返回类型:

tuple

get_buynhold_curve()[源代码]

Get buy-and-hold comparison curve.

返回:

(dates, values) Lists of dates and buy-and-hold values

返回类型:

tuple

static sqn_to_rating(sqn_score)[源代码]

Convert SQN score to human-readable rating.

Reference: http://www.vantharp.com/tharp-concepts/sqn.asp

参数:

sqn_score -- SQN score

返回:

Human-readable rating

返回类型:

str

get_strategy_info()[源代码]

Get strategy information.

返回:

Strategy information dictionary

返回类型:

dict

get_data_info()[源代码]

Get data information.

返回:

Data information dictionary

返回类型:

dict