Fractional differentiation of time-series.
$ pip install fracdiff
- Perform fractional differentiation of time-series
- Scikit-learn-like API
See M. L. Prado, "Advances in Financial Machine Learning".
A transformer class Fracdiff
performs fractional differentiation by its method transform
.
The following example gives 0.5th differentiation of S&P 500.
from fracdiff import Fracdiff
spx = ... # Fetch 1d array of S&P 500 historical price
fracdiff = Fracdiff(0.5)
spx_diff = fracdiff.transform(spx)
The result looks like this:
A transformer class StationaryFracdiff
finds the minumum order of fractional differentiation that makes time-series stationary.
from fracdiff import StationaryFracdiff
nky = ... # Fetch 1d array of Nikkei 225 historical price
statfracdiff = StationaryFracdiff()
statfracdiff.fit(nky)
statfracdiff.order_
# 0.23
Differentiated time-series with this order is obtained by subsequently applying transform
method.
This series is interpreted as a stationary time-series keeping the maximum memory of the original time-series.
nky_diff = statfracdiff.transform(nky) # same with Fracdiff(0.23).transform(nky)
The method fit_transform
carries out fit
and transform
at once.
nky_diff = statfracdiff.fit_transform(nky)
The result looks like this:
Other examples are provided here.
Example solutions of exercises in Section 5 of "Advances in Financial Machine Learning" are provided here.