aboutsummaryrefslogtreecommitdiffstats
path: root/python/script_calibrate_tranches.py
blob: 6368a74f00cd33493474c43ea8ba3c42f007b10a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)