Strategy
on_update() and trade through self.
on_update() runs once per pulse, after the clock has advanced and before the broker
fills that pulse’s orders. The collaborators it reaches for (datafeed, resolver,
broker, portfolio, pulse_index) are attached by the TradingEnvironment when
the run starts, which is why they are not constructor arguments.
Initialize the Strategy with its underlying id(s), a name and a description.
Parameters
Strategy.id
property
Strategy.underlying_id
property
Strategy.pulse_index
property
Strategy.last_pulse
property
Strategy.open_trades
property
Strategy.has_open_trades
property
Strategy.trades
property
Strategy.broker
property
Strategy.portfolio
property
Strategy.current_equity
property
Strategy.initial_equity
property
Strategy.pnl
property
current_equity - initial_equity. Includes the impact of fees
(because both terms are post-fee).
Strategy.pnl_pct
property
pnl / abs(current_equity). The denominator is the current
portfolio equity, so this is the live, sizing-aware return of the whole
strategy. Same basis as TradesSummary.pnl_pct; differs from
Trade.pnl_pct, which is fixed to each trade’s equity-at-open
snapshot. abs keeps the sign coming from pnl. Returns 0.0 if
current_equity is 0.
Strategy.pnl_pct_of_initial_equity
property
pnl / abs(initial_equity). Stable denominator across the entire
run, mirroring Trade.pnl_pct_of_initial_equity and
TradesSummary.pnl_pct_of_initial_equity. Returns 0.0 if
initial_equity is 0.
Strategy.datafeed
property
Strategy.resolver
property
Strategy.stats
property
Strategy.set_datafeed
Strategy.set_resolver
Strategy.set_broker
Strategy.set_portfolio
Strategy.set_pulse_index
Strategy.on_update
Strategy.pulse
Strategy.create_order
Strategy.buy
Strategy.sell
Strategy.close_all
Strategy.calculate_stats
Returns
Strategy.get_trades_by_tags
Returns
Strategy.close_trades_by_tags
Strategy.calculate_trades_summary
TradesSummary, marked at the current pulse.
Parameters
Returns
Raises
Strategy.get_trades_summary_by_tags
Returns
to_underlying_ids
UnderlyingIDs, in the order given.
A plain str gains the default declaration; an already declared id keeps its
variable_contract_size. A single UnderlyingID is itself a str, which is why the
isinstance branch treats it as one id rather than as a sequence of characters.
