aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics')
-rw-r--r--python/analytics/tranche_functions.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/python/analytics/tranche_functions.py b/python/analytics/tranche_functions.py
index 66a1b68b..a625949f 100644
--- a/python/analytics/tranche_functions.py
+++ b/python/analytics/tranche_functions.py
@@ -54,6 +54,23 @@ libloss.BCloss_recov_dist.argtypes = [
ndpointer('double', ndim=2, flags='F,writeable'),# output L
ndpointer('double', ndim=2, flags='F,writeable')# output R
]
+libloss.BCloss_recov_trunc.restype = None
+libloss.BCloss_recov_trunc.argtypes = [
+ ndpointer('double', ndim=2, flags='F'),# defaultprob
+ POINTER(c_int),# nrow(defaultprob)
+ POINTER(c_int),# ncol(defaultprob)
+ ndpointer('double', ndim=1, flags='F'),# issuerweights
+ ndpointer('double', ndim=1, flags='F'),# recovery
+ ndpointer('double', ndim=1, flags='F'),# Z
+ ndpointer('double', ndim=1, flags='F'),# w
+ POINTER(c_int), # len(Z) = len(w)
+ ndpointer('double', ndim=1, flags='F'), # rho
+ POINTER(c_int), # Ngrid
+ POINTER(c_double), #K
+ POINTER(c_int), #defaultflag
+ ndpointer('double', ndim=2, flags='F,writeable'),# output L
+ ndpointer('double', ndim=2, flags='F,writeable')# output R
+]
libloss.lossdistrib_joint.restype = None
libloss.lossdistrib_joint.argtypes = [
@@ -110,13 +127,25 @@ def fitprob(Z, w, rho, p0):
def BCloss_recov_dist(defaultprob, issuerweights, recov, rho, Z, w, Ngrid=101, defaultflag=False):
L = np.zeros((Ngrid, defaultprob.shape[1]), order='F')
R = np.zeros_like(L)
- rho = np.repeat(rho, issuerweights.size)
+ rho = np.full(issuerweights.size, rho)
libloss.BCloss_recov_dist(defaultprob, byref(c_int(defaultprob.shape[0])),
byref(c_int(defaultprob.shape[1])),
issuerweights, recov, Z, w, byref(c_int(Z.size)), rho,
byref(c_int(Ngrid)), byref(c_int(defaultflag)), L, R)
return L, R
+def BCloss_recov_trunc(defaultprob, issuerweights, recov, rho, K, Z, w, Ngrid=101, defaultflag=False):
+ L = np.zeros((Ngrid, defaultprob.shape[1]), order='F')
+ R = np.zeros_like(L)
+ rho = np.full(issuerweights.size, rho)
+ libloss.BCloss_recov_trunc(defaultprob, byref(c_int(defaultprob.shape[0])),
+ byref(c_int(defaultprob.shape[1])),
+ issuerweights, recov, Z, w, byref(c_int(Z.size)),
+ rho, byref(c_int(Ngrid)), byref(c_double(K)),
+ byref(c_int(defaultflag)),
+ L, R)
+ return L, R
+
def lossdistrib_joint(p, pp, w, S, Ngrid=101, defaultflag=False):
"""Joint loss-recovery distribution recursive algorithm.