1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! Demonstrates the core analytical operations of [`TimeSeries`].
//!
//! Starting from a short price series, this example chains three operations
//! that are common in quantitative finance:
//!
//! 1. [`TimeSeries::pct_change`] — converts prices into period returns.
//! 2. [`TimeSeries::rolling`] + [`RollingSeries::mean`] — smooths the returns
//! with a rolling mean, producing a simple momentum signal.
//!
//! # NaN convention
//!
//! Both operations leave positions where no result can be computed set to
//! `NaN` rather than truncating the series. `pct_change` sets index 0 to `NaN`
//! (no prior observation); `rolling(2).mean()` sets index 0 to `NaN` as well
//! (window not yet full). The output length always equals the input length.
//!
//! # Expected output
//!
//! ```text
//! [NaN, NaN, 0.0099..., 0.0099..., 0.0099...]
//! ```
//!
//! # Run
//!
//! ```bash
//! cargo run --example basic
//! ```
use TimeSeries;