visualise_equity_curve_benchmark#

API documentation for tradeexecutor.visual.benchmark.visualise_equity_curve_benchmark Python function.

visualise_equity_curve_benchmark(name=None, title=None, state=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, log_y=False)[source]#

Visualise strategy performance against benchmarks.

  • Live or backtested strategies

  • Benchmark against buy and hold of various assets

  • Benchmark against hold all cash

Note

This will be deprecated. Use visualise_equity_curves() instead.

Example for a single trading pair strategy:

from tradeexecutor.visual.benchmark import visualise_benchmark

traded_pair = universe.universe.pairs.get_single()

fig = visualise_benchmark(
    state.name,
    portfolio_statistics=state.stats.portfolio,
    all_cash=state.portfolio.get_initial_deposit(),
    buy_and_hold_asset_name=traded_pair.base_token_symbol,
    buy_and_hold_price_series=universe.universe.candles.get_single_pair_data()["close"],
    height=800
)

fig.show()

Example how to benchmark a strategy against buy-and-hold BTC and ETH:

from tradeexecutor.visual.benchmark import visualise_benchmark

# List of pair descriptions we used to look up pair metadata
our_pairs = [
    (ChainId.centralised_exchange, "binance", "BTC", "USDT"),
    (ChainId.centralised_exchange, "binance", "ETH", "USDT"),
]

btc_pair = strategy_universe.data_universe.pairs.get_pair_by_human_description(our_pairs[0])
eth_pair = strategy_universe.data_universe.pairs.get_pair_by_human_description(our_pairs[1])

benchmark_indexes = pd.DataFrame({
    "BTC": strategy_universe.data_universe.candles.get_candles_by_pair(btc_pair)["close"],
    "ETH": strategy_universe.data_universe.candles.get_candles_by_pair(eth_pair)["close"],
})
benchmark_indexes["BTC"].attrs = {"colour": "orange"}
benchmark_indexes["ETH"].attrs = {"colour": "blue"}

fig = visualise_benchmark(
    name=state.name,
    portfolio_statistics=state.stats.portfolio,
    all_cash=state.portfolio.get_initial_deposit(),
    benchmark_indexes=benchmark_indexes,
)

fig.show()

Another 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:
  • name (Optional[str]) – The name of the primary asset we benchark

  • title (Optional[str]) – The title of the chart if separate from primary asset

  • 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 (DataFrame) –

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

    DataFrame containing multiple series.

    • Asset name is the series name.

    • Setting colour for pd.Series.attrs allows you to override the colour of the index

  • 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 (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

  • log_y

    Use logarithmic Y-axis.

    Because we accumulate larger treasury over time, the swings in the value will be higher later. We need to use a logarithmic Y axis so that we can compare the performance early in the strateg and late in the strategy.

  • state (Optional[State]) –

Returns:

Plotly figure

Return type:

Figure