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.
Read on-chain simulated wallet and reflect its balances back to the state
- __init__(wallet, initial_deposit_amount=None)[source]#
- Parameters:
wallet (SimulatedWallet) –
initial_deposit_amount (decimal.Decimal | None) –
Methods
__init__
(wallet[, initial_deposit_amount])Calculate accrued interest of a position since last update.
Backtesting does not need to care about how to build blockchain transactions.
fetch_onchain_balances
(assets[, ...])Read the on-chain asset details.
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.
reset_deposits
(state)Clear out pending withdrawals/deposits events.
resync_nonce
()Re-read hot wallet nonce before trade execution.
simulate_funding
(timestamp, amount)Simulate a funding flow event.
sync_initial
(state)Set up the initial sync details.
sync_interests
(timestamp, state, universe, ...)Update interest on all tokens that receive interest thru rebase.
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=None)[source]#
- Parameters:
wallet (SimulatedWallet) –
initial_deposit_amount (decimal.Decimal | None) –
- fund_flow_queue: List[FundFlowEvent]#
Simulated deposit/redemption events pending to be processed
Legacy code path.
- 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, end_block=None)[source]#
Apply the balance sync before each strategy cycle.
Warning
Old legacy code with wrong return signature compared to the parent class
- Parameters:
- 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(strategy_universe, asset, start, end)[source]#
Calculate accrued interest of a position since last update.
- Parameters:
strategy_universe (TradingStrategyUniverse) –
asset (AssetIdentifier) –
start (datetime) –
end (datetime) –
- Return type:
- sync_interests(timestamp, state, universe, pricing_model)[source]#
Update interest on all tokens that receive interest thru rebase.
Credit supply positions: aToken
Short positions: aToken, vToken
- 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.
pricing_model (PricingModel) – Used to re-value loans
- Returns:
All triggered balance update events, one per asset per position
- Return type:
- fetch_onchain_balances(assets, filter_zero=True, block_identifier=None)[source]#
Read the on-chain asset details.
Mark the block we are reading at the start
Asset list is sorted to be by address to make sure the return order is deterministic
- Parameters:
filter_zero – Do not return zero balances
block_identifier (Union[Literal['latest', 'earliest', 'pending', 'safe', 'finalized'], ~eth_typing.evm.BlockNumber, ~eth_typing.evm.Hash32, ~eth_typing.encoding.HexStr, ~hexbytes.main.HexBytes, int]) – Cbeck at certain block height.
assets (Collection[AssetIdentifier]) –
- Returns:
Iterator for assets by the sort order.
- Return type: