FracdiffStat#

class fracdiff.sklearn.FracdiffStat(window=10, mode='same', window_policy='fixed', stattest='ADF', pvalue=0.05, precision=0.01, upper=1.0, lower=0.0, n_jobs=None)[source]#

A scikit-learn transformer to compute fractional differentiation, where the order is chosen as the minumum order that makes fracdiff stationary.

Parameters:
  • window (int > 0 or None, default 10) – Number of observations to compute each element in the output.

  • mode ({"same", "valid"}, default "same") – See fracdiff.fdiff() for details.

  • window_policy ({"fixed"}, default "fixed") –

    If “fixed” :

    Fixed window method. Every term in the output is evaluated using window observations. In other words, a fracdiff operator, which is a polynominal of a backshift operator, is truncated up to the window-th term. The beginning window - 1 elements in output are filled with numpy.nan.

    If “expanding” (not available) :

    Expanding window method. Every term in fracdiff time-series is evaluated using at least window observations. The beginning window - 1 elements in output are filled with numpy.nan.

  • stattest ({"ADF"}, default "ADF") – Method of stationarity test.

  • pvalue (float, default 0.05) – Threshold of p-value to judge stationarity.

  • precision (float, default .01) – Precision for the order of differentiation.

  • upper (float, default 1.0) – Upper limit of the range to search the order.

  • lower (float, default 0.0) – Lower limit of the range to search the order.

  • n_jobs (int, default None) – The number of jobs to run fit in parallel. -1 means using all processors

d_#

Minimum order of fractional differentiation that makes time-series stationary.

Type:

numpy.array, shape (n_features,)

Note

If upper th differentiation of series is still non-stationary, order_ is set to numpy.nan. If lower th differentiation of series is already stationary, order_ is set to lower, but the true value may be smaller.

Examples

>>> from fracdiff.sklearn import FracdiffStat
>>> np.random.seed(42)
>>> X = np.random.randn(100, 4).cumsum(0)
>>> f = FracdiffStat().fit(X)
>>> f.d_
array([0.140625 , 0.5078125, 0.3984375, 0.140625 ])
>>> X = f.transform(X)
fit(X, y=None)[source]#

Fit the model with X.

Parameters:
  • X (array_like, shape (n_samples, n_features)) – Time-series to perform fractional differentiation. Here n_samples is the number of samples and n_features is the number of features.

  • y (array_like, optional) – Ignored.

Returns:

self – Returns the instance itself.

Return type:

object

transform(X, y=None)[source]#

Return the fractional differentiation of X.

Parameters:
  • X (array_like, shape (n_samples, n_series)) – Time-series to perform fractional differentiation. Raises ValueError if n_samples < self.window.

  • y (array_like, optional) – Ignored.

Returns:

fdiff – The fractional differentiation of X.

Return type:

numpy.ndarray, shape (n_samples, n_series)