aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/analytics/tranche_basket.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index 38114670..b2faecea 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -1,3 +1,4 @@
+from __future__ import annotations
from .basket_index import BasketIndex
from .tranche_functions import (
credit_schedule,
@@ -45,6 +46,14 @@ import warnings
logger = logging.getLogger(__name__)
+class dSkew:
+ __slots__ = ("s1", "s2")
+
+ def __init__(self, skew1: CubicSpline, skew2: CubicSpline):
+ self.s1 = skew1.skew_fun
+ self.s2 = skew2.skew_fun
+
+
class Skew:
_cache = LRU(64)
@@ -56,8 +65,20 @@ class Skew:
yield self.el
yield self.skew_fun
- def __call__(self, k):
- return expit(self.skew_fun(np.log(k)))
+ def __call__(self, moneyness):
+ return expit(self.skew_fun(np.log(moneyness)))
+
+ def __add__(self, dS: dSkew) -> Callable:
+ def newSkew(moneyness):
+ lmoneyness = np.log(moneyness)
+ return expit(
+ self.skew_fun(lmoneyness) + dS.s2(lmoneyness) - dS.s1(lmoneyness)
+ )
+
+ return newSkew
+
+ def __sub__(self, other: Skew) -> dSkew:
+ return dSkew(other, self)
@classmethod
def from_desc(