Strategy Properties

Inside your strategy you can also get a lot of information about the state of the strategy and set specific variables to determine how the strategy works. Here is a list of those properties that you can use:

Strategy.cash

Returns the current cash.

Strategy.portfolio_value

Returns the last portfolio value (cash + positions value) reported by the broker.

Strategy.positions

Strategy.first_iteration

Returns True if this is the first iteration of the strategy (is True if the lifecycle method on_trading_iteration is being excuted for the first time).

Strategy.is_backtesting

Boolean flag indicating whether the strategy is running in backtesting mode.

Strategy.quote_asset

Returns the quote asset for the strategy.

Strategy.name

Returns the name of the strategy.

Strategy.initial_budget

Returns the strategy's starting value.

Strategy.minutes_before_closing

Get or set the number of minutes that the strategy will stop executing before market closes.

Strategy.minutes_after_closing

Get or set the number of minutes that the strategy will continue executing after market closes.

Strategy.minutes_before_opening

Get or set the number of minutes that the strategy will start executing before the market opens.

Strategy.sleeptime

Get or set the current sleep time for the strategy.

Strategy.last_on_trading_iteration_datetime

Returns the datetime of the last iteration.

Strategy.timezone

Returns the timezone of the data source.

Strategy.pytz

Returns the pytz object of the data source.

Strategy.unspent_money

Deprecated, will be removed in the future.

Strategy.backtesting_start

Strategy.backtesting_end

Strategy.stats

Strategy.stats_file

Strategy.analysis

Strategy.risk_free_rate

Strategy.budget_conversion

Caller-supplied backtest capital conversion and its provenance, or None.

Live speed settings

Set these as class attributes on your strategy.

  • wake_iteration_on_fill (default False): in live trading, run the next trading iteration at once after an order fills instead of waiting out sleeptime. Only a fill that arrives while no iteration is running wakes it; a fill during a running iteration does not, and the next iteration starts after sleeptime as usual. Leave it off if the strategy places an order in every iteration.

  • wake_iteration_on_partial_fill (default False): also wake on partial fills.

Quote and option chain reuse is set with environment variables, see Environment Variables. See Charles Schwab API Trading Bot in Python (LumiBot) (section “Fewer requests for scanners”).