Skip to content

Commit

Permalink
REF: add hash to FXDeltaVolSmile (#576)
Browse files Browse the repository at this point in the history
Co-authored-by: JHM Darbyshire (M1) <attack68@users.noreply.github.com>
  • Loading branch information
attack68 and attack68 authored Dec 26, 2024
1 parent 53cc6a2 commit 5bf705a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions python/rateslib/curves/curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -2537,8 +2537,7 @@ def index_value(self, date: datetime, interpolation: str = "daily") -> DualTypes
def _get_node_vector(self) -> Arr1dObj | Arr1dF64:
raise NotImplementedError("Instances of CompositeCurve do not have solvable variables.")

@property
def _state_id_composited(self) -> int:
def _composited_hashes(self) -> int:
return hash(sum(hash(curve) for curve in self.curves))

def _clear_cache(self) -> None:
Expand All @@ -2556,10 +2555,10 @@ def _clear_cache(self) -> None:
invalidates the cache on a composite curve.
"""
self._cache: dict[datetime, DualTypes] = dict()
self._state_id = self._state_id_composited
self._state_id = self._composited_hashes()

def _validate_cache(self) -> None:
if self._state_id != self._state_id_composited:
if hash(self) != self._composited_hashes():
# If any of the associated curves have been mutated then the cache is invalidated
self._clear_cache()

Expand Down

0 comments on commit 5bf705a

Please sign in to comment.