visualise_advanced_metrics#

API documentation for tradeexecutor.analysis.advanced_metrics.visualise_advanced_metrics Python function.

visualise_advanced_metrics(returns, mode=AdvancedMetricsMode.basic, benchmark=None, name=None, convert_to_daily=False)[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 visualise_advanced_metrics

equity = calculate_equity_curve(state)
returns = calculate_returns(equity)
df = visualise_advanced_metrics(returns)
display(df)

Example with benchmarking against buy and hold ETH:

from tradeexecutor.visual.equity_curve import calculate_equity_curve, calculate_returns, generate_buy_and_hold_returns
from tradeexecutor.analysis.advanced_metrics import visualise_advanced_metrics, AdvancedMetricsMode

equity = calculate_equity_curve(state)
returns = calculate_returns(equity)
benchmark_returns = generate_buy_and_hold_returns(benchmark_indexes["ETH"])
benchmark_returns.attrs["name"] = "Buy and hold ETH"

metrics = visualise_advanced_metrics(
    returns,
    mode=AdvancedMetricsMode.full,
    benchmark=benchmark_returns,
)

display(metrics)

When dealing with 1h or 8h data:

from tradeexecutor.analysis.advanced_metrics import visualise_advanced_metrics

visualise_advanced_metrics(
    best_result.returns,
    benchmark=benchmark_indexes["ETH"],
    convert_to_daily=True,
)

See also calculate_advanced_metrics().

Parameters:
  • returns (Series) –

    Returns series of the strategy.

    See :py:`tradeeexecutor.visual.equity_curve.calculate_returns`.

  • mode (AdvancedMetricsMode) – Full or basic stats

  • benchmark (pandas.core.series.Series | None) –

    Benchmark portfolio or buy and hold asset.

    If this series as series.attrs[“name”] name set, it is used as a title instead of “Benchmark”.

  • name (str | None) – Title oif the primary performance series instead of “Strategy”.

  • convert_to_daily – QuantStats metrics can only work on daily data, so force convert from 1h or 8h or so if needed.

Returns:

A DataFrame ready to display a table of comparable merics.

Return empty DataFrame if returns is all zeroes.

Return type:

DataFrame