StrategyInput#

API documentation for tradeexecutor.strategy.pandas_trader.strategy_input.StrategyInput Python class in Trading Strategy framework.

class StrategyInput[source]#

Bases: object

Inputs for a trading decision.

The data structure used to make trade decisions. Captures all values that need to go to a single trade, under different live and backtesting circumstances.

  • Inputs for decide_trades function

  • Enabled when trading_strategy_engine_version = “0.5” or higher

__init__(cycle, timestamp, state, strategy_universe, parameters, indicators, pricing_model, execution_context, other_data)#
Parameters:
Return type:

None

Methods

__init__(cycle, timestamp, state, ...)

get_default_pair()

Get the default trading pair for this stragegy.

get_position_manager()

Create a position manager instance to open/close trading positions in this decision cycle.

is_visualisation_enabled()

Should we render any visualisation or not.

Attributes

cycle

Strategy cycle number

timestamp

Timestamp of this strategy cycle

state

The current state of a strategy

strategy_universe

The source trading universe for this strategy run

parameters

Parameters used for this backtest or live run

indicators

All indicators that are precalculated with create_indicators()

pricing_model

Asset pricing model.

execution_context

Information about whether this is live or backtest run.

other_data

Diagnostics and debug data

cycle: int#

Strategy cycle number

  • Deterministic for a backtest

  • May be reset for live execution

timestamp: Timestamp#

Timestamp of this strategy cycle

  • Timestamp can/should only access earlier data and cannot peek into the future

  • Always in UTC, no timezone

state: State#

The current state of a strategy

strategy_universe: TradingStrategyUniverse#

The source trading universe for this strategy run

parameters: StrategyParameters#

Parameters used for this backtest or live run

indicators: StrategyInputIndicators#

All indicators that are precalculated with create_indicators()

  • Indicators calculated in create_indicators function

  • Cached in backtesting for fast reader

  • In livee trading recalculated for every cycle

pricing_model: PricingModel#

Asset pricing model.

  • Used to determine the position size and value of trades

  • Backtesting uses historical pricing whereas live trading will read any data directly on-chain

  • Access using get_position_manager()

execution_context: ExecutionContext#

Information about whether this is live or backtest run.

other_data: dict#

Diagnostics and debug data

  • Undefined format

  • Mostly used in internal testing and logging

  • Is mutated in-place, but don’t rely on this to work for live strategies

get_position_manager()[source]#

Create a position manager instance to open/close trading positions in this decision cycle.

Return type:

PositionManager

get_default_pair()[source]#

Get the default trading pair for this stragegy.

  • Works only for single pair strateiges

Raises:

InvalidForMultipairStrategy – If called for a multi pair strategy

Return type:

TradingPairIdentifier

is_visualisation_enabled()[source]#

Should we render any visualisation or not.

  • Use this function inside decide_trades() to figure out if state.visualisation should be filled in

  • Disabled for grid seach to optimise grid search speed, as the visualisation results would be likely be discarded

Example:

def decide_trades(input: StrategyInput):

    # ...

    #
    # Visualisations
    #

    if input.is_visualisation_enabled():

        visualisation = state.visualisation  # Helper class to visualise strategy output

        visualisation.plot_indicator(
            timestamp,
            f"ETH",
            PlotKind.technical_indicator_detached,
            current_price[eth_pair],
            colour="blue",
        )

        # Draw BTC + ETH RSI between its trigger zones for this pair of we got a valid value for RSI for this pair

        # BTC RSI daily
        if pd.notna(current_rsi_values[btc_pair]):
            visualisation.plot_indicator(
                timestamp,
                f"RSI",
                PlotKind.technical_indicator_detached,
                current_rsi_values[btc_pair],
                colour="orange",
            )
Return type:

bool

__init__(cycle, timestamp, state, strategy_universe, parameters, indicators, pricing_model, execution_context, other_data)#
Parameters:
Return type:

None