diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/tranche_functions.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/python/tranche_functions.py b/python/tranche_functions.py new file mode 100644 index 00000000..44244040 --- /dev/null +++ b/python/tranche_functions.py @@ -0,0 +1,37 @@ +import numpy as np +from ctypes import * + +lib = np.ctypeslib.load_library("lossdistribgomez", "/home/share/CorpCdos/code/R") +lib.fitprob.restype = None +lib.fitprob.argtypes = [np.ctypeslib.ndpointer('double', ndim=1, flags='F'), + np.ctypeslib.ndpointer('double', ndim=1, flags='F'), + POINTER(c_int), + POINTER(c_double), + POINTER(c_double), + np.ctypeslib.ndpointer('double', ndim=1, flags='F,writeable')] +lib.stochasticrecov.restype = None +lib.stochasticrecov.argtypes = [POINTER(c_double), + POINTER(c_double), + np.ctypeslib.ndpointer('double', ndim=1, flags='F'), + np.ctypeslib.ndpointer('double', ndim=1, flags='F'), + POINTER(c_int), + POINTER(c_double), + POINTER(c_double), + POINTER(c_double), + np.ctypeslib.ndpointer('double', ndim=1, flags='F,writeable')] + +def stochasticrecov(R, Rtilde, Z, w, rho, porig, pmod): + q = np.zeros_like(Z) + lib.stochasticrecov(byref(c_double(R)), byref(c_double(Rtilde)), Z, w, byref(c_int(Z.size)), + byref(c_double(rho)), byref(c_double(porig)), byref(c_double(pmod)), q) + return q + + +def lossdistZ(p, w, S, N, defaultflag= False, rho, Z, wZ): + q = np.zeros_like(Z) + lib.lossdistrib_Z(byref()) + +def fitprob(Z, w, rho, p0): + result = np.empty_like(Z) + lib.fitprob(Z, w, byref(c_int(Z.size)), byref(c_double(rho)), byref(c_double(p0)), result) + return result |
