Skip to content

Class AbsolutePriceOscillator

  • Jump right in for a hands-on Open In Colab

Import

from NitroFE import AbsolutePriceOscillator

AbsolutePriceOscillator

The Absolute Price Oscillator displays the difference between two exponential moving averages

\[ Fast \ exponential \ moving \ feature \ (FEMF) = Exponential \ moving \ feature \ of \ 'fast\_period' \ span \]
\[ Slow \ exponential \ moving \ feature \ (SEMF) = Exponential \ moving \ feature \ of \ 'slow\_period' \ span \]
\[ Absolute \ Price \ Oscillator = SEMF - FEMF \]

Methods

Provided dataframe must be in ascending order.

__init__(self, fast_period=5, slow_period=2, fast_operation='mean', slow_operation='mean', initialize_using_operation=False, initialize_span=None, min_periods=0, ignore_na=False, axis=0, times=None) special

Parameters:

Name Type Description Default
fast_period int

specify decay in terms of span, for the fast moving feature , by default 10

5
slow_period int

specify decay in terms of span, for the slow moving feature, by default 20

2
fast_operation str

operation to be performed for the fast moving feature, by default 'mean'

'mean'
slow_operation str

operation to be performed for the slow moving feature, 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
ignore_na bool

Ignore missing values when calculating weights, 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\_absolutepriceoscillator.py
def __init__(
    self,
    fast_period: int = 5,
    slow_period: int = 2,
    fast_operation: str = "mean",
    slow_operation: str = "mean",
    initialize_using_operation: bool = False,
    initialize_span: int = None,
    min_periods: int = 0,
    ignore_na: bool = False,
    axis: int = 0,
    times: str = None,
):
    """

    Parameters
    ----------
    fast_period : int, optional
        specify decay in terms of span, for the fast moving feature , by default 10
    slow_period : int, optional
        specify decay in terms of span, for the slow moving feature, by default 20
    fast_operation : str, optional
        operation to be performed for the fast moving feature, by default 'mean'
    slow_operation : str, optional
        operation to be performed for the slow moving feature, 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
    ignore_na : bool, optional
        Ignore missing values when calculating weights, 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.span_fast = fast_period
    self.span_slow = slow_period

    self.min_periods = min_periods

    self.ignore_na = ignore_na
    self.axis = axis
    self.times = times
    self.fast_operation = fast_operation
    self.slow_operation = slow_operation

    self.initialize_using_operation = initialize_using_operation
    self.initialize_span = initialize_span

fit(self, dataframe, first_fit=True)

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\_absolutepriceoscillator.py
def fit(self, dataframe: Union[pd.DataFrame, pd.Series], first_fit: bool = True):
    """
    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._fast_em_object = ExponentialMovingFeature(
            span=self.span_fast,
            initialize_using_operation=self.initialize_using_operation,
            initialize_span=self.initialize_span,
            ignore_na=self.ignore_na,
            axis=self.axis,
            times=self.times,
            operation=self.fast_operation,
        )
        self._slow_em_object = ExponentialMovingFeature(
            span=self.span_slow,
            initialize_using_operation=self.initialize_using_operation,
            initialize_span=self.initialize_span,
            ignore_na=self.ignore_na,
            axis=self.axis,
            times=self.times,
            operation=self.fast_operation,
        )

    fast_em = self._fast_em_object.fit(dataframe=dataframe, first_fit=first_fit)
    slow_em = self._slow_em_object.fit(dataframe=dataframe, first_fit=first_fit)

    absolute_price_oscillator = slow_em - fast_em
    return absolute_price_oscillator

References