feed.api.float.window package

Submodules

feed.api.float.window.ewm module

ewm.py contains functions and classes for exponential weighted moving stream operations.

class feed.api.float.window.ewm.EWM(com: float = None, span: float = None, halflife: float = None, alpha: float = None, min_periods: int = 0, adjust: bool = True, ignore_na: bool = False)[source]

Bases: feed.core.base.Stream

Provide exponential weighted (EW) functions.

Exactly one parameter: com, span, halflife, or alpha must be provided.

Parameters:
  • com (float, optional) – Specify decay in terms of center of mass, \(\alpha = 1 / (1 + com)\), for \(com \geq 0\).
  • span (float, optional) – Specify decay in terms of span, \(\alpha = 2 / (span + 1)\), for \(span \geq 1\).
  • halflife (float, str, timedelta, optional) – Specify decay in terms of half-life, \(\alpha = 1 - \exp\left(-\ln(2) / halflife\right)\), for \(halflife > 0\). If times is specified, the time unit (str or timedelta) over which an observation decays to half its value. Only applicable to mean() and halflife value will not apply to the other functions.
  • alpha (float, optional) – Specify smoothing factor \(\alpha\) directly, \(0 < \alpha \leq 1\).
  • min_periods (int, default 0) – Minimum number of observations in window required to have a value (otherwise result is NA).
  • adjust (bool, default True) –

    Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings (viewing EWMA as a moving average). - When adjust=True (default), the EW function is calculated using weights

    \(w_i = (1 - \alpha)^i\). For example, the EW moving average of the series [\(x_0, x_1, ..., x_t\)] would be:
    \[y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... + (1 - \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t}\]
    • When adjust=False, the exponentially weighted function is calculated recursively:
    \[\begin{split}\begin{split} y_0 &= x_0\\ y_t &= (1 - \alpha) y_{t-1} + \alpha x_t, \end{split}\end{split}\]
  • ignore_na (bool, default False) – Ignore missing values when calculating weights. - When ignore_na=False (default), weights are based on absolute positions. - When ignore_na=True, weights are based on relative positions.

See also

References

[1]https://github.com/pandas-dev/pandas/blob/d9fff2792bf16178d4e450fe7384244e50635733/pandas/core/window/ewm.py#L65
forward() → Tuple[List[float], List[float]][source]

Generates the next value from the underlying data streams.

Returns:The next value in the stream.
Return type:T
has_next() → bool[source]

Checks if there is another value.

Returns:If there is another value or not.
Return type:bool
mean() → feed.core.base.Stream[float][float][source]

Computes the exponential weighted moving average.

Returns:The exponential weighted moving average stream based on the underlying stream of values.
Return type:Stream[float]
reset() → None[source]

Resets all the listeners of the stream.

std(bias=False) → feed.core.base.Stream[float][float][source]

Computes the exponential weighted moving standard deviation.

Returns:The exponential weighted moving standard deviation stream based on the underlying stream of values.
Return type:Stream[float]
var(bias=False) → feed.core.base.Stream[float][float][source]

Computes the exponential weighted moving variance.

Returns:The exponential weighted moving variance stream based on the underlying stream of values.
Return type:Stream[float]
class feed.api.float.window.ewm.ExponentialWeightedMovingAverage(alpha: float, adjust: bool, ignore_na: bool, min_periods: int)[source]

Bases: feed.core.base.Stream

A stream operator that computes an exponential weighted moving average on a given float stream.

Parameters:
  • alpha (float) – The smoothing factor \(\alpha\) directly, \(0 < \alpha \leq 1\).
  • adjust (bool) – Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings (viewing EWMA as a moving average).
  • ignore_na (bool) – Ignore missing values when calculating weights.
  • min_periods (int) – Minimum number of observations in window required to have a value (otherwise result is NA).

References

[1]https://github.com/pandas-dev/pandas/blob/d9fff2792bf16178d4e450fe7384244e50635733/pandas/_libs/window/aggregations.pyx#L1801
forward() → float[source]

Generates the next value from the underlying data streams.

Returns:The next value in the stream.
Return type:T
has_next() → bool[source]

Checks if there is another value.

Returns:If there is another value or not.
Return type:bool
reset() → None[source]

Resets all the listeners of the stream.

class feed.api.float.window.ewm.ExponentialWeightedMovingCovariance(alpha: float, adjust: bool, ignore_na: bool, min_periods: int, bias: bool)[source]

Bases: feed.core.base.Stream

A stream operator that computes an exponential weighted moving average on a given float stream.

Parameters:
  • alpha (float) – The smoothing factor \(\alpha\) directly, \(0 < \alpha \leq 1\).
  • adjust (bool) – Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings (viewing EWMA as a moving average).
  • ignore_na (bool) – Ignore missing values when calculating weights.
  • min_periods (int) – Minimum number of observations in window required to have a value (otherwise result is NA).
  • bias (bool) – Use a standard estimation bias correction
forward() → float[source]

Generates the next value from the underlying data streams.

Returns:The next value in the stream.
Return type:T
has_next() → bool[source]

Checks if there is another value.

Returns:If there is another value or not.
Return type:bool
reset() → None[source]

Resets all the listeners of the stream.

feed.api.float.window.ewm.ewm(s: feed.core.base.Stream[float][float], com: float = None, span: float = None, halflife: float = None, alpha: float = None, min_periods: int = 0, adjust: bool = True, ignore_na: bool = False) → feed.core.base.Stream[typing.Tuple[typing.List[float], typing.List[float]]][Tuple[List[float], List[float]]][source]

Computes the weights and values in order to perform an exponential weighted moving operation.

Parameters:
  • s (Stream[float]) – A float stream.
  • com (float, optional) – Specify decay in terms of center of mass, \(\alpha = 1 / (1 + com)\), for \(com \geq 0\).
  • span (float, optional) – Specify decay in terms of span, \(\alpha = 2 / (span + 1)\), for \(span \geq 1\).
  • halflife (float, optional) – Specify decay in terms of half-life, \(\alpha = 1 - \exp\left(-\ln(2) / halflife\right)\), for \(halflife > 0\).
  • alpha (float, optional) – Specify smoothing factor \(\alpha\) directly, \(0 < \alpha \leq 1\).
  • min_periods (int, default 0) – Minimum number of observations in window required to have a value (otherwise result is NA).
  • adjust (bool, default True) – Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings (viewing EWMA as a moving average).
  • ignore_na (bool, default False) – Ignore missing values when calculating weights.
Returns:

A stream of weights and values to be used for computation of exponential weighted moving operations.

Return type:

Stream[Tuple[List[float], List[float]]]

feed.api.float.window.expanding module

expanding.py contains functions and classes for expanding stream operations.

class feed.api.float.window.expanding.Expanding(min_periods: int = 1)[source]

Bases: feed.core.base.Stream

A stream that generates the entire history of a stream at each time step.

Parameters:min_periods (int, default 1) – The number of periods to wait before producing values from the aggregation function.
agg(func: Callable[[List[float]], float]) → feed.core.base.Stream[float][float][source]

Computes an aggregation of a stream’s history.

Parameters:func (Callable[[List[float]], float]) – A aggregation function.
Returns:A stream producing aggregations of the stream history at each time step.
Return type:Stream[float]
count() → feed.core.base.Stream[float][float][source]

Computes an expanding count fo the underlying stream.

Returns:An expanding count stream.
Return type:Stream[float]
forward() → List[float][source]

Generates the next value from the underlying data streams.

Returns:The next value in the stream.
Return type:T
generic_name = 'expanding'
has_next() → bool[source]

Checks if there is another value.

Returns:If there is another value or not.
Return type:bool
max() → feed.core.base.Stream[float][float][source]

Computes an expanding maximum fo the underlying stream.

Returns:An expanding maximum stream.
Return type:Stream[float]
mean() → feed.core.base.Stream[float][float][source]

Computes an expanding mean fo the underlying stream.

Returns:An expanding mean stream.
Return type:Stream[float]
median() → feed.core.base.Stream[float][float][source]

Computes an expanding median fo the underlying stream.

Returns:An expanding median stream.
Return type:Stream[float]
min() → feed.core.base.Stream[float][float][source]

Computes an expanding minimum fo the underlying stream.

Returns:An expanding minimum stream.
Return type:Stream[float]
reset() → None[source]

Resets all the listeners of the stream.

std() → feed.core.base.Stream[float][float][source]

Computes an expanding standard deviation fo the underlying stream.

Returns:An expanding standard deviation stream.
Return type:Stream[float]
sum() → feed.core.base.Stream[float][float][source]

Computes an expanding sum fo the underlying stream.

Returns:An expanding sum stream.
Return type:Stream[float]
var() → feed.core.base.Stream[float][float][source]

Computes an expanding variance fo the underlying stream.

Returns:An expanding variance stream.
Return type:Stream[float]
class feed.api.float.window.expanding.ExpandingCount[source]

Bases: feed.api.float.window.expanding.ExpandingNode

A stream operator that counts the number of non-missing values.

forward() → float[source]

Generates the next value from the underlying data streams.

Returns:The next value in the stream.
Return type:T
class feed.api.float.window.expanding.ExpandingNode(func: Callable[[List[float]], float])[source]

Bases: feed.core.base.Stream

A stream operator for aggregating an entire history of a stream.

Parameters:func (Callable[[List[float]], float]) – A function that aggregates the history of a stream.
forward() → float[source]

Generates the next value from the underlying data streams.

Returns:The next value in the stream.
Return type:T
has_next()[source]

Checks if there is another value.

Returns:If there is another value or not.
Return type:bool
feed.api.float.window.expanding.expanding(s: feed.core.base.Stream[float][float], min_periods: int = 1) → feed.core.base.Stream[typing.List[float]][List[float]][source]

Computes a stream that generates the entire history of a stream at each time step.

Parameters:
  • s (Stream[float]) – A float stream.
  • min_periods (int, default 1) – The number of periods to wait before producing values from the aggregation function.

feed.api.float.window.rolling module

rolling.py contains functions and classes for rolling stream operations.

class feed.api.float.window.rolling.Rolling(window: int, min_periods: int = 1)[source]

Bases: feed.core.base.Stream

A stream that generates a rolling window of values from a stream.

Parameters:
  • window (int) – The size of the rolling window.
  • min_periods (int, default 1) – The number of periods to wait before producing values from the aggregation function.
agg(func: Callable[[List[float]], float]) → feed.core.base.Stream[float][float][source]

Computes an aggregation of a rolling window of values.

Parameters:func (Callable[[List[float]], float]) – A aggregation function.
Returns:A stream producing aggregations of a rolling window of values.
Return type:Stream[float]
count() → feed.core.base.Stream[float][float][source]

Computes a rolling count from the underlying stream.

Returns:A rolling count stream.
Return type:Stream[float]
forward() → List[float][source]

Generates the next value from the underlying data streams.

Returns:The next value in the stream.
Return type:T
generic_name = 'rolling'
has_next() → bool[source]

Checks if there is another value.

Returns:If there is another value or not.
Return type:bool
max() → feed.core.base.Stream[float][float][source]

Computes a rolling maximum from the underlying stream.

Returns:A rolling maximum stream.
Return type:Stream[float]
mean() → feed.core.base.Stream[float][float][source]

Computes a rolling mean from the underlying stream.

Returns:A rolling mean stream.
Return type:Stream[float]
median() → feed.core.base.Stream[float][float][source]

Computes a rolling median from the underlying stream.

Returns:A rolling median stream.
Return type:Stream[float]
min() → feed.core.base.Stream[float][float][source]

Computes a rolling minimum from the underlying stream.

Returns:A rolling minimum stream.
Return type:Stream[float]
reset() → None[source]

Resets all the listeners of the stream.

std() → feed.core.base.Stream[float][float][source]

Computes a rolling standard deviation from the underlying stream.

Returns:A rolling standard deviation stream.
Return type:Stream[float]
sum() → feed.core.base.Stream[float][float][source]

Computes a rolling sum from the underlying stream.

Returns:A rolling sum stream.
Return type:Stream[float]
var() → feed.core.base.Stream[float][float][source]

Computes a rolling variance from the underlying stream.

Returns:A rolling variance stream.
Return type:Stream[float]
class feed.api.float.window.rolling.RollingCount[source]

Bases: feed.api.float.window.rolling.RollingNode

A stream operator that counts the number of non-missing values in the rolling window.

forward()[source]

Generates the next value from the underlying data streams.

Returns:The next value in the stream.
Return type:T
class feed.api.float.window.rolling.RollingNode(func: Callable[[List[float]], float])[source]

Bases: feed.core.base.Stream

A stream operator for aggregating a rolling window of a stream.

Parameters:func (Callable[[List[float]], float]) – A function that aggregates a rolling window.
forward() → float[source]

Generates the next value from the underlying data streams.

Returns:The next value in the stream.
Return type:T
has_next() → bool[source]

Checks if there is another value.

Returns:If there is another value or not.
Return type:bool
reset() → None[source]

Resets all the listeners of the stream.

feed.api.float.window.rolling.rolling(s: feed.core.base.Stream[float][float], window: int, min_periods: int = 1) → feed.core.base.Stream[typing.List[float]][List[float]][source]

Creates a stream that generates a rolling window of values from a stream.

Parameters:
  • s (Stream[float]) – A float stream.
  • window (int) – The size of the rolling window.
  • min_periods (int, default 1) – The number of periods to wait before producing values from the aggregation function.

Module contents