Skip to content

Commit

Permalink
drop unnecessary path and return path args
Browse files Browse the repository at this point in the history
  • Loading branch information
attack68 committed Dec 6, 2024
1 parent b8cc504 commit 15f1438
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
6 changes: 3 additions & 3 deletions python/rateslib/curves/curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
)
Expand Down
28 changes: 5 additions & 23 deletions python/rateslib/fx/fx_forwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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]
)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_fx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 15f1438

Please sign in to comment.