Skip to content

Verification infrastructure: cross-engine consistency, property invariants, hot-path benchmarks#186

Merged
rosssaunders merged 3 commits into
mainfrom
claude/pricing-library-review-ou36tm
Jun 10, 2026
Merged

Verification infrastructure: cross-engine consistency, property invariants, hot-path benchmarks#186
rosssaunders merged 3 commits into
mainfrom
claude/pricing-library-review-ou36tm

Conversation

@rosssaunders

Copy link
Copy Markdown
Owner

Durable verification infrastructure following the two review passes (#183/#185): instead of more reading, this PR makes the engine stack check itself.

tests/cross_engine_consistency.rs (11 tests, ~20s debug)

The same instruments priced through every applicable engine with agreement asserted:

  • European vanillas over a 96-point grid: BS analytic vs CRR, trinomial, Crank-Nicolson (vol-adaptive S_max so low-vol points are grid-resolved rather than tolerance-excused), Monte Carlo (4σ), and Carr-Madan FFT via the exact BS characteristic function
  • American puts across CRR / independent binomial / trinomial / CN / LSM; American call with q=0 ≡ European
  • Barriers: in + out = vanilla exactly in analytic and in common-path MC; discrete MC vs analytic at the Broadie–Glasserman–Kou shifted barrier
  • Geometric Asians and digitals vs MC

No genuine inter-engine discrepancies found. The two independent CRR implementations agree to 1e-9; MC barrier parity holds to float precision.

tests/property_invariants.rs (18 tests, 0.03s)

Seeded-sweep no-arbitrage and structural properties: put-call parity (BS/Black76/GK/digital cash+asset), monotonicity/bounds/delta ranges/gamma–vega positivity, strike convexity, barrier parity and KO monotonicity, SVI calendar + Fengler butterfly checks, curve DF and swap-bootstrap repricing identities, CDS bootstrap repricing, analytic-vs-FD Greeks. All properties hold at first run.

benches/hot_paths_bench.rs (12 benchmarks)

Covers every recently optimized hot path so future regressions are measurable. Measured against the pre-review baseline (da6b4b8, release, criterion quick medians):

Path Baseline Current Speedup
Vol-surface query (128 lookups) 20.1 µs 3.3 µs ~6.1x
Autocallable single price 285.6 ms 31.9 ms ~8.9x
CDS bootstrap (5 pillars) 1.011 ms ~75 µs ~13x
Rolling historical VaR (5k, w=250) 21.7 ms ~3.4 ms ~6.4x
Gamma ladder (10 pillars) 33.3 µs 22.4 µs ~1.45x

Validation: both suites green, cargo bench --no-run --features parallel,simd compiles, fmt clean, workspace clippy zero errors.

https://claude.ai/code/session_01FAx1FjfzYunS5ZmSzywFjv


Generated by Claude Code

claude added 3 commits June 10, 2026 07:40
18 deterministic property tests over seeded random sweeps: put-call
parity (BS/Black76/Garman-Kohlhagen/digital cash+asset), monotonicity and
bounds (strike/spot/vol/maturity with documented q=0 restriction, delta
ranges, gamma/vega positivity), strike convexity, barrier in/out parity
across all four barrier types plus KO monotonicity in the barrier level,
SVI calendar monotonicity and Fengler butterfly checks through the public
query APIs, curve invariants (DF(0)=1, monotone DFs, swap-bootstrap par
repricing), CDS bootstrap repricing and survival monotonicity, and
analytic-vs-finite-difference Greeks consistency.

All properties hold at the specified tolerances; runtime 0.03s.

https://claude.ai/code/session_01FAx1FjfzYunS5ZmSzywFjv
Eleven deterministic tests pricing the same instruments through every
applicable engine and asserting agreement:
- European vanillas over a 96-point grid: Black-Scholes analytic vs CRR
  (1000 steps), trinomial (800), Crank-Nicolson (400x400 with a
  vol-adaptive S_max so low-vol short-maturity points are grid-resolved,
  not tolerance-excused), Monte Carlo (4 stderr), and Carr-Madan FFT via
  the exact BS characteristic function.
- American puts: CRR vs the independent AmericanBinomialEngine (agree to
  1e-9), trinomial, CN, and LSM; American call with q=0 equals European.
- Barriers: in+out = vanilla exactly in both analytic and common-path MC;
  discrete-monitoring MC vs analytic at the Broadie-Glasserman-Kou
  shifted barrier; one-sided discrete/continuous ordering checks.
- Asians: discrete geometric closed form vs MC with observations on grid.
- Digitals: analytic vs exact-terminal GBM MC.

No genuine inter-engine discrepancies found. ~20s debug runtime.

https://claude.ai/code/session_01FAx1FjfzYunS5ZmSzywFjv
Twelve criterion benchmarks covering the recently optimized paths:
vol-surface queries, BS analytic reference, MC European (standard, SoA
scalar, SoA SIMD), ADI Heston, LSM American, autocallable price-only vs
with-greeks, CDS bootstrap, one LM Heston iteration, rolling historical
VaR, and the curve gamma ladder.

Measured against the pre-review baseline (da6b4b8, release, criterion
quick medians):
- vol-surface query path        20.1us -> 3.3us   (~6.1x)
- autocallable single price     285.6ms -> 31.9ms (~8.9x, Greeks opt-in)
- CDS bootstrap (5 pillars)     1.011ms -> ~75us  (~13x)
- rolling historical VaR        21.7ms -> ~3.4ms  (~6.4x)
- gamma ladder (10 pillars)     33.3us -> 22.4us  (~1.45x)
- autocallable with_greeks      parity, as expected

https://claude.ai/code/session_01FAx1FjfzYunS5ZmSzywFjv
@rosssaunders rosssaunders marked this pull request as ready for review June 10, 2026 08:09
@rosssaunders rosssaunders merged commit 2c81207 into main Jun 10, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants