Repository navigation
Conversation
|
|
|
Thanks a lot for these, Tyler! Could you sign the CLA (link above)? Then we can run CI and review all four. |
auto-differentiation-dev
left a comment
There was a problem hiding this comment.
Thanks for picking up #15, and for porting the full portfolio rather than a single option: that's a nice first example for new users. A few things before we can merge:
- Run it on QuantLibAAD. QuantLibAAD 1.44.0 is now on PyPI (
pip install QuantLibAAD, Python 3.10–3.14), so the example can now be run against the package it's for. - Rebase onto current
main. Your branch is based on the state before 1.44.0, so the diff currently shows the whole release. After the rebase it should only addPython/examples/european-option-adjoint.pyand one CHANGELOG line. - Central differences for the check. Bump each input up and down,
(V(x+h) - V(x-h)) / (2h)withh = 1e-5, so the comparison agrees to about 1e-8 relative instead of 1e-5. Print the largest relative difference over all 98 inputs, not just the largest sensitivities. - Put the AAD computation in a function, as the newer examples do: see
aad_sensitivities()inPython/examples/trade-risk.py. Here it would return the portfolio value and a dict of sensitivities keyed by input name (e.g."rate 1999-04-27","strike 40","underlying 36","dividend yield"), and the script calls it and prints the results as now. That keeps the examples consistent and lets readers reuse the calculation from their own code or a notebook. - CHANGELOG: add a line under
## [Unreleased]/### Added, e.g. "Exampleeuropean-option-adjoint.py: sensitivities of a European option portfolio to all market inputs in one adjoint pass". - CLA: please sign it (link in the CLA check on this PR); we can't merge before it's signed.
The same points apply to #24, #25 and #26 (run on QuantLibAAD 1.44.0, rebase, central-difference check over all inputs, an aad_sensitivities() function, a CHANGELOG line each), so please work through them there too, rather than us repeating them. Two things specific to those:
- #24 (American option): QuantLibAAD 1.44.0 fixes the zero dividend rho with finite-difference engines that your notes describe, so on 1.44.0 the adjoint dividend rho should match the bumped one. Please remove that caveat from the example and include the dividend yield in the check.
- #26 (Heston): please run the calibration with
COSHestonEngineas written, rather than the analytic engine you used locally, and include all sensitivities in the check, not only the eight largest.
Once these are in, we'll run our checks and review all four again.
Rebase onto current main and address review: run against QuantLibAAD 1.44.0, move the AAD computation into aad_sensitivities() returning the portfolio value and a dict of sensitivities keyed by input name, replace the forward-difference check with central differences over all 98 inputs, and add a CHANGELOG entry. Run on QuantLibAAD 1.44.0: portfolio value 9481.90744; largest relative difference over all 98 inputs 6.6e-08 (strike 33).
613e782 to
7249324
Compare
|
Review points addressed:
The CLA is still unsigned on my side; that is separate from these changes. |
|
Thanks for the quick turnaround, Tyler, and for running this on QuantLibAAD 1.44.0. We can't review or merge contributions without a signed CLA, so that's the one thing holding this PR up. It takes a minute: the link is in the bot comment at the top. If you've signed and the check still shows pending, the "recheck" link next to it refreshes it. If something about the CLA is a concern, tell us and we'll sort it out. Once it's signed, we'll go through this one straight away. One small thing meanwhile: the PR description still mentions the 1.33.3 run, so please update it to match your latest comment. |
Closes #15.
Python port of the
AdjointEuropeanEquityOptionC++ example, following the pattern ofswap-adjoint.py:aad_sensitivities()function returning the portfolio value and a dict of sensitivities keyed by input name. The example cross-checks the adjoints against central differences (h = 1e-5) over all 98 inputs at the end.Testing: run on QuantLibAAD 1.44.0 (Python 3.12): portfolio value 9481.90744, largest relative difference over all 98 inputs: 6.6e-08 (strike 33).
Note: this repo requires a signed CLA before merge (per CONTRIBUTING) — I understand it will be handled through the CLA flow.