6 releases (breaking)

0.6.0 Oct 11, 2023
0.5.0 Sep 29, 2022
0.4.0 Sep 27, 2022
0.3.0 Sep 25, 2022
0.1.0 Sep 25, 2022

#904 in Math

Download history 28/week @ 2024-06-17 15/week @ 2024-06-24 42/week @ 2024-07-01 21/week @ 2024-07-08 3/week @ 2024-07-15 37/week @ 2024-07-22 64/week @ 2024-07-29 20/week @ 2024-08-05 26/week @ 2024-08-12 20/week @ 2024-08-19 14/week @ 2024-08-26 15/week @ 2024-09-02 15/week @ 2024-09-09 29/week @ 2024-09-16 72/week @ 2024-09-23 29/week @ 2024-09-30

149 downloads per month
Used in 4 crates (2 directly)

Apache-2.0

54KB
865 lines

Unit root tests in Rust

Build

Description

Stationarity tests for time-series data in Rust.

At the moment: Dickey-Fuller test and Augmented Dickey-Fuller test with no constan no trend, constant or constant and trend.

License

This project is licensed under the terms of the Apache License 2.0.

Usage

Augmented Dickey-Fuller test:

use unit_root::prelude::distrib::{AlphaLevel,Regression};
use unit_root::prelude::nalgebra::DVector;
use unit_root::prelude::*;

fn main() {
    let y = DVector::from_row_slice(&[
        -0.89642362,
        0.3222552,
        -1.96581989,
        -1.10012936,
        -1.3682928,
        1.17239875,
        2.19561259,
        2.54295031,
        2.05530587,
        1.13212955,
        -0.42968979,
    ]);

    let lag = 2;
    
    // compute the test statistic
    let regression = Regression::Constant;
    let report = tools::adf_test(&y, lag, regression).unwrap();

    // critical values for the model with a constant but no trend:
    let critical_value: f32 = distrib::dickeyfuller::get_critical_value(
        regression,
        report.size,
        AlphaLevel::OnePercent,
    )
    .unwrap();
    assert_eq!(report.size, 8);

    // comparison
    let t_stat = report.test_statistic;
    println!("t-statistic: {}", t_stat);
    println!("critical value: {}", critical_value);
}

See examples for more.

Dependencies

~3.5MB
~77K SLoC