-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_4.py
58 lines (45 loc) · 1.81 KB
/
main_4.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
main 4: test runMonteParallel with multiprocessing
"""
from Asset import Asset
from Loan import Loan
from LoanPool import LoanPool
from StandardTranche import StandardTranche
from StructuredSecurity import StructuredSecurity
from runMonteParallel import runMonteParallel
import random
import multiprocessing
def main():
print('\nRuochen Wang'
'\nmain 4: test runMonteParallel with multiprocessing')
multiprocessing.freeze_support()
random.seed(74) # set seed
# Create a LoanPool object that consists of 1,500 loans.
with open('/Users/wrc/Desktop/python HW/Ruochen Wang_ABS modeling/Loans_data.csv', 'r', ) as f:
next(f) # skip header line
loan = []
for line in f:
l = line.rstrip("', '', '', '', '\n'").split(',') # convert lines of csv into list
loan.append(Loan(Asset(float(l[6])), int(l[4]), float(l[3]), float(l[2])))
lp = LoanPool(*loan)
# Instantiate StructuredSecurity object
# add two standard tranches
ta = StandardTranche(15000000, 0.05, 1)
tb = StandardTranche(lp.totalPrincipal() - 15000000, 0.08, 2)
ss = StructuredSecurity('Sequential', ta, tb)
# let tolerance be 0.005, try 200 simulations and 5 processes
rm = runMonteParallel(lp, ss, 0.005, 200, 5)
# get DIRR
print('\nDIRR of standard tranche "ta":', rm[0])
print('DIRR of standard tranche "tb":', rm[1])
# get AL
print('\nAL of standard tranche "ta":', rm[2])
print('AL of standard tranche "tb":', rm[3])
# get rate
print('\nrate of standard tranche "ta":', rm[4])
print('rate of standard tranche "tb":', rm[5])
# get rating
print('\nDIRR of standard tranche "ta" is 0, the rating of "ta" is Aaa.'
'\nDIRR of standard tranche "tb" is 0, the rating of "tb" is Aaa.')
if __name__ == '__main__':
main()