aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics/tranche_functions.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics/tranche_functions.py')
-rw-r--r--python/analytics/tranche_functions.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/python/analytics/tranche_functions.py b/python/analytics/tranche_functions.py
index 16661b41..d4c38097 100644
--- a/python/analytics/tranche_functions.py
+++ b/python/analytics/tranche_functions.py
@@ -68,8 +68,8 @@ libloss.BCloss_recov_trunc.argtypes = [
POINTER(c_int), # Ngrid
POINTER(c_double), #K
POINTER(c_int), #defaultflag
- ndpointer('double', ndim=1, flags='F,writeable'),# output L
- ndpointer('double', ndim=1, flags='F,writeable')# output R
+ ndpointer('double', ndim=1, flags='F,writeable'),# output EL
+ ndpointer('double', ndim=1, flags='F,writeable')# output ER
]
libloss.lossdistrib_joint.restype = None
@@ -300,15 +300,39 @@ def tranche_cl(L, R, cs, K1, K2, scaled=False):
else:
return np.dot(sizeadj * cs["coupons"], cs["df"])
+def tranche_cl_trunc(EL, ER, cs, K1, K2, scaled=False):
+ if(K1 == K2):
+ return 0.
+ else:
+ size = EL - ER
+ dK = K2 - K1
+ sizeadj = 0.5 * (size + np.hstack((dK, size[:-1])))
+ if scaled:
+ return 1 / dK * np.dot(sizeadj * cs["coupons"], cs["df"])
+ else:
+ return np.dot(sizeadj * cs["coupons"], cs["df"])
+
def tranche_pl(L, cs, K1, K2, scaled=False):
if(K1 == K2):
return 0
else:
+ dK = K2 - K1
support = np.linspace(0, 1, L.shape[0])
- cf = K2 - K1 - np.dot(trancheloss(support, K1, K2), L)
- cf = np.hstack((K2-K1, cf))
+ cf = dK - np.dot(trancheloss(support, K1, K2), L)
+ cf = np.hstack((dK, cf))
+ if scaled:
+ return 1 / dK * np.dot(np.diff(cf), cs["df"])
+ else:
+ return np.dot(np.diff(cf), cs["df"])
+
+def tranche_pl_trunc(EL, cs, K1, K2, scaled=False):
+ if(K1 == K2):
+ return 0
+ else:
+ dK = K2 - K1
+ cf = np.hstack((dK, EL))
if scaled:
- return 1/(K2-K1) * np.dot(np.diff(cf), cs["df"])
+ return 1 / dK * np.dot(np.diff(cf), cs["df"])
else:
return np.dot(np.diff(cf), cs["df"])