坚持数值评估这个积分,只有在做简单求积分方案方面的经验所以如果这看起来很业余,请耐心等待。嵌套积分在下面使用Gauss-Hermite(-inf,+ inf)和Gauss Laguerre方案(0,+ inf)的变体 - 高斯和伽马(v / 2,2)密度。我到了几乎完成整合的阶段,中间步骤看起来很好,但我仍然坚持如何结合权重来评估整体积分。我非常感谢修改代码/其他想法以编写更好的求解问题的正交方案的建议。 \开始{}方程 \ int ^ {\ infty} { - \ infty} \ int ^ {\ infty} {0} \ prod_ {i = 1} ^ n \ Phi \ left(\ frac {\ sqrt {w / v} \,C {i} -a {i} Z} {\ sqrt {1a {i ^ 2}} \ right)f {z}(Z)f {w}(W)dwdz \ end {equation}
%script定义节点,权重,参数然后调用一个主函数和一个子函数
RHO = 0.3; nfirms = 10; H = repmat(0.1,[1,nfirms]); T = 1; R = 0.4; V = 8;阿尔法= V / 2; GaussPts = 15;
% Quadrature nodes - gaussian and gamma(v/2) from Miranda and Fackler CompEcon
% toolbox
[x_norm,w_norm] = qnwnorm(GaussPts,0,1);
[x_gamma,w_gamma] = qnwgamma(GaussPts,alpha);
L_mat=zeros(nfirms+1,GaussPts);
for i=1:1:GaussPts;
L_mat(:,i) = TC_gamma(x_norm(i,:),x_gamma(i,:),h,rho,T,v,nfirms);
end;
w_norm_mat= repmat(w_norm',nfirms+1,1);
w_gamma_mat = repmat(w_gamma',nfirms+1,1);
% need to weight L_mat by the gaussian and chi-sq i.e, (gamma v/2,2)?
ucl = L_mat.*w_norm;%?? HERE
ucl2 = sum(ucl.*w_gamma2,2);% ?? HERE
function [out] = TC_gamma(x_norm,x_gamma,h,rho,T,v,nfirms)
% calls subfunction feeds into recursion
qki= Vec_CondPTC_gamma(x_norm,x_gamma,h,rho,T,v)' ;
fpdf=zeros(nfirms+1,nfirms+1);
% start at the first point on the tree
fpdf(1,1)=1;
for i=2:nfirms+1 ;
fpdf(1,i)=fpdf(1,i-1)*(1-qki(:,i-1));
for j=2:nfirms+1;
fpdf(j,i)=fpdf(j,i-1)*(1-qki(:,i-1))+fpdf(j-1,i-1)*qki(:,i-1);
end
fpdf(i,i)=fpdf(i-1,i-1)*qki(:,i-1);
end
out=fpdf(:,end);
end% of function TC_gamma
function qki= Vec_CondPTC_gamma(x_norm,x_gamma,h,rho,T,v)
PD = (1-exp(-kron(h,T)));DB = tinv(PD,v);
a=rho.^0.5; sqrt1_a2 = sqrt(1-sum(a.*a,2));
aM = gtimes(a, x_norm'); Sqrt_W=gamcdf(x_gamma,v/2,2).^0.5;
DB_times_W= gtimes(DB,Sqrt_W); DB_minus_aM = gminus(DB_times_W',aM);
qki=normcdf(grdivide(DB_minus_aM,sqrt1_a2));
end% of function Vec_CondPTC