Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions financepy/market/curves/ois_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def _build_curve_linear_swap_rate_interpolation(self):
####################################################################################

def check_refit(self, fra_tol, swap_tol):
"""Ensure that the Libor curve refits the calibration instruments.
"""Ensure that the OIS curve refits its calibration instruments.
We omit deposits as these are fitted exactly in the bootstrap."""

for fra in self.used_fras:
Expand All @@ -590,9 +590,9 @@ def check_refit(self, fra_tol, swap_tol):
raise FinError("FRA not repriced.")

for swap in self.used_swaps:
# We value it as of the start date of the swap
v = swap.value(self.anchor_dt, self, self, None, principal=0.0)
v = v / swap.notional
# Use the same single-curve valuation as the bootstrap objective.
v = swap.value(self.anchor_dt, self)
v = v / swap.fixed_leg.notional
if abs(v) > swap_tol:
swap.print_fixed_leg_pv()
swap.print_float_leg_pv()
Expand Down
8 changes: 4 additions & 4 deletions financepy/products/rates/ois_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def _build_curve_linear_swap_rate_interpolation(self):
####################################################################################

def check_refit(self, fra_tol, swap_tol):
"""Ensure that the Libor curve refits the calibration instruments.
"""Ensure that the OIS curve refits its calibration instruments.
We omit deposits as these are fitted exactly in the bootstrap."""

for fra in self.used_fras:
Expand All @@ -592,9 +592,9 @@ def check_refit(self, fra_tol, swap_tol):
raise FinError("FRA not repriced.")

for swap in self.used_swaps:
# We value it as of the start date of the swap
v = swap.value(self.anchor_dt, self, self, None, principal=0.0)
v = v / swap.notional
# Use the same single-curve valuation as the bootstrap objective.
v = swap.value(self.anchor_dt, self)
v = v / swap.fixed_leg.notional
if abs(v) > swap_tol:
print(
"Swap with maturity " + str(swap.maturity_dt) + " Not Repriced. Has Value",
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/test_ois_refit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Regression for optional repricing of OIS calibration instruments."""

import pytest

from financepy.market.curves.ois_curve import OISCurve
from financepy.products.rates.ois_curve import OISCurve as LegacyOISCurve
from financepy.products.rates.ois import OIS
from financepy.utils.date import Date
from financepy.utils.day_count import DayCountTypes
from financepy.utils.error import FinError
from financepy.utils.frequency import FrequencyTypes
from financepy.utils.global_types import SwapTypes


@pytest.mark.parametrize("curve_class", (OISCurve, LegacyOISCurve))
def test_ois_curve_reprices_with_optional_check(curve_class):
anchor = Date(3, 1, 2024)
swaps = [
OIS(anchor, tenor, SwapTypes.PAY, quote, FrequencyTypes.ANNUAL,
DayCountTypes.ACT_360, notional=10.0)
for tenor, quote in (("1Y", 0.025), ("2Y", 0.028))
]
curve = curve_class(anchor, [], [], swaps, check_refit_flag=True)
for swap in swaps:
assert abs(swap.value(anchor, curve)) / swap.fixed_leg.notional < 1e-8


def test_ois_curve_check_still_rejects_off_market_swap():
anchor = Date(3, 1, 2024)
dc = DayCountTypes.ACT_360
swap = OIS(anchor, "1Y", SwapTypes.PAY, 0.025, FrequencyTypes.ANNUAL, dc)
curve = OISCurve(anchor, [], [], [swap])
curve.used_swaps[0] = OIS(anchor, "1Y", SwapTypes.PAY, 0.04, FrequencyTypes.ANNUAL, dc)
with pytest.raises(FinError, match="Swap not repriced"):
curve.check_refit(1e-5, 1e-5)