Skip to main content

lorentzian_classification_core/
lib.rs

1//! Bit-faithful Rust port of the **Lorentzian Classification** indicator.
2//!
3//! This crate is a direct, forward-indexed port of the PineScript v6 reference
4//! (and the parity-tested Python port under `ports/python`). Series use index
5//! `0` as the oldest bar, and missing Pine `na` values are represented as
6//! [`f64::NAN`] ([`MISSING`]).
7//!
8//! The implementation is deliberately allocation-simple and dependency-light so
9//! it stays easy to audit against the reference. Floating-point operations
10//! mirror the Python port's accumulation order and rounding (banker's rounding
11//! via [`f64::round_ties_even`], libm `powf`/`exp`), which makes the two ports
12//! bit-for-bit equal and keeps the crate within `1e-6` of the TradingView gold
13//! baselines.
14//!
15//! # Cargo features
16//!
17//! * **`csv`** (default): TradingView CSV input ([`read_tradingview_csv`]) and
18//!   Pine-export parity checking (the [`parity`] module), via the established
19//!   `csv` crate so valid quoted CSV behaves like Python's standard `csv`
20//!   parser. Disable it (`default-features = false`) for a zero-dependency
21//!   numeric core when you feed [`Bar`] values from your own data pipeline.
22//!
23//! # Example
24//! ```
25//! use lorentzian_classification_core::{calculate, Bar, Settings};
26//!
27//! let bars: Vec<Bar> = (0..32)
28//!     .map(|i| {
29//!         let c = 100.0 + f64::from(i);
30//!         Bar { time: i.to_string(), open: c, high: c + 1.0, low: c - 1.0, close: c }
31//!     })
32//!     .collect();
33//! let rows = calculate(&bars, &Settings::default(), 0.0);
34//! assert_eq!(rows.len(), bars.len());
35//! ```
36
37#![forbid(unsafe_code)]
38// Published crate: every public item must be documented.
39#![deny(missing_docs)]
40#![warn(clippy::pedantic)]
41// Numeric casts are pervasive in this index-heavy numeric port and are always
42// within range for realistic bar counts; flagging each one adds noise.
43#![allow(clippy::cast_precision_loss)]
44#![allow(clippy::cast_possible_truncation)]
45#![allow(clippy::cast_possible_wrap)]
46#![allow(clippy::cast_sign_loss)]
47#![allow(clippy::must_use_candidate)]
48#![allow(clippy::missing_panics_doc)]
49// The following pedantic lints conflict with this crate's stated goal of a
50// 1:1, line-faithful translation of the PineScript / Python reference:
51// `Settings`/`ResultRow` mirror the Pine inputs and outputs (many bools);
52// paired bindings like `is_ema_up`/`is_sma_up` are intentionally parallel; the
53// `x != 0.0 ? a : b` divide-by-zero guards mirror the reference expressions.
54#![allow(clippy::struct_excessive_bools)]
55#![allow(clippy::similar_names)]
56#![allow(clippy::if_not_else)]
57// doc_markdown flags every product name (PineScript, TradingView, …); not worth
58// the backtick churn for prose.
59#![allow(clippy::doc_markdown)]
60
61pub mod ann;
62pub mod csv_io;
63pub mod display;
64pub mod engine;
65pub mod filters;
66pub mod indicators;
67pub mod kernels;
68#[cfg(feature = "csv")]
69pub mod parity;
70pub mod types;
71
72pub use ann::AnnState;
73pub use csv_io::detect_price_scale;
74#[cfg(feature = "csv")]
75pub use csv_io::{read_tradingview_csv, CsvError};
76pub use engine::{calculate, select_source};
77#[cfg(feature = "csv")]
78pub use parity::{parity_summary, read_pine_export, ExpectedRow, Mismatch, ParitySummary};
79pub use types::{
80    is_missing, nz, Bar, FeatureKind, FeatureSpec, ParseError, ResultRow, Settings, Source,
81    MISSING, RESULT_FIELDNAMES,
82};