ar3_estimation/
ar3_estimation.rs

1extern crate rand;
2use arima::{acf, sim};
3use rand::prelude::*;
4use rand_distr::{Distribution, Normal};
5
6fn main() {
7    // initialize RNG with seed
8    let mut rng: StdRng = SeedableRng::from_seed([100; 32]);
9
10    // our noise should be normally distributed
11    let normal = Normal::new(10.0, 2.0).unwrap();
12
13    // simulate time series
14    let ts = sim::arima_sim(
15        1000,                               // number of samples
16        Some(&[0.7, 0.2]),                  // AR parameters
17        None,                               // MA parameters
18        0,                                  // difference parameter
19        &|mut rng| normal.sample(&mut rng), // noise fn
20        &mut rng,                           // RNG
21    )
22    .unwrap();
23
24    // estimate AR parameters
25    let ar = acf::ar(&ts, Some(2)).unwrap();
26
27    println!("Estimated parameters: {:?}", ar);
28    // Estimated parameters: [0.7436892808499717, 0.14774749031248915]
29}