Skip to content

feat(itofin-py): expose CapFloor instrument to Python - #629

Merged
benbenbang merged 4 commits into
mainfrom
fable/621
Jul 27, 2026
Merged

feat(itofin-py): expose CapFloor instrument to Python#629
benbenbang merged 4 commits into
mainfrom
fable/621

Conversation

@benbenbang

@benbenbang benbenbang commented Jul 27, 2026

Copy link
Copy Markdown
Owner

close #621

Add Python bindings for cap and floor instruments built through the
standard MakeCapFloor market builder. The new `CapFloor` and
`CapFloorType` classes are registered in the `instruments` module.

**New instrument bindings:**
* Added `crates/itofin-py/src/capfloor.rs` implementing `PyCapFloor` and
  `PyCapFloorType`, registered in `lib.rs` under the `instruments` module.
* The `Collar` variant is intentionally not exposed since it has no
  construction path from Python yet.

**Stubs and tests:**
* Updated `instruments.pyi` with hand-written stubs for `CapFloor` and
  `CapFloorType`, documenting the unit-nominal single-strike leg and the
  zero forward-start behavior that avoids a historical index fixing.
* Added `tests/test_capfloor.py` covering the new instrument.
This change adds Python bindings for caplet/floorlet volatility surfaces,
making them available under the `termstructures` module.

**New optionlet volatility bindings:**
* Added `crates/itofin-py/src/optionletvol.rs` implementing
  `PyOptionletVolatilityStructure` and `PyConstantOptionletVolatility`.
* Registered both classes in the `termstructures` module in `lib.rs`.
* `OptionletVolatilityStructure` exposes `volatility`, `volatility_date`,
  `black_variance`, and `displacement` on a single option axis.
* `ConstantOptionletVolatility` provides a fixed-reference constructor and
  a quote-backed `with_quote` factory that tracks its `SimpleQuote`.

**Stubs and tests:**
* Extended `termstructures.pyi` with hand-written stubs for the new classes.
* Added tests covering constant volatility queries, Black variance, and
  quote-backed surfaces reacting to `set_value`.
Expose the shifted-lognormal Black cap/floor engine to Python and wire it
into cap/floor instruments so each optionlet prices off an optionlet
volatility surface.

* Add the `PyBlackCapFloorEngine` binding with a surface-handle constructor
  and a `with_flat_vol` builder, registered under `pricingengines`.
* Add `set_black_engine` on `CapFloor` to attach the engine, requiring it to
  resolve dates against the same `Settings` object as the instrument.
* Reject normal-volatility surfaces and displacements that disagree with the
  surface's own shift.
* Add Python tests covering finite/positive NPVs, strike sensitivity,
  volatility sensitivity, constructor equivalence, and validation errors.
* Update the `instruments` and `pricingengines` type stubs.

Closes #621
@benbenbang
benbenbang enabled auto-merge (rebase) July 27, 2026 05:14
@github-actions github-actions Bot added the enhancement New feature or request label Jul 27, 2026
@benbenbang
benbenbang merged commit 92b26ee into main Jul 27, 2026
3 of 6 checks passed
@benbenbang
benbenbang deleted the fable/621 branch July 27, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[D7][itofin-py] Pass B1: PyCapFloor + PyBlackCapFloorEngine (#605)

1 participant