filter

class timeseries.filter.window._RollingWindow(tseries, window_size, weights='even', **kwargs)[source]

Bases: object

Rolling window class for applying filters to time series.

_apply_filter(window_func, **kwargs)[source]

Apply filter and return time series.

Parameters
  • window_func – windowed function to apply. Current options: ‘average’ - weighted moving average over window size

  • **kwargs – keyword arguments passed to window function

custom(func)[source]

Apply custom function to weighted values in rolling window and return time series.

Parameters

func – custom function to apply in rolling windows

sum()[source]

Sum weighted values in rolling window and return time series.

exponential_custom(func, alpha)[source]

Apply custom exponentially smoothed function and return time series.

Parameters
  • func – function to apply to series

  • alpha – smoothing factor, must be between 0 and 1

exponential_moving_average(alpha)[source]

Sum weighted values in rolling window and return time series.

Parameters

alpha – smoothing factor, must be between 0 and 1

class timeseries.filter.weights.Weights(*args, **kwargs)[source]

Bases: abc.ABC

Abstract class for applying weights in rolling window.

class timeseries.filter.weights.EvenWeights(*args, **kwargs)[source]

Bases: timeseries.filter.weights.Weights

Even (uniform) weights for rolling window.

Example

>>> from timeseries.filter.weights import EvenWeights
>>> EvenWeights().get_weights(4)
[0.25, 0.25, 0.25, 0.25]
>>> EvenWeights().get_weights(5)
[0.2, 0.2, 0.2, 0.2, 0.2]
class timeseries.filter.weights.LinearWeights(min_weight)[source]

Bases: timeseries.filter.weights.Weights

Linearly increasing weights for rolling window.

Example

>>> from timeseries.filter.weights import LinearWeights
>>> LinearWeights(min_weight=0.1).get_weights(2)
[0.1, 0.9]
>>> LinearWeights(min_weight=0.1).get_weights(4)
[0.1, 0.2, 0.3, 0.4]
class timeseries.filter.weights.NoneWeights(*args, **kwargs)[source]

Bases: timeseries.filter.weights.Weights

None-weights (all ones) for rolling window.

Example

>>> from timeseries.filter.weights import NoneWeights
>>> NoneWeights().get_weights(5)
[1, 1, 1, 1, 1]
class timeseries.filter.func.WindowFunction[source]

Bases: abc.ABC

Abstract class for applying function in window.

class timeseries.filter.func.SeriesFunction[source]

Bases: abc.ABC

Abstract class for applying function to series.

class timeseries.filter.func.CustomWindowFunction(func)[source]

Bases: timeseries.filter.func.WindowFunction

Apply custom function in window.

Parameters

func – function to apply in window

apply_to_window(values)[source]

Return result of function applied in window.

Parameters

values – values to apply function to

class timeseries.filter.func.SumWindow[source]

Bases: timeseries.filter.func.CustomWindowFunction

Sum over values in window.

class timeseries.filter.func.CustomExponentialSeriesFunction(func, alpha)[source]

Bases: timeseries.filter.func.SeriesFunction

Apply custom exponentially smoothed function to series.

Parameters
  • func – function to apply to series

  • alpha – smoothing factor, must be between 0 and 1

apply_to_series(values)[source]

Return result of exponentially smoothed function applied to series.

Parameters

values – values to apply function to

exponential_moving_average(values)[source]

Return exponential moving average of values.

Parameters

values – values to apply function to

class timeseries.filter.func.ExponentialMovingAverageSeries(alpha)[source]

Bases: timeseries.filter.func.CustomExponentialSeriesFunction

Exponentially smoothed moving average of series.

Parameters

alpha – smoothing factor, must be between 0 and 1