1515[ ![ Wiki] ( https://img.shields.io/badge/wiki-latest-blue.svg )] ( https://deepwiki.com/joaquinbejar/OptionStratLib )
1616
1717
18- ## OptionStratLib v0.16.4 : Financial Options Library
18+ ## OptionStratLib v0.16.5 : Financial Options Library
1919
2020### Table of Contents
21211 . [ Introduction] ( #introduction )
@@ -134,6 +134,96 @@ Complete pricing support for all exotic option types:
134134- ** Exchange** : Margrabe's formula for asset exchange
135135- ** Power** : Non-linear payoff options
136136
137+ ### Quality & Discipline (0.16.x)
138+
139+ The 0.16 line is a quality-hardening release. Every change below is
140+ enforced crate-wide and documented in ` CHANGELOG.md ` :
141+
142+ - ** Checked ` Decimal ` arithmetic.** Every monetary-path kernel routes
143+ through ` d_add ` / ` d_sub ` / ` d_mul ` / ` d_div ` / ` d_sum ` /
144+ ` d_sum_iter ` in ` model::decimal ` . Overflow on any monetary
145+ expression surfaces ` DecimalError::Overflow { operation, lhs, rhs } `
146+ tagged with a static call-site string; no silent wraparound.
147+ - ** Non-finite ` f64 ` guards.** Every ` f64 → Decimal ` boundary inside
148+ pricing, Greeks, volatility, and simulation is wrapped with
149+ ` finite_decimal(..) ` and surfaces a domain-specific
150+ ` NonFinite { context, value } ` variant
151+ (` PricingError ` , ` GreeksError ` , ` VolatilityError ` ,
152+ ` SimulationError ` ) instead of collapsing silently to
153+ ` Decimal::ZERO ` .
154+ - ** ` NonZeroUsize ` step counts.** ` price_binomial ` ,
155+ ` monte_carlo_option_pricing ` , ` telegraph ` and related kernels take
156+ ` std::num::NonZeroUsize ` for ` steps ` / ` simulations ` ; zero is
157+ structurally invalid at the type level. Use the ` nz!(N) ` macro
158+ at literal call sites.
159+ - ** ` Positive ` at every public boundary.** Monetary values,
160+ strikes, quantities, volatilities are ` Positive ` (newtype around
161+ ` Decimal ` ). Strategy-level P&L goes through
162+ ` Positive::new_decimal(..) ` at every point where a signed
163+ ` Decimal ` would otherwise be clamped to ` Positive ` , so inverted
164+ strikes or out-of-range optimizer candidates return typed
165+ ` StrategyError ` rather than panicking.
166+ - ** Zero unchecked indexing in production code.**
167+ ` #![deny(clippy::indexing_slicing)] ` is enforced crate-wide with
168+ scoped, documented escapes per module. Tests stay permissive via
169+ ` #![cfg_attr(test, allow(..))] ` . Production paths use
170+ ` .get(..).ok_or_else(..) ` with typed errors.
171+ - ** Doc coverage floor.** `#![ deny(missing_docs,
172+ rustdoc::broken_intra_doc_links)] ` . Every ` pub` item has a ` ///`
173+ summary; every ` Result ` returner documents its ` # Errors `
174+ contract.
175+ - ** Structured tracing.** ` #[tracing::instrument] ` on the public
176+ hot paths: ` pricing::black_scholes ` ,
177+ ` pricing::monte_carlo_option_pricing ` ,
178+ ` pricing::price_binomial ` , ` volatility::implied_volatility ` ,
179+ and the strategy optimizer entry points
180+ ` get_best_ratio ` / ` get_best_area ` . No ` println! ` / ` eprintln! `
181+ / ` dbg! ` / ` log:: ` anywhere in ` src/ ` .
182+ - ** Compiler-attribute discipline.** ` #[must_use] ` on every pure
183+ function and builder, ` #[inline] ` on small hot-path helpers,
184+ ` #[cold] #[inline(never)] ` on every error constructor,
185+ ` #[repr(u8)] ` on small stable enums, canonical ` #[derive] `
186+ ordering.
187+ - ** Deterministic simulation tests.** ` utils::deterministic_rng(seed) `
188+ provides a canonical seeded ` StdRng ` for Monte-Carlo / simulation
189+ tests, so precision shifts in upstream arithmetic cannot flip
190+ assertions by luck.
191+ - ** Pricing-identity regression tests.** ` tests/unit/pricing/identities_test.rs `
192+ locks put-call parity on a grid, CRR binomial convergence to
193+ Black-Scholes, and the Greek sanity identities
194+ (` Γ_c = Γ_p ` , ` Vega_c = Vega_p ` , ` Δ_c − Δ_p ≈ e^{-qT} ` ).
195+
196+ #### Arithmetic-Error Cascade
197+
198+ ``` mermaid
199+ flowchart LR
200+ subgraph Kernels["Numeric kernels (model / pricing / greeks / volatility / simulation)"]
201+ DADD["d_add / d_sub / d_mul / d_div"]
202+ DSUM["d_sum / d_sum_iter"]
203+ FD["finite_decimal(f64)"]
204+ end
205+
206+ subgraph Errors["Typed errors (error/*)"]
207+ DOV["DecimalError::Overflow { operation, lhs, rhs }"]
208+ PNF["PricingError::NonFinite { context, value }"]
209+ GNF["GreeksError::NonFinite"]
210+ VNF["VolatilityError::NonFinite"]
211+ SNF["SimulationError::NonFinite"]
212+ end
213+
214+ DADD -- "checked_*" --> DOV
215+ DSUM -- "checked_*" --> DOV
216+ FD -- "NaN / ±∞ guard" --> PNF
217+ FD --> GNF
218+ FD --> VNF
219+ FD --> SNF
220+
221+ DOV -- "#[from]" --> PNF
222+ DOV -- "#[from]" --> GNF
223+ DOV -- "#[from]" --> VNF
224+ DOV -- "#[from]" --> SNF
225+ ```
226+
137227
138228### Core Modules
139229
@@ -587,6 +677,31 @@ flowchart LR
587677 Surfaces --> |"3D Analysis"| Analysis
588678```
589679
680+ ### Observability
681+
682+ Public hot paths are annotated with ` #[tracing::instrument] ` .
683+ Enable a subscriber in the consumer crate (the library itself never
684+ installs one) to surface structured spans:
685+
686+ ``` mermaid
687+ flowchart LR
688+ APP[Consumer application] -- "installs" --> SUB["tracing_subscriber"]
689+
690+ subgraph Spans["Instrumented public fns"]
691+ BS["pricing::black_scholes\n(strike, style, side)"]
692+ MC["pricing::monte_carlo_option_pricing\n(steps, simulations, strike, style, side)"]
693+ BI["pricing::price_binomial\n(strike, asset, steps, style, side)"]
694+ IV["volatility::implied_volatility\n(market_price, strike, max_iterations)"]
695+ OPT["Optimizable::get_best_ratio/area\n(side, criteria)"]
696+ end
697+
698+ BS --> SUB
699+ MC --> SUB
700+ BI --> SUB
701+ IV --> SUB
702+ OPT --> SUB
703+ ```
704+
590705### Trading Strategies
591706
592707OptionStratLib provides 25+ comprehensive trading strategies organized by complexity and market outlook:
@@ -668,7 +783,7 @@ All strategies implement a comprehensive trait system:
668783
669784#### Prerequisites
670785
671- - Rust 1.80 or higher (2024 edition)
786+ - Rust 1.85 or higher (Rust 2024 edition)
672787- Cargo package manager
673788
674789#### Installation
@@ -677,7 +792,7 @@ Add OptionStratLib to your `Cargo.toml`:
677792
678793``` toml
679794[dependencies ]
680- optionstratlib = " 0.16.4 "
795+ optionstratlib = " 0.16.5 "
681796```
682797
683798Or use cargo to add it to your project:
@@ -692,11 +807,12 @@ The library includes optional features for enhanced functionality:
692807
693808``` toml
694809[dependencies ]
695- optionstratlib = { version = " 0.16.4 " , features = [" plotly" ] }
810+ optionstratlib = { version = " 0.16.5 " , features = [" plotly" ] }
696811```
697812
698813- ` plotly ` : Enables interactive visualization using plotly.rs
699- - ` async ` : Enables asynchronous I/O operations for OptionChain and OHLCV data
814+ - ` static_export ` : PNG / SVG export via ` plotly_static ` (pulls in async runtime)
815+ - ` async ` : Enables asynchronous I/O operations for OptionChain and OHLCV data (tokio + reqwest + futures)
700816
701817#### Building from Source
702818
@@ -947,7 +1063,9 @@ fn main() -> Result<(), optionstratlib::error::Error> {
9471063
9481064### Testing
9491065
950- OptionStratLib includes a comprehensive test suite with over 3800 unit and integration tests:
1066+ OptionStratLib ships with a large, fully deterministic test suite
1067+ (3760 unit / integration tests + 205 doctests + property- and
1068+ identity-based regressions):
9511069
9521070#### ** Running Tests**
9531071
@@ -971,13 +1089,22 @@ cargo test -- --nocapture
9711089#### ** Test Categories**
9721090
9731091- ** Unit Tests** : Individual function and method testing
974- - ** Integration Tests** : Cross-module functionality testing
1092+ - ** Integration Tests** : Cross-module functionality under ` tests/ `
9751093- ** Strategy Tests** : Comprehensive strategy validation
9761094- ** Pricing Model Tests** : Accuracy and performance testing
9771095- ** Greeks Tests** : Mathematical precision validation
9781096- ** Visualization Tests** : Chart generation and export testing
9791097- ** Property-Based Tests** : Mathematical invariant testing with ` proptest `
980- - ** Exotic Options Tests** : Complete coverage for all 14 exotic option types
1098+ (` tests/property/put_call_parity_test.rs ` , ` greeks_bounds_test.rs ` )
1099+ - ** Identity Regression Tests** : ` tests/unit/pricing/identities_test.rs `
1100+ locks put-call parity, CRR → Black-Scholes convergence, and
1101+ Greek sanity (` Γ_c = Γ_p ` , ` Vega_c = Vega_p ` ,
1102+ ` Δ_c − Δ_p ≈ e^{-qT} ` ).
1103+ - ** Deterministic Monte-Carlo Tests** : Seeded via
1104+ [ ` utils::deterministic_rng ` ] so arithmetic-precision shifts can't
1105+ flip assertions.
1106+ - ** Exotic Options Tests** : Complete coverage for all 14 exotic
1107+ option types.
9811108
9821109#### ** Benchmarking**
9831110
@@ -993,23 +1120,46 @@ cargo tarpaulin --all-features --out Html
9931120
9941121### Examples
9951122
996- The library includes extensive examples organized by functionality:
1123+ Examples live in self-contained sub-crates under ` examples/ ` , each
1124+ with its own ` Cargo.toml ` :
1125+
1126+ - ** ` examples_strategies/ ` ** : 25+ strategy demos
1127+ - ** ` examples_strategies_best/ ` ** : Optimizer entry points
1128+ (` get_best_area ` / ` get_best_ratio ` ) per strategy
1129+ - ** ` examples_strategies_delta/ ` ** : Delta-neutrality workflows
1130+ - ** ` examples_chain/ ` ** : Option chain construction, import/export,
1131+ and async I/O
1132+ - ** ` examples_curves/ ` ** : Greek curves (` charm ` , ` color ` , ` d1 ` , ` d2 ` ,
1133+ ` delta ` , ` gamma ` , ` rho ` , ` theta ` , …) and vector curves
1134+ - ** ` examples_surfaces/ ` ** : 3-D volatility surfaces
1135+ - ** ` examples_metrics/ ` ** : Price / risk / liquidity / stress /
1136+ temporal / composite metric curves and surfaces
1137+ - ** ` examples_volatility/ ` ** : Implied-volatility solver walkthroughs
1138+ - ** ` examples_simulation/ ` ** : Monte-Carlo random-walk demos for
1139+ ` LongCall ` , ` ShortPut ` , position / strategy simulators, and
1140+ random-walk-of-chain
1141+ - ** ` examples_exotics/ ` ** : Exotic option pricing (barrier,
1142+ cliquet, …)
1143+ - ** ` examples_visualization/ ` ** : Interactive chart wiring
1144+
1145+ Run any binary with the usual cargo invocation (from the repo
1146+ root, so relative data-fixture paths resolve correctly):
9971147
998- - ** ` examples/examples_strategies/ ` ** : Complete strategy examples (25+ strategies)
999- - ** ` examples/examples_chains/ ` ** : Option chain analysis examples
1000- - ** ` examples/examples_pricing/ ` ** : Pricing model demonstrations
1001- - ** ` examples/examples_visualization/ ` ** : Interactive chart examples
1002- - ** ` examples/examples_volatility/ ` ** : Volatility analysis examples
1003- - ** ` examples/examples_simulation/ ` ** : Monte Carlo and simulation examples
1004- - ** ` examples/examples_exotics/ ` ** : Exotic option pricing examples
1005-
1006- Run examples:
10071148``` bash
1008- cargo run --example bull_call_spread --features plotly
1009- cargo run --example black_scholes_pricing
1010- cargo run --example volatility_surface
1149+ cargo run --manifest-path=examples/examples_strategies/Cargo.toml \
1150+ --bin strategy_bull_call_spread
1151+ cargo run --manifest-path=examples/examples_simulation/Cargo.toml \
1152+ --bin long_call_strategy_simulation --features plotly
1153+ cargo run --manifest-path=examples/examples_metrics/Cargo.toml \
1154+ --bin implied_volatility_surface
10111155```
10121156
1157+ Simulation-heavy demos (` *_strategy_simulation ` , ` position_simulator ` ,
1158+ ` strategy_simulator ` , ` random_walk_chain ` ) use a demo-friendly
1159+ hourly grid so ` cargo run ` finishes in a few seconds in debug mode;
1160+ bump ` n_steps ` / ` n_simulations ` inside the binary if you want a
1161+ finer sample.
1162+
10131163### Contribution and Contact
10141164
10151165#### ** Contributing**
@@ -1048,7 +1198,7 @@ cargo test --all-features
10481198
10491199---
10501200
1051- ** OptionStratLib v0.16.4 ** - Built with ❤️ in Rust for the financial community
1201+ ** OptionStratLib v0.16.5 ** - Built with ❤️ in Rust for the financial community
10521202
10531203
10541204
0 commit comments