请教高手用Matlab求解极大似然估计函数,估计出H(或者alf即α=H/X)、v 和δ(即sgm)
请教高手用Matlab求解极大似然估计函数,估计出H(或者alf即α=H/X)、v和δ(即sgm)所需数据请给出程序代码一楼程序运行出错,求解...
请教高手用Matlab求解极大似然估计函数,估计出H(或者alf即α=H/X)、v 和δ(即sgm)
所需数据
请给出程序代码 一楼程序运行出错,求解 展开
所需数据
请给出程序代码 一楼程序运行出错,求解 展开
1个回答
展开全部
function LE= LE( x , ve , X , h , T ,r) % 对数似然函数
int m;
double t1;double TT;double t2; doublet3;double t4;double V0;
m = numel(ve);
va = zeros (m,1);
alf = exp (x(1)); sgm = exp (x(2)); % 对数化待估参数
sgms = sgm^2;proxy1 = r - sgms * 0.5 ;
H = alf * X; Mh = (m-1) * h;
for i=1:m %
V0 =ve(i)+X;
TT=T-(i-1)*h;
va(i) = fsolve
(@(v)exoticoption(ve(i),alf,sgm,TT,r,v,X),V0,optimset('Display','off'));
end
S = normcdf ( ( ( proxy1 * Mh ) - log (H/va(1) ) )/ sqrt ( Mh ) / sgm ) - exp ( 2/sgms
* proxy1 * log ( H/va(1) ) ) * ...
normcdf ( ( ( proxy1 * Mh ) + log ( H/va(1) ))/ sqrt ( Mh ) / sgm );
sum1 = 0;sum2 = 0;sum3 = 0; sum4 = 0;
for j=1:m-1 % 得到对数似然函数的值
TT =T - j*h;
t1 =( log (va(j+1) / va(j)) - proxy1 * h )^2 / sgms / h;
t2 =log ( va(j+1) );
t3 =log ( 1 - exp ( -2 / sgms / h * log ( va(j) / H) * log ( va(j+1) / H )) );
t4 =log ( abs ( der( va(j+1),alf,sgm,TT,r,X ) ) );
sum1= sum1 + t1;
sum2= sum2 + t2;
sum3= sum3 + t3;
sum4= sum4 + t4;
end
LE = 0.5 * (m-1) * log ( 2 * pi * sgms * h)+ 0.5 * sum1 + sum2 - ...
sum3 + log (S) + sum4;
end
%----------------------------------------------------------------------------------------------------
function der = der ( x, alf , sgm , T , r ,X )
double a;
double b;
double H;
double pp; pp = 1 / ( sqrt(2*pi) );
double pp2;
H = alf * X;
double eta;
eta = r/(sgm^2)+0.5;
double pro1;
double pro2;
double pro3;
double pro4;
pro1 = r + sgm^2/2;
pro2 = sgm * sqrt(T);
pp2 = 1 / pro2 / x;
pro3 = X * exp(-r*T);
pro4 = (H/x)^(2*eta);
pro5 = (H/x)^(2*eta - 2);
if alf <= 1
a =( log( x / X ) + pro1 * T ) / pro2;
b =( log( H^2 / (x*X) ) + pro1 * T ) / pro2;
else
a =( log( x / H ) + pro1 * T ) / pro2;
b =( log( H / x ) + pro1 * T ) / pro2;
end
der = pp * exp( -0.5 * a^2) / pro2 +normcdf (a) - pro3 * pp * exp (-0.5 * (a - pro2)^2)
* pp2 + ...
pro4 * pp * exp (-0.5 * b^2) / pro2 + (2 *eta - 1) * pro4 * normcdf(b) - pro3 * pro5
* ...
(pp* exp (-0.5 * (b - pro2)^2) * pp2 + (2 * eta - 2) * normcdf( b-pro2 ) / x);
end
%----------------------------------------------------------------------------------------------------
function [ F ] = exoticoption( e , alf ,sgm , T , r , v , X )
double a;
double b;
double H;
H = alf * X;
double eta;
eta = r/(sgm^2)+0.5;
double rightside;
double pro1;
double pro2;
double pro3;
pro1 = r + sgm^2/2;
pro2 = sgm * sqrt(T);
pro3 = X * exp(-r*T);
if alf <= 1
a =( log( v / X ) + pro1 * T ) / pro2;
b =( log( H^2 / (v*X) ) + pro1 * T ) / pro2;
else
a =( log( v / H ) + pro1 * T ) / pro2;
b =( log( H / v ) + pro1 * T ) / pro2;
end
rightside = v * normcdf(a) - pro3 *normcdf(a - pro2) - v * (H/v)^(2 * eta) *
normcdf(b) + pro3 *(H/v)^(2 * eta -2) *normcdf(b - pro2);
F = e - rightside;
end
int m;
double t1;double TT;double t2; doublet3;double t4;double V0;
m = numel(ve);
va = zeros (m,1);
alf = exp (x(1)); sgm = exp (x(2)); % 对数化待估参数
sgms = sgm^2;proxy1 = r - sgms * 0.5 ;
H = alf * X; Mh = (m-1) * h;
for i=1:m %
V0 =ve(i)+X;
TT=T-(i-1)*h;
va(i) = fsolve
(@(v)exoticoption(ve(i),alf,sgm,TT,r,v,X),V0,optimset('Display','off'));
end
S = normcdf ( ( ( proxy1 * Mh ) - log (H/va(1) ) )/ sqrt ( Mh ) / sgm ) - exp ( 2/sgms
* proxy1 * log ( H/va(1) ) ) * ...
normcdf ( ( ( proxy1 * Mh ) + log ( H/va(1) ))/ sqrt ( Mh ) / sgm );
sum1 = 0;sum2 = 0;sum3 = 0; sum4 = 0;
for j=1:m-1 % 得到对数似然函数的值
TT =T - j*h;
t1 =( log (va(j+1) / va(j)) - proxy1 * h )^2 / sgms / h;
t2 =log ( va(j+1) );
t3 =log ( 1 - exp ( -2 / sgms / h * log ( va(j) / H) * log ( va(j+1) / H )) );
t4 =log ( abs ( der( va(j+1),alf,sgm,TT,r,X ) ) );
sum1= sum1 + t1;
sum2= sum2 + t2;
sum3= sum3 + t3;
sum4= sum4 + t4;
end
LE = 0.5 * (m-1) * log ( 2 * pi * sgms * h)+ 0.5 * sum1 + sum2 - ...
sum3 + log (S) + sum4;
end
%----------------------------------------------------------------------------------------------------
function der = der ( x, alf , sgm , T , r ,X )
double a;
double b;
double H;
double pp; pp = 1 / ( sqrt(2*pi) );
double pp2;
H = alf * X;
double eta;
eta = r/(sgm^2)+0.5;
double pro1;
double pro2;
double pro3;
double pro4;
pro1 = r + sgm^2/2;
pro2 = sgm * sqrt(T);
pp2 = 1 / pro2 / x;
pro3 = X * exp(-r*T);
pro4 = (H/x)^(2*eta);
pro5 = (H/x)^(2*eta - 2);
if alf <= 1
a =( log( x / X ) + pro1 * T ) / pro2;
b =( log( H^2 / (x*X) ) + pro1 * T ) / pro2;
else
a =( log( x / H ) + pro1 * T ) / pro2;
b =( log( H / x ) + pro1 * T ) / pro2;
end
der = pp * exp( -0.5 * a^2) / pro2 +normcdf (a) - pro3 * pp * exp (-0.5 * (a - pro2)^2)
* pp2 + ...
pro4 * pp * exp (-0.5 * b^2) / pro2 + (2 *eta - 1) * pro4 * normcdf(b) - pro3 * pro5
* ...
(pp* exp (-0.5 * (b - pro2)^2) * pp2 + (2 * eta - 2) * normcdf( b-pro2 ) / x);
end
%----------------------------------------------------------------------------------------------------
function [ F ] = exoticoption( e , alf ,sgm , T , r , v , X )
double a;
double b;
double H;
H = alf * X;
double eta;
eta = r/(sgm^2)+0.5;
double rightside;
double pro1;
double pro2;
double pro3;
pro1 = r + sgm^2/2;
pro2 = sgm * sqrt(T);
pro3 = X * exp(-r*T);
if alf <= 1
a =( log( v / X ) + pro1 * T ) / pro2;
b =( log( H^2 / (v*X) ) + pro1 * T ) / pro2;
else
a =( log( v / H ) + pro1 * T ) / pro2;
b =( log( H / v ) + pro1 * T ) / pro2;
end
rightside = v * normcdf(a) - pro3 *normcdf(a - pro2) - v * (H/v)^(2 * eta) *
normcdf(b) + pro3 *(H/v)^(2 * eta -2) *normcdf(b - pro2);
F = e - rightside;
end
追问
程序运行出错
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询