最近也在做kmv模型
参考了你的和贴吧的改了一下代码,可是初始值设置总是有问题,参考了郑老师的初始值设置[1,1]可以搜索后,再改了以下代码,可是出的结果就只有1,1,但是用郑老师的代码改的话,出的结果就没有问题。
你的和贴吧的改的
clear all
clc
Ve=xlsread('C:\Users\lenovo\Desktop\kmv.xls','G2:G31');%股权价值
k=xlsread('C:\Users\lenovo\Desktop\kmv.xls','H2:H31');%负债总额
sigmae=xlsread('C:\Users\lenovo\Desktop\kmv.xls','F2:F31');%股权波动率
R=xlsread('C:\Users\lenovo\Desktop\kmv.xls','K2:K31');%利率
t =1;
result=zeros(30,2);%va和sigma
for i=1:30
VE=Ve(i);
K=k(i);
sigmaE=sigmae(i);
r =R(i);
x0=[1,1];%按X的初始值搜索
a=fsolve(@(X)Y(X,K,r,VE,sigmaE,t),x0);
result(i,1)=a(1)
result(i,2)=a(2)
end
调用的函数Y.m
function Y=Y(X,K,r,VE,sigmaE,t)
VA=X(1);
sigmaA=X(2);
d1=(log(VA/K)+(r+1/2*(sigmaA)^2)*t)/(sigmaA*sqrt(t));% d1
d2=d1-sigmaA *sqrt(t);% d2
Y=[VA*normcdf(d1)-K*exp(-r*t)*normcdf(d2)-VE;VA*normcdf(d1)*sigmaA/VE-sigmaE];%两个方程I
end
跟用郑老师书后给的代码改的出的结果怎么就不一样
%test KMV
%r: risk-free rate
r=0.015;
%T: Time to expiration
T=1;%输入年数
%EquityTheta: volatility of Theta value
equitytheta=xlsread('C:\Users\lenovo\Desktop\kmv.xls','F2:F31');
%AssetTheta: volatility of asset
%E:Equit maket value
e=xlsread('C:\Users\lenovo\Desktop\kmv.xls','G2:G31');
%负债总额
d=xlsread('C:\Users\lenovo\Desktop\kmv.xls','H2:H31');
result=zeros(30,2);%va和sigma
for i=1:30
D=d(i);
E=e(i);
EquityTheta=equitytheta(i)
%to compute the Va and AssetTheta
[Va,AssetTheta]=KMVOptSearch(E,D,r,T,EquityTheta)
result(i,1)=Va
result(i,2)=AssetTheta
end
调用的两函数
function F=KMVfun(EtoD,r,T,EquityTheta,x)
d1=( log(x(1)*EtoD)+(r+0.5*x(2)^2)*T ) / ( x(2)*sqrt(T));
d2=d1-x(2)*sqrt(T);
F=[ x(1)*normcdf(d1)-exp(-r*T)*normcdf(d2)/EtoD-1;
normcdf(d1)*x(1)*x(2)-EquityTheta];
end
function [Va,AssetTheta]=KMVOptSearch(E,D,r,T,EquityTheta)
%KMVOptSearch
%code by ariszheng@
EtoD=E/D;
x0=[1,1];%搜素初始点
VaThetaX=fsolve(@(x) KMVfun(EtoD,r,T,EquityTheta,x), x0);
Va=VaThetaX(1)*E;
AssetTheta=VaThetaX(2);
% F=KMVfun(EtoD,r,T,EquityTheta,x)
end