From 15f143805a9f2848310f6aca9fc6196a2e5847b5 Mon Sep 17 00:00:00 2001 From: JHM Darbyshire <24256554+attack68@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:40:45 +0100 Subject: [PATCH] drop unnecessary path and return path args --- python/rateslib/curves/curves.py | 6 +++--- python/rateslib/fx/fx_forwards.py | 28 +++++----------------------- python/tests/test_fx.py | 2 +- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/python/rateslib/curves/curves.py b/python/rateslib/curves/curves.py index 2d8bc273..2fe9acdb 100644 --- a/python/rateslib/curves/curves.py +++ b/python/rateslib/curves/curves.py @@ -23,7 +23,7 @@ from rateslib.calendars.dcfs import _DCF1d from rateslib.calendars.rs import Modifier, _get_calendar_with_kind from rateslib.default import NoInput, _drb, plot -from rateslib.dual import Dual, Dual2, DualTypes, dual_exp, dual_log, set_order_convert +from rateslib.dual import Dual, Dual2, DualTypes, dual_exp, dual_log, set_order_convert, Number from rateslib.rs import index_left_f64 from rateslib.splines import PPSplineDual, PPSplineDual2, PPSplineF64 @@ -2813,9 +2813,9 @@ def __init__( self.calendar = default_curve.calendar self.node_dates = [self.fx_forwards.immediate, self.terminal] - def __getitem__(self, date: datetime): + def __getitem__(self, date: datetime) -> Number: return ( - self.fx_forwards.rate(self.pair, date, path=self.path) + self.fx_forwards._rate_with_path(self.pair, date, path=self.path)[0] / self.fx_forwards.fx_rates_immediate.fx_array[self.cash_idx, self.coll_idx] * self.fx_forwards.fx_curves[self.coll_pair][date] ) diff --git a/python/rateslib/fx/fx_forwards.py b/python/rateslib/fx/fx_forwards.py index 4e6922d4..c2d02672 100644 --- a/python/rateslib/fx/fx_forwards.py +++ b/python/rateslib/fx/fx_forwards.py @@ -521,6 +521,7 @@ def rate( f_{DOMFOR, i} = f_{DOMALT, i} ... f_{ALTFOR, i} """ # noqa: E501 + return self._rate_with_path(pair, settlement)[0] def _rate_with_path( self, @@ -546,27 +547,8 @@ def _rate_with_path( Returns ------- - float, Dual, Dual2 or tuple - - Notes - ----- - Uses the formula, - - .. math:: - - f_{DOMFOR, i} = \\frac{w_{dom:for, i}}{v_{for:for, i}} F_{DOMFOR,0} = \\frac{v_{dom:dom, i}}{w_{for:dom, i}} F_{DOMFOR,0} - - where :math:`v` is a local currency discount curve and :math:`w` is a discount - curve collateralised with an alternate currency. - - Where curves do not exist in the relevant currencies we chain rates available - given the available curves. - - .. math:: - - f_{DOMFOR, i} = f_{DOMALT, i} ... f_{ALTFOR, i} - - """ # noqa: E501 + tuple + """ def _get_d_f_idx_and_path( pair: str, path: list[dict[str, int]] | NoInput @@ -913,7 +895,7 @@ def _full_curve(self, cashflow: str, collateral: str) -> Curve: days = (end - self.immediate).days nodes = { k: ( - self._rate_with_path(f"{cash_ccy}{coll_ccy}", k, path=path) + self._rate_with_path(f"{cash_ccy}{coll_ccy}", k, path=path)[0] / self.fx_rates_immediate.fx_array[cash_idx, coll_idx] * self.fx_curves[f"{coll_ccy}{coll_ccy}"][k] ) @@ -1052,7 +1034,7 @@ def plot( points: int = (right_ - left_).days x = [left_ + timedelta(days=i) for i in range(points)] _, path = self._rate_with_path(pair, x[0]) - rates: list[DualTypes] = [self._rate_with_path(pair, _, path=path) for _ in x] + rates: list[DualTypes] = [self._rate_with_path(pair, _, path=path)[0] for _ in x] if not fx_swap: y: list[Number] = [rates] else: diff --git a/python/tests/test_fx.py b/python/tests/test_fx.py index 4b4cfc52..812ffa6c 100644 --- a/python/tests/test_fx.py +++ b/python/tests/test_fx.py @@ -789,7 +789,7 @@ def test_rate_path_immediate(settlement) -> None: "nokeur": nokeur, }, ) - _, result = fxf.rate("nokusd", settlement, return_path=True) + _, result = fxf._rate_with_path("nokusd", settlement) expected = [{"col": 1}, {"col": 2}] assert result == expected