Commit b9623a1
authored
Closed-form Greeks for the Black-76 (Black 1976) model, complementing the
pricing kernel landed in #398. Black-76 prices options on futures, forwards,
swaptions, caps/floors, and commodity futures — anywhere the underlying is a
forward price `F` with the cost of carry already baked in. The Greeks share
the same `e^(-rT)` discount factor across both legs and ignore
`dividend_yield` (since `F` is carry-adjusted).
Public surface (`src/greeks/black_76.rs`):
- `delta_b76`, `gamma_b76`, `vega_b76`, `theta_b76`, `rho_b76`
- `Black76Greeks` trait mirroring the `Black76` pricing trait — implementors
provide `get_option(&self)` and inherit default delegations to the free
functions above.
Units mirror the BSM module: vega per 1 % vol, theta per calendar day
(annual ÷ 365), rho per 1 % rate (annual ÷ 100). Quantity scales linearly;
`Side::Short` flips the delta sign only (consistent with `greeks::delta`).
Promoted `calculate_d_values_black_76` from `pub(crate)` to `pub` so external
crates and the new module can share the helper.
Formulas use the complete Hull (10th ed., Ch. 18) expressions. Note that the
issue's formula for theta and rho omitted the `r·F·e^(-rT)·N(d1)` and
F-leg discount terms; this implementation follows Hull rigorously and the
relationship `ρ = -T · price` is verified analytically and by test.
Tests (21, all passing):
- Delta range: call ∈ (0,1), put ∈ (-1,0)
- Identity `Δ_call − Δ_put = e^(-rT)` to 1e-9
- Gamma > 0, Vega > 0 across multiple strikes
- Gamma and Vega are call/put symmetric
- Theta < 0 for long ATM call/put (decay)
- `ρ = -T · price / 100` analytic identity
- BSM cross-check via `S = F·e^(-rT)`, `q = 0`:
- `Δ_b76 = e^(-rT) · Δ_bsm` to 1e-9
- `ν_b76 = ν_bsm` to 1e-9
- `Γ_b76 = e^(-2rT) · Γ_bsm` to 1e-9
- Hull ATM-call reference (F=K=20, r=0.09, T≈1/3, σ=0.25) → Δ ≈ 0.5132
- Zero volatility → error
- American / Bermuda / exotic → `GreeksError::Pricing(UnsupportedOptionType)`
- Trait impl, side negation, quantity scaling
Example: `examples/examples_pricing/src/bin/black_76_greeks.rs` walks ATM /
ITM / OTM calls and puts on a 6-month CL futures contract, prints all
Greeks, demonstrates the call-minus-put identity and trait usage.
Closes #400.
1 parent 6cc3226 commit b9623a1
5 files changed
Lines changed: 866 additions & 5 deletions
File tree
- examples/examples_pricing
- src/bin
- src/greeks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
0 commit comments