run_backtest_inline#

API documentation for tradeexecutor.backtest.backtest_runner.run_backtest_inline Python function.

run_backtest_inline(*ignore, start_at=None, end_at=None, minimum_data_lookback_range=None, client, decide_trades, cycle_duration, initial_deposit, reserve_currency=None, trade_routing=None, create_trading_universe=None, universe=None, routing_model=None, max_slippage=0.01, candle_time_frame=None, log_level=30, data_preload=True, data_delay_tolerance=None, name='backtest', allow_missing_fees=False, engine_version=None, strategy_logging=False, parameters=None)[source]#

Run backtests for given decide_trades and create_trading_universe functions.

Does not load strategy from a separate .py file. Useful for running strategies directly from notebooks.

Parameters:
  • name (str) – Name for this backtest. If not set default to “backtest”.

  • start_at (Optional[datetime]) –

    When backtesting starts.

    If not given take the date of the first candle.

  • end_at (Optional[datetime]) –

    When backtesting ends.

    If not given take the date of the last candle.

  • minimum_data_lookback_range (Optional[timedelta]) – If start_at and end_at are not given, use this range to determine the backtesting period. Cannot be used with start_at and end_at. Automatically ends at the current time.

  • client (Optional[Client]) – You need to set up a Trading Strategy client for fetching the data

  • decide_trades (tradeexecutor.strategy.strategy_module.DecideTradesProtocol | tradeexecutor.strategy.strategy_module.DecideTradesProtocol2 | tradeexecutor.strategy.strategy_module.DecideTradesProtocol3) – Trade decider function of your strategy

  • create_trading_universe (Optional[CreateTradingUniverseProtocol]) – Universe creation function of your strategy. You must give either create_trading_universe or universe.

  • universe (Optional[TradingStrategyUniverse]) – The pregenerated universe for this backtest. You must give either create_trading_universe or universe.

  • cycle_duration (CycleDuration) – Strategy cycle duration

  • candle_time_frame (Optional[TimeBucket]) – Candles we use for this strategy

  • initial_deposit (float) – how much reserve currency we allocate as a capital at the beginning of the backtest

  • reserve_currency (Optional[ReserveCurrency]) – Reserve currency used for the strategy

  • trade_routing (Optional[TradeRouting]) – Routing model for trades

  • routing_model (Optional[BacktestRoutingModel]) – Use a predefined routing model.

  • max_slippage – Max slippage tolerance for trades before execution failure

  • log_level – Python logging level to display log messages during the backtest run.

  • data_preload – Before the backtesting begins, load and cache datasets with nice progress bar to the user.

  • data_delay_tolerance (Optional[Timedelta]) –

    What is the maximum hours/days lookup we allow in the backtesting when we ask for the latest price of an asset.

    The asset price fetch might fail due to sparse candle data - trades have not been made or the blockchain was halted during the price look-up period. Because there are no trades we cannot determine what was the correct asset price using {data_delay_tolerance} data tolerance delay.

    The default value None tries to guess the value based on the univerity candle timeframe, but often this guess is incorrect as only analysing every pair data gives a correct answer.

    The workarounds include ignoring assets in your backtest that might not have price data (look up they have enough valid candles at the decide_trades timestamp) or simply increasing this parameter.

    This parameter is passed to tradeexecutor.backtest.backtest_pricing.BacktestSimplePricingModel.

  • allow_missing_fees

    Allow synthetic data to lack fee information.

    Only set in legacy backtests.

  • engine_version (Optional[str]) –

    The used TS engine version/

    See tradeexecutor.strategy.engine_version.

  • strategy_logging

    Enable PositionManager log output.

    See tradeexecutor.strategy.pandas_trading.position_manager.PositionManager.log() for usage.

  • parameters (Optional[StrategyParameters]) –

Returns:

tuple (State of a completely executed strategy, trading strategy universe, debug dump dict)

Return type:

Tuple[State, TradingStrategyUniverse, dict]