Skip to main content

adaq_talib/
lib.rs

1//! # adaq-talib
2//!
3//! 纯 Rust、Zero-FFI、零依赖的 [TA-Lib](https://ta-lib.org) 0.7.1 技术指标复刻库。
4//!
5//! Pure-Rust, zero-FFI, dependency-free reimplementation of the
6//! [TA-Lib](https://ta-lib.org) 0.7.1 technical-analysis indicators.
7//!
8//! ## 设计目标 / Design goals
9//!
10//! - **零偏差 (zero-deviation)**:每个函数的数值输出与原版 TA-Lib 0.7.1 逐项一致
11//!   (在浮点误差容限内,见 [`crate::utils`] 与 ADR 0005)。
12//! - **Zero-FFI / No-Dependencies**:发布的库不调用任何 C ABI,`[dependencies]` 为空,
13//!   全部算法原生手写。
14//! - **惯用 Rust API (模型 B)**:切片入参、`Result<_, TaError>` 出参、多输出用结构体返回
15//!   (见 ADR 0001)。前导不稳定期以 [`f64::NAN`] 填充、等长返回(见 ADR 0007)。
16//! - **性能优先**:在内存布局、循环分支、数组运算层面做优化。
17//!
18//! ## 覆盖范围 / Coverage
19//!
20//! 采用里程碑式发布(见 ADR 0002):`0.1.0` 覆盖重叠研究、动量、波动率、成交量、价格变换
21//! 与统计类;数学变换(Math Transform)、数学运算符(Math Operators)与剩余周期/模式识别
22//! 指标在后续里程碑补齐,最终全量且不删减任何原版能力(见 [`docs/0.1.0-scope.md`](docs/0.1.0-scope.md)
23//! 与 `docs/NEXT-ACTIONS-perf.md` 的 P4 进度)。
24//!
25//! ## 快速开始 / Quick start
26//!
27//! ```rust
28//! use adaq_talib::overlap::sma;
29//!
30//! let prices = [1.0, 2.0, 3.0, 4.0, 5.0];
31//! let out = sma(&prices, 3).unwrap();
32//! // out 与 prices 等长;前导 2 个位置为 NaN,其余为窗口均值。
33//! // `out` has the same length as `prices`; the first 2 positions are NaN, the rest are window means.
34//! assert!(out[0].is_nan());
35//! assert!((out[2] - 2.0).abs() < 1e-9);
36//! ```
37//!
38//! ## 验证与基准 / Verification & benchmarks
39//!
40//! - 正确性:与入库黄金向量(由 TA-Lib 原版生成,`tools/gen_fixtures`)比对,普通
41//!   `cargo test` 无需 Python(见 ADR 0003)。
42//! - 性能:双轨基准 —— `benches/` 可选 `bench-c` feature FFI 对照原生 C,
43//!   `tools/bench` 提供 Python 便捷对照(如实标注为 TA-Lib Python 绑定层,见 ADR 0004)。
44
45pub mod error;
46pub mod momentum;
47pub mod overlap;
48pub mod price_transform;
49pub mod stat;
50pub mod volume;
51pub mod volatility;
52pub mod cycle;
53pub mod math_ops;
54pub mod math_trans;
55pub mod pattern;
56
57pub(crate) mod core;
58
59// 指标脚手架接缝(架构评审候选①深化):零成本 `indicator!` 宏,集中指标的
60// 「等长 NaN 缓冲分配 + 转发 _with_output」重复脚手架。详见 `src/indicator.rs`。
61// Indicator-scaffold seam (candidate-①): zero-cost `indicator!` macro.
62pub(crate) mod indicator;
63
64// 默认关闭的多核并行分块(P3-2)。仅 `parallel` feature 下参与编译。
65// Default-off multi-core parallel chunking (P3-2). Compiled only under the `parallel` feature.
66#[cfg(feature = "parallel")]
67pub(crate) mod parallel;
68// 暴露为 doc(hidden) 公共模块,便于集成测试与 benches 复用 approx 工具(内部实现细节)。
69// Exposed as a doc(hidden) public module so integration tests and benches can reuse the
70// approx helpers; it is an internal implementation detail, not part of the public API.
71#[doc(hidden)]
72pub mod utils;
73
74pub use error::TaError;