pure_greeks 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 918296785f22c79dac0dbf36cc96ba5cab3e31364678b2000346dc118e7a2d35
4
+ data.tar.gz: 536611801714363ee38eb8ea07eab8c041237138bb78566aaa9340b52d9ec9b0
5
+ SHA512:
6
+ metadata.gz: 34dafaf69f927d47690e6606c34bf75bd45a37e71ff349f282e7651a6fee71498d50e3b0a81c086365a9bbf28ac5b1ba446f54776bfcdcd2d12265aef18b2ad4
7
+ data.tar.gz: 2c49149f21e39c69332b11abdecdacce14f4f8623e2cd7dd59f4f3f1653903632218a92552d02ee1c9597ea8b7ec00cf338acc4f85936de3660cd138eea47a35
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2
data/BENCHMARKS.md ADDED
@@ -0,0 +1,50 @@
1
+ # Benchmarks — pure_greeks v0.1.0
2
+
3
+ Measured on Apple Silicon (arm64-darwin22), Ruby 3.2.0, MRI. Hardware-dependent — your numbers will differ. Re-run on your machine before relying on them.
4
+
5
+ ## Single-option microbenchmark
6
+
7
+ `bundle exec ruby bench/single_option.rb`
8
+
9
+ ```
10
+ American CRR (200 steps) 83.4 i/s (12.0 ms per call)
11
+ European Black-Scholes 147,500 i/s ( 6.8 µs per call)
12
+ ```
13
+
14
+ The American number is dominated by the CRR backward-induction tree (200 steps × up to 200 nodes per step = ~40k node operations per call, plus two more full tree solves for vega and rho via finite difference). The European number is essentially the cost of the Black-Scholes closed form plus three extra `Distribution::Normal.cdf` calls.
15
+
16
+ ## Batch benchmark
17
+
18
+ `bundle exec ruby bench/batch.rb` (American, mixed calls/puts, IVs in [0.20, 0.65]):
19
+
20
+ | batch size | wall time | throughput |
21
+ |-----------:|----------:|-----------:|
22
+ | 100 | 1.2 s | 84 ops/s |
23
+ | 1,000 | 11.9 s | 84 ops/s |
24
+ | 10,000 | 122.1 s | 82 ops/s |
25
+
26
+ Throughput is flat across batch sizes — no GC pressure or hot-path memoization wins, just the per-tree cost compounding linearly. This is the expected shape for pure-Ruby CRR.
27
+
28
+ ## v0.1 ship decision
29
+
30
+ Tenor's QuantLib pipeline (`GreeksCalculationBatchJob`) processes ~5,000–15,000 options per batch in ~30–60 s, i.e. ~250 ops/s. Our 83 ops/s on the same workload is **~33% of QuantLib's throughput** — acceptable for interactive use and most batch jobs, but slow for large nightly Greeks computations.
31
+
32
+ The plan's pure-Ruby ship threshold was 50 ops/s; we're comfortably above that. Ship pure Ruby for v0.1; queue performance work for v0.2.
33
+
34
+ ## Performance backlog (v0.2 candidates)
35
+
36
+ Roughly ordered by expected impact:
37
+
38
+ 1. **Reuse the baseline CRR tree across the σ and r bumps.** Today, vega and rho rebuild the entire tree with a perturbed parameter (3× cost). With careful state separation we can reuse the leaf payoffs and replay only the affected step. Expected: ~3× speedup on American Greeks. Risk: easy to introduce subtle numerical drift if the bumped tree's `dt`, `u`, `d`, `p`, `disc` aren't fully recomputed.
39
+ 2. **Drop default `steps` from 200 to 100.** O(N²) tree work, so this is a 4× speedup. Risk: extreme-IV or near-expiry rows lose accuracy — verify against the regression suite before adopting.
40
+ 3. **C extension for backward induction** (`rice` or a direct Ruby C extension). Estimated 10–50× speedup on the inner loop. Risk: native code re-introduces the install-friction problem this gem exists to solve. Worth doing only if v0.1 throughput becomes a real bottleneck.
41
+
42
+ ## How to re-run
43
+
44
+ ```bash
45
+ bundle install
46
+ bundle exec ruby bench/single_option.rb # microbenchmark with benchmark/ips
47
+ bundle exec ruby bench/batch.rb # batch sweep at 100 / 1k / 10k
48
+ ```
49
+
50
+ `benchmark-ips` is in the gemspec as a `development_dependency`, so `bundle install` pulls it in for the gem checkout but it isn't required for end users.
data/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-04-26
10
+
11
+ Initial release.
12
+
13
+ ### Added
14
+
15
+ - Object-oriented `PureGreeks::Option` API for vanilla American and European options.
16
+ - Three engines selected automatically by `PureGreeks::Engines::FallbackChain`:
17
+ - **CRR Binomial American** (200 steps) — for American exercise.
18
+ - **Black-Scholes European** (closed form) — for European or as fallback.
19
+ - **Intrinsic** — for `implied_volatility <= 0`.
20
+ - All five Greeks per option: delta, gamma, theta (per calendar day), vega (per 1% vol move), rho (per 1% rate move).
21
+ - Implied volatility solver via Brent's method (`PureGreeks::ImpliedVolatility::BrentSolver`), invoked by passing `market_price:` instead of `implied_volatility:`.
22
+ - `Option#calculation_model` accessor exposes which engine produced the result.
23
+ - Custom error hierarchy (`PureGreeks::Error`, `InvalidInputError`, `ExpiredContractError`, `CalculationError`, `IVConvergenceError`).
24
+ - Regression suite against ~500 historical option snapshots from production data; methodology and observed drift documented in `REGRESSION_REPORT.md`.
25
+ - Performance baselines documented in `BENCHMARKS.md`: ~83 ops/s for American (CRR 200 steps), ~150k ops/s for European (closed form).
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jay Ravaliya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.