merton.greeks.autodiff¶
Autodiff Greeks via JAX.
Each Greek is computed by composing jax.grad() with the BSM equity
or PD expression, then jax.vmap() to vectorise across input arrays
and jax.jit() to compile the result. This is useful for:
Validating the closed-form Greeks in
merton.greeks.equityandmerton.greeks.pd_sensitivity(they should agree to ~1e-7).Differentiating novel BSM extensions where deriving Greeks by hand is error-prone.
The module is only importable when merton[jax] is installed; importing
it without JAX raises a clean ImportError.
Examples
>>> from merton.greeks import autodiff
>>> import numpy as np
>>> A = np.array([100.0, 150.0, 80.0])
>>> autodiff.equity_delta_ad(A, 0.25, 60.0, 0.04, 1.0)
Functions¶
|
∂E/∂A via JAX autodiff. |
|
∂E/∂σ_A via JAX autodiff. |
|
∂²E/∂A² via JAX autodiff (gradient of the delta). |
|
Theta as |
|
∂E/∂r via JAX autodiff. |
|
∂PD/∂D via JAX autodiff. |
|
∂PD/∂σ_A via JAX autodiff. |
|
∂PD/∂r via JAX autodiff. |
Module Contents¶
- merton.greeks.autodiff.equity_delta_ad(asset_value, asset_vol, debt, rf, T, *, dividend_yield=0.0)[source]¶
∂E/∂A via JAX autodiff.
- merton.greeks.autodiff.equity_vega_ad(asset_value, asset_vol, debt, rf, T, *, dividend_yield=0.0)[source]¶
∂E/∂σ_A via JAX autodiff.
- merton.greeks.autodiff.equity_gamma_ad(asset_value, asset_vol, debt, rf, T, *, dividend_yield=0.0)[source]¶
∂²E/∂A² via JAX autodiff (gradient of the delta).
- merton.greeks.autodiff.equity_theta_ad(asset_value, asset_vol, debt, rf, T, *, dividend_yield=0.0)[source]¶
Theta as
∂E/∂t(i.e.-∂E/∂T) — matches the option-pricing convention used bymerton.greeks.equity_theta()so the autodiff and closed-form columns line up sign-wise.
- merton.greeks.autodiff.equity_rho_ad(asset_value, asset_vol, debt, rf, T, *, dividend_yield=0.0)[source]¶
∂E/∂r via JAX autodiff.
- merton.greeks.autodiff.pd_leverage_sensitivity_ad(asset_value, asset_vol, debt, rf, T, *, dividend_yield=0.0)[source]¶
∂PD/∂D via JAX autodiff.