diff --git a/financepy/market/curves/ois_curve.py b/financepy/market/curves/ois_curve.py index 93665ec3..fd365ed9 100644 --- a/financepy/market/curves/ois_curve.py +++ b/financepy/market/curves/ois_curve.py @@ -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: @@ -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() diff --git a/financepy/products/rates/ois_curve.py b/financepy/products/rates/ois_curve.py index e2476ca1..ed44cb65 100644 --- a/financepy/products/rates/ois_curve.py +++ b/financepy/products/rates/ois_curve.py @@ -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: @@ -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", diff --git a/tests/unit/test_ois_refit.py b/tests/unit/test_ois_refit.py new file mode 100644 index 00000000..fea9ae91 --- /dev/null +++ b/tests/unit/test_ois_refit.py @@ -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)