visualise_benchmark#

visualise_benchmark(name=None, portfolio_statistics=None, all_cash=None, buy_and_hold_asset_name=None, buy_and_hold_price_series=None, benchmark_indexes=None, additional_indicators=None, height=1200, start_at=None, end_at=None)[source]#

Visualise strategy performance against benchmarks.

  • Live or backtested strategies

  • Benchmark against buy and hold of various assets

  • Benchmark against hold all cash

Example:

from tradeexecutor.visual.benchmark import visualise_benchmark

TRADING_PAIRS = [
    (ChainId.avalanche, "trader-joe", "WAVAX", "USDC"), # Avax
    (ChainId.polygon, "quickswap", "WMATIC", "USDC"),  # Matic
    (ChainId.ethereum, "uniswap-v2", "WETH", "USDC"),  # Eth
    (ChainId.ethereum, "uniswap-v2", "WBTC", "USDC"),  # Btc
]

# Benchmark against all of our assets
benchmarks = pd.DataFrame()
for pair_description in TRADING_PAIRS:
    token_symbol = pair_description[2]
    pair = universe.get_pair_by_human_description(pair_description)
    benchmarks[token_symbol] = universe.universe.candles.get_candles_by_pair(pair.internal_id)["close"]

fig = visualise_benchmark(
    "Bollinger bands example strategy",
    portfolio_statistics=state.stats.portfolio,
    all_cash=state.portfolio.get_initial_deposit(),
    benchmark_indexes=benchmarks,
    start_at=START_AT,
    end_at=END_AT,
    height=800
)

fig.show()
Parameters:
  • portfolio_statistics (Optional[List[PortfolioStatistics]]) – Portfolio performance record.

  • all_cash (Optional[float]) – Set a linear line of just holding X amount

  • buy_and_hold_asset_name (Optional[str]) –

    Visualise holding all_cash amount in the asset, bought at the start. This is basically price * all_cash.

    Note

    This is a legacy argument. Use benchmark_indexes instead.

  • buy_and_hold_price_series (Optional[Series]) –

    Visualise holding all_cash amount in the asset, bought at the start. This is basically price * all_cash.

    Note

    This is a legacy argument. Use benchmark_indexes instead.

  • benchmark_indexes (Optional[DataFrame]) –

    List of other asset price series displayed on the timeline besides equity curve.

    DataFrame containing multiple series.

    Asset name is the series name.

  • height – Chart height in pixels

  • start_at (Optional[Union[Timestamp, datetime]]) – When the backtest started

  • end_at (Optional[Union[Timestamp, datetime]]) – When the backtest ended

  • additional_indicators (Optional[Collection[Plot]]) –

    Additional technical indicators drawn on this chart.

    List of indicator names.

    The indicators must be plotted earlier using state.visualisation.plot_indicator().

    Note: Currently not very useful due to Y axis scale

  • name (Optional[str]) –

Return type:

Figure