Build Custom Indicators Using the Base Indicator Class¶
Base Indicator Class for deriving your own indicators
to use within an analysis_engine.indicators.in
dicator_processor.IndicatorProcessor
-
class
analysis_engine.indicators.base_indicator.
BaseIndicator
(config_dict, path_to_module=None, name=None, verbose=False)[source]¶ -
build_base_configurables
(ind_type='momentum', category='technical', uses_data='minute', version=1)[source]¶ Parameters: - ind_type – string indicator type
- category – string indicator category
- uses_data – string indicator usess this type of data
- version – integer for building configurables for the testing generation version
-
build_configurable_node
(name, conf_type, current_value=None, default_value=None, max_value=None, min_value=None, is_output_only=False, inc_interval=None, notes=None, **kwargs)[source]¶ Helper for building a single configurable type node for programmatically creating algo configs
Parameters: - name – name of the member configurable
- conf_type – string - configurable type
- current_value – optional - current value
- default_value – optional - default value
- max_value – optional - maximum value
- min_value – optional - minimum value
- is_output_only – optional - bool for setting
the input parameter as an output-only value
(default is
False
) - inc_interval – optional - float value
for controlling how the tests should increment
while walking between the
min_value
and themax_value
- notes – optional - string notes
- kwargs – optional - derived keyword args dictionary
-
convert_config_keys_to_members
()[source]¶ This converts any key in the config to a member variable that can be used with the your derived indicators like:
self.<KEY_IN_CONFIG>
-
get_configurables
(**kwargs)[source]¶ Derive this in your indicators
This is used as a helper for setting up algorithm configs for this indicator and to programmatically set the values based off the domain rules
Parameters: kwargs – optional keyword args
-
get_dataset_by_name
(dataset, dataset_name)[source]¶ Method for getting just a dataset by the dataset_name`` inside the cached
dataset['data']
dictionary ofpd.Dataframe(s)
Parameters: - dataset – cached dataset value
that holds the dictionaries:
dataset['data']
- dataset_name – optional - name of the
supported
pd.DataFrame
that is in the cacheddataset['data']
dictionary of dataframes
- dataset – cached dataset value
that holds the dictionaries:
-
get_report
(verbose=False)[source]¶ Get the indicator’s current output node that is used for the trading performance report generated at the end of the algorithm
Note
the report dict should mostly be numeric types to enable AI predictions after removing non-numeric columns
Parameters: verbose – optional - boolean for toggling to show the report
-
get_subscribed_dataset
(dataset, dataset_name=None)[source]¶ Method for getting just the subscribed dataset else use the
dataset_name
argument datasetParameters: - dataset – cached dataset value
that holds the dictionaries:
dataset['data']
- dataset_name – optional - name of the
supported
pd.DataFrame
that is in the cacheddataset['data']
dictionary of dataframes
- dataset – cached dataset value
that holds the dictionaries:
-
handle_subscribed_dataset
(algo_id, ticker, dataset)[source]¶ Filter the algorithm’s
dataset
to just the dataset the indicator is set up to use as defined by the member variable:self.name_of_df
- string value likedaily
,minute
Parameters: - algo_id – string - algo identifier label for debugging datasets during specific dates
- ticker – string - ticker
- dataset – dictionary of
pd.DataFrame(s)
to process
-
lg
(msg, level=20)[source]¶ Log only if the indicator has
self.verbose
set toTrue
or if thelevel == logging.CRITICAL
orlevel = logging.ERROR
otherwise no logsParameters: - msg – string message to log
- level – set the logging level
(default is
logging.INFO
)
-
process
(algo_id, ticker, dataset)[source]¶ Derive custom indicator processing to determine buy and sell conditions before placing orders. Just implement your own
process
method.Please refer to the TA Lib guides for details on building indicators:
- Overlap Studies https://mrjbq7.github.io/ta-lib/func_groups/overlap_studies.html
- Momentum Indicators https://mrjbq7.github.io/ta-lib/func_groups/momentum_indicators.html
- Volume Indicators https://mrjbq7.github.io/ta-lib/func_groups/volume_indicators.html
- Volatility Indicators https://mrjbq7.github.io/ta-lib/func_groups/volatility_indicators.html
- Price Transform https://mrjbq7.github.io/ta-lib/func_groups/price_transform.html
- Cycle Indicators https://mrjbq7.github.io/ta-lib/func_groups/cycle_indicators.html
- Pattern Recognition https://mrjbq7.github.io/ta-lib/func_groups/pattern_recognition.html
- Statistic Functions https://mrjbq7.github.io/ta-lib/func_groups/statistic_functions.html
- Math Transform https://mrjbq7.github.io/ta-lib/func_groups/math_transform.html
- Math Operators https://mrjbq7.github.io/ta-lib/func_groups/math_operators.html
Parameters: - algo_id – string - algo identifier label for debugging datasets during specific dates
- ticker – string - ticker
- dataset – dictionary of
pd.DataFrame(s)
to process
-