IndicatorSet#
API documentation for tradeexecutor.strategy.pandas_trader.indicator.IndicatorSet Python class in Trading Strategy framework.
- class IndicatorSet[source]#
Bases:
objectDefine the indicators that are needed by a trading strategy.
For backtesting, indicators are precalculated
For live trading, these indicators are recalculated for the each decision cycle
Indicators are calculated for each given trading pair, unless specified otherwise, and a separate
IndicatorKeyis generated bygenerate_combinations()Indicators that have multiple instances of itself with different parameters in the same backtest are called variations - mainly useful for strategies where parameters are rollingly adjusted.
See
CreateIndicatorsProtocolV2for usage.- __init__(indicators=<factory>, variation_cache=<factory>, variation_lookup=<factory>)#
- Parameters:
indicators (dict[str, tradeexecutor.strategy.pandas_trader.indicator.IndicatorDefinition]) –
variation_lookup (dict[int, tradeexecutor.strategy.pandas_trader.indicator.IndicatorDefinition]) –
- Return type:
None
Methods
__init__([indicators, variation_cache, ...])add(name, func[, parameters, source, order, ...])Add a new indicator to this indicator set.
from_indicator_keys(indicator_keys)Reconstruct the original indicator set from keys.
generate_combinations(strategy_universe)Create all individual indicator (per pair) we need to calculate for this trading universe.
How many indicators we have
get_indicator(name)Get a named indicator definition.
get_indicator_by_name_and_parameters(name, ...)Get a variation indicator definition.
get_label()get_variations(name)Get all parameter variations for an indicator.
has_indicator(name)is_varying_indicator(name)iterate()make_parameter_key(name, parameters)Attributes
indicatorsvariation_cachevariation_lookup- get_indicator(name)[source]#
Get a named indicator definition.
- Parameters:
name (str) –
- Return type:
tradeexecutor.strategy.pandas_trader.indicator.IndicatorDefinition | None
- get_indicator_by_name_and_parameters(name, parameters)[source]#
Get a variation indicator definition.
- Parameters:
- Return type:
tradeexecutor.strategy.pandas_trader.indicator.IndicatorDefinition | None
- add(name, func, parameters=None, source=IndicatorSource.close_price, order=1, variations=False)[source]#
Add a new indicator to this indicator set.
Builds an indicator set for the trading strategy, called from create_indicators.
See
CreateIndicatorsProtocolfor usage.- Parameters:
name (str) –
Name of the indicator.
Human-readable name. If the same function is calculated multiple times, e.g. EMA, you can have names like ema_short and ema_long.
func (Callable) –
Python function to be called.
Function takes arguments from parameters dict. It must return either
pd.DataFrameorpd.Series.parameters (dict | None) –
Parameters to be passed to the Python function.
Raw func Python arguments.
You can pass parameters as is from StrategyParameters.
source (IndicatorSource) –
Data source on this indicator is calculated.
Defaults to the close price for each trading pair. To calculate universal indicators set to
IndicatorSource.strategy_universe.order –
Dependency resolution order.
See
tradingstrategy.strategy.pandas_trader.indicator.IndicatorKey.orderparameter.variations –
Set for rolling indicators that need to have their values calculated with several combinations for a backtest run.
You can add the same variation multiple times and the sequent adds are ignored.
- generate_combinations(strategy_universe)[source]#
Create all individual indicator (per pair) we need to calculate for this trading universe.
Because most indicators are per pair, we need to combine the trading pair universe with wanted indicators to get the final set of indicators we need to calcuate
Note that some indicator are calculated over the whole universe or an external source and may not have a trading pair defined
- Returns:
IndicatorKey iterator.
(Trading pair, indicator) iterator
- Parameters:
strategy_universe (TradingStrategyUniverse) –
- Return type:
- static from_indicator_keys(indicator_keys)[source]#
Reconstruct the original indicator set from keys.
Used when grid search passes data around processes
- Parameters:
indicator_keys (set[tradeexecutor.strategy.pandas_trader.indicator.IndicatorKey]) –
- Return type:
- __init__(indicators=<factory>, variation_cache=<factory>, variation_lookup=<factory>)#
- Parameters:
indicators (dict[str, tradeexecutor.strategy.pandas_trader.indicator.IndicatorDefinition]) –
variation_lookup (dict[int, tradeexecutor.strategy.pandas_trader.indicator.IndicatorDefinition]) –
- Return type:
None