关于在Python用KMV模型估计资产价值及其波动

Bleibet |浏览227次
检举|收藏|2018/07/12 00:45

import scipy as sp
import pandas as pd
import scipy.stats as stats
from scipy import log,sqrt,exp
# input area
D=30.            # debt
E=70.            # equity
T=1.             # maturity
r=0.07           # risk-free
sigmaE=0.4       # volatility of equity
#
# define a function to siplify notations later
def N(x):
    return stats.norm.cdf(x)
#
def KMV_f(E,D,T,r,sigmaE):
    n=10000
    m=2000
    diffOld=1e6     # a very big number
    for i in sp.arange(1,10):
        for j in sp.arange(1,m):
            A=E+D/2+i*D/n
            sigmaA=0.05+j*(1.0-0.001)/m
            d1 = (log(A/D)+(r+sigmaA*sigmaA/2.)*T)/(sigmaA*sqrt(T))
            d2 = d1-sigmaA*sqrt(T)
            diff4A= (A*N(d1)-D*exp(-r*T)*N(d2)-E)/A  # scale by assets
            diff4sigmaE= A/E*N(d1)*sigmaA-sigmaE     # a small number already
            diffNew=abs(diff4A)+abs(diff4sigmaE)
            if diffNew<diffOld:
               diffOld=diffNew
               output=(round(A,2),round(sigmaA,4),round(diffNew,5))
    return output
#
print("KMV=", KMV_f(D,E,T,r,sigmaE))
print("KMV=", KMV_f(D=65e3,E=110e3,T=1,r=0.01,sigmaE=0.2))




对于此代码中对A和sigmaA的定义实在不怎么理解,求助各位了


全部回答(0)
0人关注该问题
 加载中...