calculate_advanced_metrics#

calculate_advanced_metrics(returns, mode=AdvancedMetricsMode.basic, periods_per_year=365)[source]#

Calculate advanced strategy performance statistics using Quantstats.

Calculates multiple metrics used to benchmark strategies for risk-adjusted returns in one go.

See Quantstats for more information.

Example:

from tradeexecutor.visual.equity_curve import calculate_equity_curve, calculate_returns
from tradeexecutor.analysis.advanced_metrics import calculate_advanced_metrics

equity = calculate_equity_curve(state)
returns = calculate_returns(equity)
metrics = calculate_advanced_metrics(returns)

# Each metric as a series. Index 0 is our performance,
# index 1 is the benchmark.
sharpe = metrics.loc["Sharpe"][0]
assert sharpe == pytest.approx(-1.73)

See also visualise_advanced_metrics().

Parameters:
Returns:

DataFrame of metrics generated by quantstats.

You can directly display this in your notebook, or extract individual metrics.

Return type:

DataFrame