pub fn frac_diff(series: &[f64], diff_amt: f64, thresh: f64) -> Vec<f64>Expand description
Fractionally differences series with an expanding window (AFML Snippet 5.2).
Output t applies the first t + 1 weights of (1 - B)^d to series[0..=t]. The
leading outputs, where the weights that would apply to missing history exceed thresh
of the total absolute weight, are NaN. thresh = 1.0 skips nothing (the mlfinlab
default); AFML uses 0.01. The growing number of terms introduces a window-induced drift
(ยง5.5.1), which is why frac_diff_ffd is preferred for features.
series is a level (log price or price), oldest first. The output has the same length.
Cost is O(n^2).
use openquant::fracdiff::frac_diff;
let out = frac_diff(&[1.0, 2.0, 4.0], 1.0, 1.0);
assert_eq!(out, vec![1.0, 1.0, 2.0]);