Expand description
§wc_fir
A Rust library for Manual & Auto (OLS) FIR modelling of working capital drivers.
This crate provides two main modes:
- Manual: Apply user-supplied FIR profiles (percentages + scale) to drivers
- Auto (OLS): Estimate FIR taps via ordinary least squares, then map to {scale, percentages}
§Example
use wc_fir::{fit_auto, ManualProfile, OlsOptions, fit_ols, manual_apply};
// Historical series (same length)
let d1: Vec<f64> = (0..24).map(|i| 120.0 + 2.0 * i as f64).collect();
let d2: Vec<f64> = (0..24).map(|i| 80.0 + 1.5 * i as f64).collect();
let y: Vec<f64> = d1
    .iter()
    .zip(d2.iter())
    .map(|(&a, &b)| 0.6 * a + 0.3 * b + 12.0)
    .collect();
// Manual mode
let manual = manual_apply(
    &[d1.clone(), d2.clone()],
    &[
        ManualProfile { percentages: vec![0.5, 0.35, 0.15], scale: 0.9 },
        ManualProfile { percentages: vec![0.3, 0.7], scale: 0.6 },
    ],
).unwrap();
// Auto (OLS) mode
let fit = fit_ols(
    &[d1.clone(), d2.clone()],
    y.as_slice(),
    &[3, 2], // lags per driver
    &OlsOptions::default(),
).unwrap();
// Auto defaults: build max design, lasso-select, refit OLS
let auto = fit_auto(&[d1, d2], y.as_slice()).unwrap();
println!("Auto RMSE: {:.4}  R²: {:.4}", auto.rmse, auto.r2);
println!("OLS per driver: {:?}", fit.per_driver);
println!("RMSE: {:.4}  R²: {:.4}", fit.rmse, fit.r2);Re-exports§
- pub use fir::manual_apply;
- pub use ols::fit_ols;
- pub use ols::predict_ols;
Modules§
Structs§
- AutoLagResult 
- Output of automatic lag selection followed by an OLS refit.
- Caps
- Per-driver lag caps used when building the maximal design matrix.
- Guardrails
- Guardrails to keep fits statistically sane.
- LassoSettings 
- Lasso / Elastic-net settings used for automatic lag selection.
- ManualProfile 
- Manual profile per driver: percentages (tap weights) + scale.
- OlsFit
- Plain OLS fit result used across the crate.
- OlsOptions
- Output of Auto (OLS) fit, mapped for auditability.
- Truncation
- Truncation of tiny tap weights after mapping to percentages.
Enums§
- FirError
- Library error type.
- IcKind
- Information-criterion variants.
- IcSearchKind 
- Search strategies for IC-based selection.
- LagSelect
- Lag selection strategies supported by the crate.
Functions§
- fit_auto 
- fit_auto_ prefix 
- Automatic lag-length selection using prefix blocks + rolling CV.
- fit_ols_ auto_ lags 
Type Aliases§
- Lag
- Per-driver lag length.