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 (Series) –
Returns series of the strategy.
See :py:`tradeeexecutor.visual.equity_curve.calculate_returns`.
mode (AdvancedMetricsMode) – Full or basic stats
periods_per_year –
How often the trade decision cycle was run.
This affects “trading periods per year” needed, to calculate metrics like Sharpe.
The defaults to the daily trading cycle, trading 24/7.
- Returns:
DataFrame of metrics generated by quantstats.
You can directly display this in your notebook, or extract individual metrics.
- Return type: