MCPcopy Create free account
hub / github.com/Open-Quant/openquant / frac_diff

Function frac_diff

crates/openquant/src/fracdiff.rs:40–71  ·  view source on GitHub ↗
(series: &[f64], diff_amt: f64, thresh: f64)

Source from the content-addressed store, hash-verified

38}
39
40pub fn frac_diff(series: &[f64], diff_amt: f64, thresh: f64) -> Vec<f64> {
41 let n = series.len();
42 if n == 0 {
43 return Vec::new();
44 }
45 let weights = get_weights(diff_amt, n);
46
47 let mut cum = Vec::with_capacity(n);
48 let mut s = 0.0;
49 for w in &weights {
50 s += w.abs();
51 cum.push(s);
52 }
53 let total = *cum.last().unwrap_or(&1.0);
54 if total != 0.0 {
55 for v in &mut cum {
56 *v /= total;
57 }
58 }
59 let skip = cum.iter().filter(|v| **v > thresh).count();
60
61 let mut out = vec![f64::NAN; n];
62 for iloc in skip..n {
63 let w_start = n - (iloc + 1);
64 let mut acc = 0.0;
65 for j in 0..=iloc {
66 acc += weights[w_start + j] * series[j];
67 }
68 out[iloc] = acc;
69 }
70 out
71}
72
73pub fn frac_diff_ffd(series: &[f64], diff_amt: f64, thresh: f64) -> Vec<f64> {
74 let n = series.len();

Callers 2

test_frac_diffFunction · 0.85
fracdiff_frac_diffFunction · 0.85

Calls 2

get_weightsFunction · 0.85
lenMethod · 0.80

Tested by 1

test_frac_diffFunction · 0.68