Skip to content

Skip the caplets and floorlets already paid in IborCapFloor.value - #501

Open
QuantIntellect wants to merge 1 commit into
FinancePy-Org:masterfrom
QuantIntellect:fix/cap-floor-seasoned
Open

QuantIntellect wants to merge 1 commit into
FinancePy-Org:masterfrom
QuantIntellect:fix/cap-floor-seasoned

Conversation

@QuantIntellect

Copy link
Copy Markdown
Contributor

IborCapFloor.value values the first caplet or floorlet from start_dt and every later one from its own dates, without comparing them with value_dt (ibor_cap_floor.py#L165-L174, #L197-L203). Once the first payment date has passed, libor_curve.df(end_dt) asks the curve for a date before its anchor and raises, so a cap or floor can't be valued after its first payment, with any model:

value_dt = Date(2, 7, 2025)
curve = FlatDiscountCurve(value_dt, 0.04)
cap = IborCapFloor(Date(16, 6, 2023), Date(16, 6, 2028), CapFloorTypes.CAP, 0.03, 0.035)
cap.value(value_dt, curve, Black(0.20))   # FinError: Negative time period

The same contract described from the start of its current period, IborCapFloor(Date(16, 6, 2025), Date(16, 6, 2028), ...), has the same caplets left to pay and values fine, so the two should agree:

from 16-Jun-2025 from 16-Jun-2023, master from 16-Jun-2023, this PR
Cap, Black 28712.1954 raises 28712.1954
Cap, Bachelier 29347.0476 raises 29347.0476
Cap, HWTree 30479.0937 raises 30479.0937
Floor, Black 1240.2950 raises 1240.2950
Floor, Bachelier 1875.1472 raises 1875.1472
Floor, HWTree 3007.1933 raises 3007.1933

Change

Caplets and floorlets paid on or before value_dt are skipped. Their entries in the caplet lists are 0.0, so the lists still line up with caplet_floorlet_dates. The first unpaid one is valued the way the first caplet was, from last_fixing when it is given, and a cap or floor whose last payment has passed is worth 0.0. This follows SwapFloatLeg.value, which counts a payment on the value date as paid and applies first_fixing_rate to the first unpaid period (swap_float_leg.py#L196-L204), and #445, which did the same for the swaps in products/rates/swaps.

Two things change for existing users, and they are your call:

  • last_fixing is now the fixing of the period that holds value_dt, not always of the first period. Before the first payment they are the same period, so nothing changes there.
  • On a payment date the caplet paid that day is no longer counted. For the cap from 16-Jun-2025 valued on its first payment date, 16-Sep-2025, master gives 28750.8687, including that day's caplet at 1250.0000 (undiscounted, at last_fixing). This PR gives 26215.9701, with last_fixing applied to the period starting that day.

Without last_fixing, a seasoned cap still raises, as master already does once the first period has started: the current period's rate can't be implied from a curve that starts after it was fixed.

Tests

tests/unit/test_cap_floor_seasoned.py (new):

  • for a cap and a floor with Black, Bachelier and HWTree, the contract described from its trade date values the same as from its current period (6 cases);
  • the caplets already paid are 0.0, and the current one is 1e6 × α × (3.5% − 3%) × df;
  • after the last payment the cap is worth 0.0.

All 8 fail on master and pass with the change. The rest of tests/unit gives the same result as at ef59d2a, which this branch is on: 2,134 pass, and the 2 test_inflation_swap.py tests that failed there fail the same way (fixed on master since, in 4477109). regression_test_ibor_cap_floor.py gives the same output as on master. I ran these with numba 0.68.1, numpy 2.3.5, scipy 1.17.1 and pandas 2.3.3.

value took the first caplet from start_dt and the others from their own
dates without comparing them with value_dt, so once the first payment date
had passed libor_curve.df(end_dt) asked for a date before the curve anchor
and raised "Negative time period", with every model.

Caplets and floorlets paid on or before value_dt are now worth 0.0, and the
first unpaid one is valued as the first caplet was, from last_fixing when
it is given, as SwapFloatLeg.value does with first_fixing_rate. A cap or
floor whose last payment has passed is worth 0.0.

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.

1 participant