Skip to content

Commit

Permalink
BUG: returning an NPV of STIR future when supplying an FX. (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
attack68 authored Jan 25, 2025
1 parent e7e4c8d commit a9f5021
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/rateslib/instruments/rates/single_currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def npv(
else:
traded_price = 100 - self.fixed_rate
_ = (mid_price - traded_price) * 100 * self.kwargs["contracts"] * self.kwargs["bp_value"]
return _maybe_local(_, local, self.kwargs["currency"], fx, base)
return _maybe_local(_, local, self.leg1.currency, fx, base)

def rate(
self,
Expand Down
19 changes: 19 additions & 0 deletions python/tests/test_instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3343,6 +3343,25 @@ def test_stir_npv(self) -> None:
expected = (99.5 - (100 - 0.99250894761)) * 2500 * -1.0
assert abs(result - expected) < 1e-7

def test_stir_npv_currency_bug(self) -> None:
# GH : instantiation without a currency failed to NPV when an fx object provided.
c1 = Curve({dt(2022, 1, 1): 1.0, dt(2023, 1, 1): 0.99})
c2 = Curve({dt(2022, 1, 1): 1.0, dt(2023, 1, 1): 0.98})
c3 = Curve({dt(2022, 1, 1): 1.0, dt(2023, 1, 1): 0.97})
fxf = FXForwards(
FXRates({"eurusd": 1.1}, dt(2022, 1, 1)),
{"eureur": c1, "eurusd": c2, "usdusd": c3}
)
stir = STIRFuture(
effective=dt(2022, 3, 16),
termination=dt(2022, 6, 15),
frequency="Q",
bp_value=25.0,
contracts=-1,
)
result = stir.npv(curves=[c1, c1, c2, c3], fx=fxf)
assert abs(result) < 1e-7

def test_stir_npv_fx(self) -> None:
c1 = Curve({dt(2022, 1, 1): 1.0, dt(2023, 1, 1): 0.99}, id="usdusd")
# irs = IRS(dt(2022, 3, 16), dt(2022, 6, 15), "Q", curves="usdusd")
Expand Down

0 comments on commit a9f5021

Please sign in to comment.