-
Notifications
You must be signed in to change notification settings - Fork 1
/
loanOutcome.py
56 lines (44 loc) · 1.77 KB
/
loanOutcome.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
import numpy as np
import matplotlib.pyplot as plt
def loanApprovalStatus(risk_Default, risk_Maybe, risk_NotDefault, int_rate, loanTerm, funded_amount):
# assume daily compounding
# defaulting: rejected.
# risky & nonrisky: all accepted - high risk with the former.
tot= len(risk_Default)
profit= np.zeros(tot)
int_rate= int_rate/100.
##
default= np.where(risk_Default==1)[0]
profit[default]= np.nan
# assume monthly compounding
n= 365.
# calculate profit
notdefault= np.where(risk_NotDefault==1)[0]
nYears= loanTerm[notdefault]/12.
profit[notdefault]= funded_amount[notdefault]*(1.+((int_rate[notdefault])/n))**(n*nYears)-funded_amount[notdefault]
risky= np.where(risk_Maybe==1)[0]
nYears= (loanTerm[risky]+6.)/12. # assume risky would take 6months extra?
profit[risky]= funded_amount[risky]*(1+((int_rate[risky])/n))**(n*nYears)-funded_amount[risky]
ind= range(10)
# profit percent
profitPercent= profit/funded_amount
# plot histogram: profit %
bins= 20
alpha= 0.5
fontsize= 14
histtype= 'bar'
plt.hist(profitPercent[risky], label= 'maybe', alpha= alpha, bins= bins, histtype=histtype)
plt.hist(profitPercent[notdefault], label= 'not default', alpha= alpha, bins= bins, histtype=histtype)
plt.xlabel('profit (% funded)', fontsize= fontsize)
plt.legend(fontsize= fontsize)
plt.gcf().set_size_inches(12,6)
plt.show()
# loan approval? accept everything thats not 100% defaulting.
loanApproval= np.zeros(tot)+1
loanApproval[default]= 0.
# histogram
#plt.hist(loanApproval)
#plt.xlabel('loan approval', fontsize= fontsize)
#plt.show()
print 'Approval rate (%): ', 100.*(1.-float(len(default))/tot)
return loanApproval