Skip to content

Commit

Permalink
Merge branch 'main' into refactor-splines
Browse files Browse the repository at this point in the history
  • Loading branch information
attack68 committed Jan 3, 2025
2 parents 201800d + 0a9b786 commit f49e315
Show file tree
Hide file tree
Showing 11 changed files with 790 additions and 489 deletions.
1 change: 1 addition & 0 deletions docs/source/i_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ independently by providing basic inputs.
},
index_base=308.95,
index_lag=3,
interpolation="linear_index",
id="us_cpi",
)
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ exclude = [
"/instruments",
"fx_volatility.py",
"legs.py",
"periods.py",
"solver.py",
]
strict = true
Expand Down
4 changes: 2 additions & 2 deletions python/rateslib/curves/curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -3058,7 +3058,7 @@ def _get_node_vector(self) -> Arr1dF64 | Arr1dObj: # pragma: no cover

def average_rate(
effective: datetime, termination: datetime, convention: str, rate: DualTypes
) -> tuple[DualTypes, float, int]:
) -> tuple[Number, float, int]:
"""
Return the geometric, 1 calendar day, average rate for the rate in a period.
Expand All @@ -3081,7 +3081,7 @@ def average_rate(
"""
d: float = _DCF1d[convention.upper()]
n: int = (termination - effective).days
_: DualTypes = ((1 + n * d * rate / 100) ** (1 / n) - 1) / d
_: Number = ((1 + n * d * rate / 100) ** (1 / n) - 1) / d
return _ * 100, d, n


Expand Down
2 changes: 1 addition & 1 deletion python/rateslib/dual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


def _dual_float(val: DualTypes) -> float:
"""Overload for the float() builtin to handle Pyo3 issues with Variabe"""
"""Overload for the float() builtin to handle Pyo3 issues with Variable"""
try:
return float(val) # type: ignore[arg-type]
except TypeError as e: # val is not Number but a Variable
Expand Down
12 changes: 7 additions & 5 deletions python/rateslib/fx_volatility.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(
self.expiry = expiry
self.t_expiry = (expiry - eval_date).days / 365.0
self.t_expiry_sqrt = self.t_expiry**0.5
self.delta_type = _validate_delta_type(delta_type)
self.delta_type: str = _validate_delta_type(delta_type)

self.__set_nodes__(nodes, ad)

Expand Down Expand Up @@ -196,7 +196,7 @@ def get_from_strike(
w_deli: DualTypes | NoInput = NoInput(0),
w_spot: DualTypes | NoInput = NoInput(0),
expiry: datetime | NoInput(0) = NoInput(0),
) -> tuple:
) -> tuple[DualTypes, DualTypes, DualTypes]:
"""
Given an option strike return associated delta and vol values.
Expand Down Expand Up @@ -820,7 +820,7 @@ def __init__(
raise ValueError("Surface `expiries` are not sorted or contain duplicates.\n")

self.delta_indexes = delta_indexes
self.delta_type = _validate_delta_type(delta_type)
self.delta_type: str = _validate_delta_type(delta_type)
self.smiles = [
FXDeltaVolSmile(
nodes=dict(zip(self.delta_indexes, node_values[i, :], strict=False)),
Expand Down Expand Up @@ -893,7 +893,7 @@ def _get_node_vars(self):
vars += tuple(f"{smile.id}{i}" for i in range(smile.n))
return vars

def get_smile(self, expiry: datetime):
def get_smile(self, expiry: datetime) -> FXDeltaVolSmile:
"""
Construct a *DeltaVolSmile* with linear total variance interpolation over delta indexes.
Expand Down Expand Up @@ -1352,7 +1352,9 @@ def _d_plus(K: DualTypes, f: DualTypes, vol_sqrt_t: DualTypes) -> DualTypes:
return _d_plus_min(K, f, vol_sqrt_t, +0.5)


def _delta_type_constants(delta_type, w, u):
def _delta_type_constants(
delta_type: str, w: DualTypes, u: DualTypes
) -> tuple[float, DualTypes, DualTypes]:
"""
Get the values: (eta, z_w, z_u) for the type of expressed delta
Expand Down
20 changes: 15 additions & 5 deletions python/rateslib/legs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,13 +1084,17 @@ def index_fixings(self, value):
for i, period in enumerate(self.periods):
if isinstance(period, IndexFixedPeriod | IndexCashflow):
if isinstance(value, Series):
_ = IndexMixin._index_value(
val: DualTypes | None = IndexMixin._index_value(
i_fixings=value,
i_method=self.index_method,
i_lag=self.index_lag,
i_date=period.end,
i_curve=NoInput(0), # ! NoInput returned for periods beyond Series end.
)
if val is None:
_: DualTypes | NoInput = NoInput(0)
else:
_ = val
elif isinstance(value, list):
if i >= len(value):
_ = NoInput(0) # some fixings are unknown, list size is limited
Expand All @@ -1106,20 +1110,26 @@ def index_base(self):
return self._index_base

@index_base.setter
def index_base(self, value):
def index_base(self, value: DualTypes | Series[DualTypes] | NoInput) -> None:
if isinstance(value, Series):
value = IndexMixin._index_value(
_: DualTypes | None = IndexMixin._index_value(
i_fixings=value,
i_method=self.index_method,
i_lag=self.index_lag,
i_date=self.schedule.effective,
i_curve=NoInput(0), # not required because i_fixings is Series
)
self._index_base = value
if _ is None:
ret: DualTypes | NoInput = NoInput(0)
else:
ret = _
else:
ret = value
self._index_base = ret
# if value is not None:
for period in self.periods:
if isinstance(period, IndexFixedPeriod | IndexCashflow):
period.index_base = value
period.index_base = self._index_base


class ZeroFloatLeg(BaseLeg, _FloatLegMixin):
Expand Down
Loading

0 comments on commit f49e315

Please sign in to comment.