aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/script_calibrate_tranches.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/python/script_calibrate_tranches.py b/python/script_calibrate_tranches.py
new file mode 100644
index 00000000..6368a74f
--- /dev/null
+++ b/python/script_calibrate_tranches.py
@@ -0,0 +1,31 @@
+import numpy as np
+from tranche_functions import GHquad, BClossdist
+
+n_int = 500
+n_credit = 100
+Z, w = GHquad(n_int)
+
+with open("recov.csv") as fh:
+ recov = np.array([float(e) for e in fh], dtype='double', order='F')
+
+with open("SurvProb.csv") as fh:
+ SurvProb = np.array([[float(e) for e in line.split(",")] for line in fh], dtype='double', order='F')
+
+defaultprob = 1 - SurvProb
+p = defaultprob
+rho = 0.45 * np.ones(n_credit)
+
+for l in range(150):
+ Rstoch = np.zeros((n_credit, n_int, SurvProb.shape[1]))
+ for t in range(SurvProb.shape[1]):
+ for i in range(n_credit):
+ Rstoch[i,:,t] = stochasticrecov(recov[i], 0, Z, w_mod, rho[i], defaultprob[i,t], p[i,t])
+ L = np.zeros((n_int, Ngrid, SurvProb.shape[1]))
+ R = np.zeros((n_int, Ngrid, SurvProb.shape[1]))
+ for t in range(SurvProba.shape[1]):
+ S = 1 - Rstoch[:,:,t]
+ L[:,:,t] = lossdistZ(p[:,t], issuerweights, S, Ngrid, 0, rho, Z)
+ R[:,:,t] = lossdistZ(p[:,t], issuerweights, S, Ngrid, 0, rho, Z)
+
+ for i in range(n_int):
+ result[:,i] = tranche.pvvec(Kmodified, L[i,,], R[i,,], cs)