BacktestSyncModel#
API documentation for tradeexecutor.backtest.backtest_sync.BacktestSyncModel Python class in Trading Strategy framework.
- class BacktestSyncModel[source]#
Bases:
SyncModel
Backtest sync model.
Simulate deposit events to the backtest wallet.
- __init__(wallet, initial_deposit_amount)[source]#
- Parameters:
wallet (SimulatedWallet) –
initial_deposit_amount (Decimal) –
Methods
__init__
(wallet, initial_deposit_amount)calculate_accrued_interest
(universe, ...)Calculate accrued interest of a position.
Backtesting does not need to care about how to build blockchain transactions.
get_hot_wallet
()Get the vault address we are using.
Get the address where tokens are stored.
get_vault_address
()Get the vault address we are using.
is_ready_for_live_trading
(state)Check that the state and sync model is ready for live trading.
resync_nonce
()Re-read hot wallet nonce before trade execution.
simulate_funding
(timestamp, amount)Simulate a funding flow event.
sync_credit_supply
(timestamp, state, ...)Update all credit supply positions.
sync_initial
(state)Set up the initial sync details.
sync_treasury
(strategy_cycle_ts, state[, ...])Apply the balance sync before each strategy cycle.
Attributes
Simulated deposit/redemption events pending to be processed
- __init__(wallet, initial_deposit_amount)[source]#
- Parameters:
wallet (SimulatedWallet) –
initial_deposit_amount (Decimal) –
- fund_flow_queue: List[FundFlowEvent]#
Simulated deposit/redemption events pending to be processed
- sync_initial(state)[source]#
Set up the initial sync details.
For backtesting these are irrelevant.
- Parameters:
state (State) –
- sync_treasury(strategy_cycle_ts, state, supported_reserves=None)[source]#
Apply the balance sync before each strategy cycle.
Warning
Old legacy code with wrong return signature compared to the parent class
- Parameters:
strategy_cycle_ts (datetime) –
state (State) –
supported_reserves (Optional[List[AssetIdentifier]]) –
- Return type:
- simulate_funding(timestamp, amount)[source]#
Simulate a funding flow event.
Call for the test to cause deposit or redemption for the backtest. The event goes to a queue and is processed in next tick() through sync_portfolio().
- create_transaction_builder()[source]#
Backtesting does not need to care about how to build blockchain transactions.
- Return type:
None
- calculate_accrued_interest(universe, position, timestamp)[source]#
Calculate accrued interest of a position.
- Parameters:
universe (TradingStrategyUniverse) –
position (TradingPosition) –
timestamp (datetime) –
- Return type:
- sync_credit_supply(timestamp, state, universe, credit_positions)[source]#
Update all credit supply positions.
- Parameters:
timestamp (datetime) –
Wall clock time.
This function can be called outside the strategy cycle.
state (State) – Current strategy state
universe (TradingStrategyUniverse) – Trading universe that must include lending data.
credit_positions (List[TradingPosition]) – Prefiltered list of credit positions to update.
- Returns:
All triggered balance update events
- Return type: