Я пытаюсь создать цикл, который будет выбирать купоны для разных траншей CDO на основе единообразных случайных чисел, созданных numpy.
если rand <0.25 <br>A получает ранд * $ 5
если rand
если rand <0.75 A получает 0.25 * $ 5 B получает 0.25 * $ 5 C получает (rand-0.5)* $ 5 </p>
если ранд <1 A получает 0,25 * $ 5 B получает 0,25 * $ 5 C получает 0,25 * $ 5 D получает (rand-0,75) * $ 5 </p>
Я создал CSV для рандов с 20столбцы для портфеля из 20 облигаций. (ranfile1)
и 100 000 строк для сценариев.
I created a code up to the third trench without the "D".
randfile1=np.random.rand(20,100000)
spots = [0.0211,0.0188,0.0184,0.0187,0.0189,0.0195,0.0201,0.0205,0.0208,0.02120,0.0215,0.0218,0.0221,0.0224,0.0227,0.0229,0.0232,0.0235,0.0238,0.0241]
A = []
B = []
C = []
D = []
a = randfile1[randfile1 < 0.25].sum() * 5
A.append(a)
b = (randfile1[np.logical_and(0.25 <= randfile1, randfile1 < 0.5)] - 0.25).sum() * 5
B.append(b)
a = np.logical_and(0.25 < randfile1, randfile1 < 0.5).sum() * 1.25
A.append(a)
c = (randfile1[np.logical_and(0.5 <= randfile1, randfile1 < 0.75)] - 0.5).sum() * 5
C.append(c)
b = np.logical_and(0.5 < randfile1, randfile1 < 0.75).sum() * 1.25
B.append(b)
a = np.logical_and(0.5 < randfile1, randfile1 < 0.75).sum() * 1.25
A.append(a)
d = (randfile1[np.logical_and(0.75 <= randfile1, randfile1 < 1)] - 0.5).sum() * 5
D.append(d)
c = np.logical_and(0.75 < randfile1, randfile1 < 1).sum() * 1.25
C.append(c)
b = np.logical_and(0.75 < randfile1, randfile1 < 1).sum() * 1.25
B.append(b)
a += np.logical_and(0.75 < randfile1, randfile1 < 1).sum() * 1.25
A.append(a)