TemporalSeries
A Rust library for quantitative time-series analysis.
Features
- Percentage change (
pct_change) - First-order difference (
diff) - Lag / forward shift (
shift) - Rolling window mean (
rolling().mean())
Usage
use TimeSeries;
let ts = new.unwrap;
// Simple returns
let returns = ts.pct_change.unwrap;
// Rolling mean with window of 3
let momentum = returns.rolling.mean.unwrap;
Error handling
All fallible operations return Result<TimeSeries, TemporalSeriesError>.
use ;
match new
Storage backends
TemporalSeries<T, B> is generic over its storage backend, so you can choose
the in-memory layout that best fits your workload.
Columnar
Values are stored in a single contiguous Vec<T>, separate from the index.
This is the most cache-friendly layout for operations that scan the value
column alone (aggregations, rolling windows).
use TemporalSeries;
use ColumnarBackend;
let index: = vec!;
let values: = vec!;
let backend = new;
let series = new.unwrap;
println!; // Some(30.0)
Row
Each observation is stored as a RowRecord { timestamp, value }. This layout
is a natural fit when data arrives record-by-record (database cursors, message
streams) and keeps timestamps co-located with their values.
use TemporalSeries;
use ;
let rows: = vec!;
let index: = rows.iter.map.collect;
let backend = new;
let series = new.unwrap;
println!; // Some(30.0)
| Columnar | Row | |
|---|---|---|
| Memory layout | values packed, index separate | timestamp + value interleaved per record |
| Best for | column scans, aggregations | record-at-a-time ingestion |
| Extra allocation | separate index Vec |
none beyond the records themselves |
NaN convention
Operations that cannot produce a value for a position (e.g. the first element
of diff or pct_change, or the first window - 1 elements of a rolling mean)
return NaN at that position rather than truncating the series. This keeps the
output length equal to the input length and preserves index alignment.
Examples
| Example | Command | Description |
|---|---|---|
basic |
cargo run --example basic |
Constructs a series and computes pct_change followed by a rolling mean |
input_output |
cargo run --example input_output |
Reads a series from examples/input.csv, writes it to examples/output.csv, and reads it back |
temporal_series_with_columnar_backend |
cargo run --example temporal_series_with_columnar_backend |
Builds a TemporalSeries with a ColumnarBackend and demonstrates access and iteration |
temporal_series_with_row_backend |
cargo run --example temporal_series_with_row_backend |
Builds a TemporalSeries with a RowBackend and demonstrates access and iteration |
panel |
cargo run --example panel |
Builds a Panel of named series on a shared index and extracts one series for analysis |
Development
# Run tests
# Run linter
# Open API docs
# Run all benchmarks
# Run a single benchmark target
# Open the HTML report in the browser (macOS)
Criterion writes an HTML report to target/criterion/ after every run.
Each benchmark target has its own sub-report, and there is a combined index at
target/criterion/report/index.html that covers all targets.
To open a single target's report directly:
License
MIT