IndicatorDefinition#
API documentation for tradeexecutor.strategy.pandas_trader.indicator.IndicatorDefinition Python class in Trading Strategy framework.
- class IndicatorDefinition[source]#
Bases:
object
A definition for a single indicator.
Indicator definitions are static - they do not change between the strategy runs
Used as id for the caching the indicator results
Definitions are used to calculate indicators for all trading pairs, or once over the whole trading universe
Indicators are calcualted independently from each other - a calculation cannot access cached values of other calculation
- __init__(name, func, parameters, source=IndicatorSource.close_price, dependency_order=1)#
Methods
__init__
(name, func, parameters[, source, ...])calculate_by_pair
(input, pair, resolver)Calculate the underlying indicator value.
calculate_by_pair_external
(pair, resolver)Calculate indicator for external data.
calculate_by_pair_ohlcv
(candles, pair, resolver)Calculate the underlying OHCLV indicator value.
calculate_universe
(input, resolver)Calculate the underlying indicator value.
Calculate the hash for the function code.
is_needed_for_pair
(pair)Currently indicators are calculated for spont pairs only.
is_per_pair
()Attributes
Name of this indicator.
The underlying method we use to
Parameters for building this indicator.
On what trading universe data this indicator is calculated
Dependency resolution order.
- name: str#
Name of this indicator.
Later in decide_trades() you use this name to access the indicator data.
- func: Optional[Callable]#
The underlying method we use to
Same function can part of multiple indicators with different parameters (length).
Because function pickling issues, this may be set to
None
in results.
- parameters: dict#
Parameters for building this indicator.
Each key is a function argument name for
func
.Each value is a single value
Grid search multiple parameter ranges are handled outside indicator definition
- source: IndicatorSource#
On what trading universe data this indicator is calculated
- dependency_order: int#
Dependency resolution order.
Indicators are calculated in order from the lowest order to the highest. The order parameter allows lightweight dependency resolution, where later indicators and read the earlier indicators data.
By default all indicators are on the same dependency resolution order layer 1 and cannot access data from other indicators. You need to create indicator with order == 2 to be able to access data from indicators where order == 1.
See
IndicatorDependencyResolver
for details and examples.
- get_function_body_hash()[source]#
Calculate the hash for the function code.
Allows us to detect if the function body changes.
- Return type:
- is_needed_for_pair(pair)[source]#
Currently indicators are calculated for spont pairs only.
- Parameters:
pair (TradingPairIdentifier) –
- Return type:
- calculate_by_pair_external(pair, resolver)[source]#
Calculate indicator for external data.
- Parameters:
pair (TradingPairIdentifier) – Trading pair we are calculating for.
resolver (IndicatorDependencyResolver) –
- Returns:
Single or multi series data.
Multi-value indicators return DataFrame with multiple columns (e.g. BB).
Single-value indicators return Series (e.g. RSI, SMA).
- Return type:
pandas.core.frame.DataFrame | pandas.core.series.Series
- calculate_by_pair(input, pair, resolver)[source]#
Calculate the underlying indicator value.
- Parameters:
input (Series) – Price series used as input.
pair (TradingPairIdentifier) –
resolver (IndicatorDependencyResolver) –
- Returns:
Single or multi series data.
Multi-value indicators return DataFrame with multiple columns (BB).
Single-value indicators return Series (RSI, SMA).
- Return type:
pandas.core.frame.DataFrame | pandas.core.series.Series
- calculate_by_pair_ohlcv(candles, pair, resolver)[source]#
Calculate the underlying OHCLV indicator value.
Assume function can take parameters: open, high, low, close, volume, or any combination of those.
- Parameters:
input – Raw OHCLV candles data.
candles (DataFrame) –
pair (TradingPairIdentifier) –
resolver (IndicatorDependencyResolver) –
- Returns:
Single or multi series data.
Multi-value indicators return DataFrame with multiple columns (BB).
Single-value indicators return Series (RSI, SMA).
- Return type:
pandas.core.frame.DataFrame | pandas.core.series.Series
- calculate_universe(input, resolver)[source]#
Calculate the underlying indicator value.
- Parameters:
input (TradingStrategyUniverse) – Price series used as input.
resolver (IndicatorDependencyResolver) –
- Returns:
Single or multi series data.
Multi-value indicators return DataFrame with multiple columns (BB).
Single-value indicators return Series (RSI, SMA).
- Return type:
pandas.core.frame.DataFrame | pandas.core.series.Series