Class ZeroLagExponentialMovingFeature
Import
from NitroFE import ZeroLagExponentialMovingFeature
The zero lag exponential moving average (ZLEMA) indicator was created by John Ehlers and Ric Way
As is the case with the double exponential moving average (DEMA) and the triple exponential moving average (TEMA) and as indicated by the name, the aim is to eliminate the inherent lag associated to all trend following indicators which average a price over time.
Methods
__init__(self, lag_period=5, alpha=None, operation='mean', initialize_using_operation=False, initialize_span=None, com=None, span=None, halflife=None, min_periods=0, ignore_na=False, axis=0, times=None)
special
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lag_period |
int |
lag peiod for feature calculation |
5 |
alpha |
float |
Specify smoothing factor directly, by default None |
None |
operation |
str |
operation to be performed for the moving feature,available operations are 'mean','var','std', by default 'mean' |
'mean' |
initialize_using_operation |
bool |
If True, then specified 'operation' is performed on the first 'initialize_span' values, and then the exponential moving average is calculated, by default False |
False |
initialize_span |
int |
the span over which 'operation' would be performed for initialization, by default None |
None |
com |
float |
Specify decay in terms of center of mass, by default None |
None |
span |
float |
pecify decay in terms of span , by default None |
None |
halflife |
float |
Specify decay in terms of half-life, by default None |
None |
min_periods |
int |
Minimum number of observations in window required to have a value (otherwise result is NA)., by default 0 |
0 |
ignore_na |
bool |
Ignore missing values when calculating weights; specify True to reproduce pre-0.15.0 behavior, by default False |
False |
axis |
int |
The axis to use. The value 0 identifies the rows, and 1 identifies the columns, by default 0 |
0 |
times |
str |
Times corresponding to the observations. Must be monotonically increasing and datetime64[ns] dtype, by default None |
None |
Source code in nitrofe\time_based_features\indicator_features\_zerolagexponentialmovingfeature.py
def __init__(
self,
lag_period: int = 5,
alpha: float = None,
operation: str = "mean",
initialize_using_operation: bool = False,
initialize_span: int = None,
com: float = None,
span: float = None,
halflife: float = None,
min_periods: int = 0,
ignore_na: bool = False,
axis: int = 0,
times: str = None,
):
"""
Parameters
----------
lag_period : int ,optional
lag peiod for feature calculation
alpha : float, optional
Specify smoothing factor directly, by default None
operation : str, {'mean','var','std'}
operation to be performed for the moving feature,available operations are 'mean','var','std', by default 'mean'
initialize_using_operation : bool, optional
If True, then specified 'operation' is performed on the first 'initialize_span' values, and then the exponential moving average is calculated, by default False
initialize_span : int, optional
the span over which 'operation' would be performed for initialization, by default None
com : float, optional
Specify decay in terms of center of mass, by default None
span : float, optional
pecify decay in terms of span , by default None
halflife : float, optional
Specify decay in terms of half-life, by default None
min_periods : int, optional
Minimum number of observations in window required to have a value (otherwise result is NA)., by default 0
ignore_na : bool, optional
Ignore missing values when calculating weights; specify True to reproduce pre-0.15.0 behavior, by default False
axis : int, optional
The axis to use. The value 0 identifies the rows, and 1 identifies the columns, by default 0
times : str, optional
Times corresponding to the observations. Must be monotonically increasing and datetime64[ns] dtype, by default None
"""
self.com = com
self.lag_period = lag_period
self.span = span
self.halflife = halflife
self.alpha = alpha
self.min_periods = min_periods
self.ignore_na = ignore_na
self.axis = axis
self.times = times
self.operation = operation
self.initialize_using_operation = initialize_using_operation
self.initialize_span = initialize_span
fit(self, dataframe, first_fit=True)
Provided dataframe must be in ascending order.
For your training/initial fit phase (very first fit) use fit_first=True, and for any production/test implementation pass fit_first=False
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataframe |
Union[pandas.core.frame.DataFrame, pandas.core.series.Series] |
dataframe containing column values to create feature over |
required |
first_fit |
bool |
Indicator features require past values for calculation. Use True, when calculating for training data (very first fit) Use False, when calculating for subsequent testing/production data { in which case the values, which were saved during the last phase, will be utilized for calculation }, by default True |
True |
Source code in nitrofe\time_based_features\indicator_features\_zerolagexponentialmovingfeature.py
def fit(
self,
dataframe: Union[pd.DataFrame, pd.Series],
first_fit: bool = True,
):
"""
Provided dataframe must be in ascending order.
For your training/initial fit phase (very first fit) use fit_first=True, and for any production/test implementation pass fit_first=False
Parameters
----------
dataframe : Union[pd.DataFrame, pd.Series]
dataframe containing column values to create feature over
first_fit : bool, optional
Indicator features require past values for calculation.
Use True, when calculating for training data (very first fit)
Use False, when calculating for subsequent testing/production data { in which case the values, which
were saved during the last phase, will be utilized for calculation }, by default True
"""
if first_fit:
self._zlema_object = ExponentialMovingFeature(
com=self.com,
operation=self.operation,
span=self.span,
halflife=self.halflife,
alpha=self.alpha,
initialize_using_operation=self.initialize_using_operation,
initialize_span=self.initialize_span,
min_periods=self.min_periods,
ignore_na=self.ignore_na,
axis=self.axis,
times=self.times,
)
self._lag_object = weighted_window_features()
res = self._lag_object._template_feature_calculation(
function_name="_lag_object",
win_function=_identity_window,
first_fit=first_fit,
dataframe=dataframe,
window=int((self.lag_period - 1) / 2),
min_periods=None,
symmetric=None,
operation=self._sub_lag,
operation_args=(),
)
res = self._zlema_object.fit(
dataframe=res,
first_fit=first_fit,
)
return res
References
- wikipedia, "Zero lag exponential moving average", https://en.wikipedia.org/wiki/Zero_lag_exponential_moving_average