Skip to content

Fix _norm_cdf scaling; add option pricer backtest + sensitivity model - #62

Open
IamJasonBian wants to merge 1 commit into
mainfrom
option-pricer-sensitivity
Open

IamJasonBian wants to merge 1 commit into
mainfrom
option-pricer-sensitivity

Conversation

@IamJasonBian

Copy link
Copy Markdown
Owner

Summary

  • Bug fix: _norm_cdf applied the A&S 7.1.26 erf approximation to x without the 1/sqrt(2) scaling, so Φ was off by up to ~0.04 (e.g. Φ(1) = 0.870 vs 0.841). Every bs_call_price / bs_put_price — including the existing protective-put/collar sims — was skewed.
  • bs_call_implied_vol: bisection IV solver.
  • option_pricer_backtest: prices a real contract daily with three σ models and scores them vs actual closes.
  • option_sensitivity: analytic Greeks + spot × IV × days-forward scenario grid CLI.

Backtest — NBIS 11/20/2026 $230C, 2026-09-29 → 2026-10-20 (n=16)

Model MAE Bias MAPE
prev-day IV $0.56 +$0.07 4.6%
frozen entry IV $1.67 +$1.50 9.9%
20d realized vol $4.12 −$4.12 22.2%

IV rose ~70% → ~93% as the underlying fell, so realized vol badly underprices and frozen IV drifts.

Run

python -m trading_system.backtests.option_pricer_backtest
python -m trading_system.backtests.option_sensitivity --spot 180

Test plan

  • pytest tests/backtests — 48 passed (IV round-trip, Greeks vs finite differences, Φ vs math.erf)
  • Re-check any saved put/collar backtest reports — their numbers change with the Φ fix

🤖 Generated with Claude Code

- Fix _norm_cdf: A&S 7.1.26 approximates erf, but was applied to x
  without the 1/sqrt(2) scaling, so Phi was off by up to ~0.04 and
  every bs_call_price/bs_put_price (incl. collar/put sims) was skewed.
- Add bs_call_implied_vol (bisection).
- Add option_pricer_backtest: prices a real contract daily with three
  sigma models (trailing realized vol, frozen entry IV, prior-day IV)
  and reports MAE / bias / MAPE vs actual closes (Yahoo chart data).
- Add option_sensitivity: analytic Greeks + spot x IV x days-forward
  scenario grid CLI.
- Tests: IV round-trip, Greeks vs finite differences, Phi vs math.erf.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb44973e-0286-46b9-aee5-6aedf0f0d003
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant