BacktestExecutionModel#
tradeexecutor.backtest.backtest_execution.BacktestExecutionModel Python class in Trading Strategy framework.
- class BacktestExecutionModel[source]#
Bases:
ExecutionModel
Simulate trades against historical data.
- __init__(wallet, max_slippage, lp_fees=0.003, stop_loss_data_available=False)[source]#
- Parameters:
wallet (SimulatedWallet) –
max_slippage (float) –
lp_fees (float) –
Methods
__init__
(wallet, max_slippage[, lp_fees, ...])execute_trades
(ts, state, trades, ...[, ...])Execute the trades on a simulated environment.
Get needed details to establish a routing state.
Set up the wallet
is_live_trading
()Do we support stop-loss/take profit functionality with this execution model?
Check that we can start the trade executor
repair_unconfirmed_trades
(state)Repair unconfirmed trades.
simulate_trade
(ts, state, idx, trade)Set backtesting trade state from planned to executed.
- __init__(wallet, max_slippage, lp_fees=0.003, stop_loss_data_available=False)[source]#
- Parameters:
wallet (SimulatedWallet) –
max_slippage (float) –
lp_fees (float) –
- is_stop_loss_supported()[source]#
Do we support stop-loss/take profit functionality with this execution model?
For backtesting we need to have data stream for candles used to calculate stop loss
For production execution, we need to have special oracle data streams for checking real-time stop loss
- preflight_check()[source]#
Check that we can start the trade executor
- Raise:
AssertionError if something is a miss
- simulate_trade(ts, state, idx, trade)[source]#
Set backtesting trade state from planned to executed.
Currently, always executes trades “perfectly” i.e. no different slipppage that was planned, etc.
- execute_trades(ts, state, trades, routing_model, routing_state, check_balances=False)[source]#
Execute the trades on a simulated environment.
Calculates price impact based on historical data and fills the expected historical trade output.
- Parameters:
check_balances – Raise an error if we run out of balance to perform buys in some point.
ts (datetime) –
state (State) –
trades (List[TradeExecution]) –
routing_model (BacktestRoutingModel) –
routing_state (BacktestRoutingState) –