turtle_quant_1.trading.engine¶
turtle_quant_1.trading.engine
¶
Trading engine for executing trading signals.
TradingEngine
¶
TradingEngine(
strategy_engine: BaseStrategyEngine,
portfolio: Portfolio,
max_lookback_days: int,
tick_interval: CandleUnit = "4H",
event_interval: CandleUnit = "30M",
)
Trading engine that processes ticks and executes trading signals.
Nomenclature:
- Signal: A single trading signal that is independent of time.
- Tick: A single trigger of the trading engine, typically defined by when the
host environment gets spooled up and triggered.
- Event: A single candle at the interval of CANDLE_UNIT. This will be at a smaller
interval than a tick, i.e. between every tick, multiple events will have passed.
- "curr..." variables: The variable refers to the latest value at the time of the
tick, not at the event.
Initialise the trading engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy_engine
|
BaseStrategyEngine
|
The strategy engine used to generate signals. |
required |
portfolio
|
Portfolio
|
The portfolio to trade against. |
required |
max_lookback_days
|
int
|
Days of history fed to the strategy on each tick. |
required |
tick_interval
|
CandleUnit
|
Duration of one tick window as a candle-unit string (e.g. "4H"). Used together with CANDLE_UNIT to determine how many candle events are replayed per tick. |
'4H'
|
event_interval
|
CandleUnit
|
Duration of one event window as a candle-unit string (e.g. "1H"). Used together with CANDLE_UNIT to determine how many candle events are replayed per event. |
'30M'
|
Source code in src/turtle_quant_1/trading/engine.py
handle_tick
¶
Process a tick for symbol by replaying every event in the tick window.
Rather than acting on the latest candle alone, iterates over every candle within the most recent tick window of curr_data, simulating an event-driven system where each arriving candle is assessed individually. The window size is determined by tick_interval set at construction time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Symbol being processed. |
required |
curr_data
|
DataFrame
|
All candles available up to the current tick timestamp. |
required |