Skip to content

Add American option adjoint example - #24

Open
tylrcc wants to merge 1 commit into
auto-differentiation:mainfrom
tylrcc:example/american-option-adjoint
Open

tylrcc wants to merge 1 commit into
auto-differentiation:mainfrom
tylrcc:example/american-option-adjoint

Conversation

@tylrcc

@tylrcc tylrcc commented Nov 12, 2026

Copy link
Copy Markdown

Closes #16.

Python port of the AdjointAmericanEquityOption C++ example, following the pattern of swap-adjoint.py:

  • Same setup as the C++ original: American put, spot 36, strike 40, rate 0.06, vol 0.20, dividend yield 0.00, evaluation date 15 May 1998, maturity 17 May 1999, priced with FdBlackScholesVanillaEngine (801 time steps, 800 grid points).
  • All five inputs registered on the tape; rho, strike sensitivity, vega, delta, and dividend rho from a single adjoint pass.
  • The example cross-checks the Greeks against bump-and-reprice finite differences (eps = 1e-5).

Testing: the current QuantLibAAD wheel is not reachable from my sandbox, so I ran the identical example code against QuantLib-Risks 1.33.3 (the direct predecessor of QuantLibAAD; only the tape-construction lines differ between the two APIs). It runs end to end: value 4.4861132726; rho adjoint -10.342487 vs bump -10.341887; strike 0.739227 vs 0.739227; vega 10.936834 vs 10.937061; delta -0.696749 vs -0.696749.

One known mismatch, documented in the example itself: the FD engine builds its operator from the dividend yield as a plain value, so the adjoint dividend rho comes out numerically zero (0.000031) while bumping gives 9.046635. I verified this is specific to the FD engine, not the port: the analytic engine and Barone-Adesi-Whaley both produce dividend rhos that match bumping on the same setup, and the FD engine shows the same behaviour for a European option. The C++ example has the same property, since it uses the same engine. Flagging it here in case you would rather the example note be worded differently.

Note: this repo requires a signed CLA before merge (per CONTRIBUTING) — I understand it will be handled through the CLA flow.

Port of the AdjointAmericanEquityOption C++ example. Prices an American
put with the finite-difference Black-Scholes engine (801 time steps) and
computes rho, strike sensitivity, vega, delta, and dividend rho in a
single adjoint pass.

The example cross-checks the Greeks against bump-and-reprice finite
differences and documents the one mismatch: the FD engine builds its
operator from the dividend yield as a plain value, so the adjoint
dividend rho is numerically zero while bumping gives about 9.05. The
other four Greeks agree to within 6e-5 relative.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@auto-differentiation-dev

Copy link
Copy Markdown
Contributor

@tylrcc friendly reminder: the CLA (link in the bot comment above) is the only thing holding these four PRs. It takes a minute to sign, and then we can get CI going and review them.

This branch has not been deployed

No deployments
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.

Port the adjoint American option example

3 participants