%先定义方差协方差矩阵sigma
A=cholesky(sigma);
Iterations=10000;
theta=zeros(Iteration,5);
y=zeros(5,1);cgpi=zeros(6,1);ex=zeros(7,1);nr=zeros(6,1);spi=zeros(6,1);
rgdp=zeros(6,1);
y(1)=-4.1254;
cgpi(1:2)=[104.4,110.60];
ex(1:3)=[9.2033,10.8357,11.8377];
nr(1:2)=[2.25,2.25];
rgdp(1:2)=[8.9,10.7];rgdp(6)=6;
spi(1:2)=[28.94,30.94];
for i=1:Iterations
for t=1:3
r=normrnd(0,1,6,1);
e=transpose(A)*r;
rgdp(t+2)=3.083+1.3917*rgdp(t+1)-0.6946*rgdp(t)+e(5);
end
for t=1:4
r=normrnd(0,1,6,1)
e=transpose(A)*r; (此处的transpose表示矩阵的转置)
cgpi(t+2)=33.1521+1.2533*cgpi(t+1)-0.5483*cgpi(t)+e(2);
ex(t+3)=1.1657*ex(t+1)-0.7189*ex(t+1)+0.5885*ex(t)+e(3);
nr(t+2)=1.4657*nr(t+1)-0.476*nr(t)+e(4);
spi(t+2)=4.6564+1.5136*spi(t+1)-0.6989*spi(t)+e(6);
y(t+1)=-4.5088+0.046*cgpi(t+2)-0.009*ex(t+3)+0.2429*nr(t+2)-0.1539*rgdp(t+2)-0.0138*spi(t+2) +0.732*y(t)+e(1);
end
theta(i,:)=[cgpi(6),ex(7),nr(6),spi(6),y(5)];
end
p=exp(theta(:,5))/(1+exp(theta(:,5)));
pquantile=sort(p);
m=mean(p)
pq=[pquantile(9000),pquantile(9500),pquantile(9900)]
subplot(2,2,1);
hist(theta(:,5),-6:0.11:0);
subplot(2,2,2);hist(p,0:0.01:0.3);