diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/analytics/option.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/python/analytics/option.py b/python/analytics/option.py index c423f15c..28aad20f 100644 --- a/python/analytics/option.py +++ b/python/analytics/option.py @@ -55,7 +55,7 @@ def ATMstrike(index, exercise_date): class BlackSwaption(ForwardIndex): """Swaption class""" - __slots__ = ('_T', '_G', '_strike', 'option_type', + __slots__ = ('_T', '_G', '_strike', 'option_type', '_orig_params', 'notional', 'sigma', '_original_pv', '_direction') def __init__(self, index, exercise_date, strike, option_type="payer", @@ -68,6 +68,7 @@ class BlackSwaption(ForwardIndex): self.sigma = None self._original_pv = None self.direction = direction + self._orig_params = (strike, index.factor, index.cumloss) self.index.observe(self) def __setstate__(self, state): @@ -90,6 +91,7 @@ class BlackSwaption(ForwardIndex): instance.notional = rec.notional instance.pv = rec.price * 1e-2 * rec.notional * (2 * rec.buysell - 1) instance._original_pv = instance.pv + instance._orig_params = (rec.strike, index.factor, index.cumloss) return instance def mark(self, source_list=[], surface_id=None, **args): @@ -118,6 +120,12 @@ class BlackSwaption(ForwardIndex): @value_date.setter def value_date(self, d): self.index.value_date = d + strike, factor, cumloss = self._orig_params + if factor != self.index.factor: + cum_recovery = 100 * (factor - self.index.factor) - \ + (self.index.cumloss - cumloss) + temp = (strike - cum_recovery) / self.index.factor + self.strike = (strike - cum_recovery) / self.index.factor @property def exercise_date(self): @@ -186,8 +194,8 @@ class BlackSwaption(ForwardIndex): return self._direction * intrinsic * self.notional def __hash__(self): - return hash((super().__hash__(), tuple(getattr(self, k) for k in - BlackSwaption.__slots__))) + return hash((hash(super()), tuple(getattr(self, k) for k in + BlackSwaption.__slots__))) @property def pv(self): @@ -201,7 +209,7 @@ class BlackSwaption(ForwardIndex): strike_tilde, self.T, self.sigma, - self.option_type == "payer") * self.notional + self.option_type == "payer") * self.notional * self.index.factor @property def tail_prob(self): |
