封面图片源自网络:

接着前面两期分析,今天介绍期限结构和收益率的方差分解代码:

function var_plot= var_term( Phi_DRAW,OMIGA_ff_DRAW,HH)

%%%% HH means the step length for forecast %%%%%%%%%%

%%%%%% get the forecast variance decomposition %%%%%%%

%%% SIGMA_u=P*P'%%%%

%%% OMIG=inv(P)*U %%%%

%%% Y=MU+SUM_(THITA_i*OMIG_i)   %%%%%%%%%%

A_1=Phi_DRAW';

SIGMA_u=OMIGA_ff_DRAW;       %%% the convriance matrix for error term %%%

%%% FOR THE VAR(1) process the MA  representation :

%%% Y=MU+SUM_(PHI_i*U_i)   %%%%%%%%%%

PHI = zeros(6,6,L);

PHI(:,:,1)=A_1;

PHI(:,:,i)=PHI(:,:,i-1)*A_1;

P= cholcov(SIGMA_u);  %%上三角,要变成下三角

H=HH; %%% SET the step forcest %%%

MSEJ= zeros(6,6,6);

MSEJ(:,:,i)=P(:,i)*P(:,i)';

sum_mse = zeros(6,6);

for j=1:H-1

MSEJ(:,:,i)=MSEJ(:,:,i)+PHI(:,:,j)*P(:,i)*P(:,i)'* PHI(:,:,j)';

MSE_single(:,i)=diag(MSEJ(:,:,i));    %% 每一个变量对提前H期的MSE的贡献

end                                      %%是对角线上的元素

sum_mse = sum(MSE_single,2);

var_de=zeros(6,6);

for i = 1:6

var_de(:,i)=MSE_single(:,i)./ sum_mse ;

var_plot = var_de(1:3,4:6);

disp(['the ' num2str(H)  'step' ' ' 'Horizon']);

一下内容可忽略:

function var_plot= var_term( Phi_DRAW,OMIGA_ff_DRAW,HH)

%%%% HH means the step length for forecast %%%%%%%%%%

%%%%%% get the forecast variance decomposition %%%%%%%

%%% SIGMA_u=P*P'%%%%

%%% OMIG=inv(P)*U %%%%

%%% Y=MU+SUM_(THITA_i*OMIG_i)   %%%%%%%%%%

A_1=Phi_DRAW';

SIGMA_u=OMIGA_ff_DRAW;       %%% the convriance matrix for error term %%%

%%% FOR THE VAR(1) process the MA  representation :

%%% Y=MU+SUM_(PHI_i*U_i)   %%%%%%%%%%

PHI = zeros(6,6,L);

PHI(:,:,1)=A_1;

PHI(:,:,i)=PHI(:,:,i-1)*A_1;

P= cholcov(SIGMA_u);  %%上三角,要变成下三角

H=HH; %%% SET the step forcest %%%

MSEJ= zeros(6,6,6);

MSEJ(:,:,i)=P(:,i)*P(:,i)';

sum_mse = zeros(6,6);

for j=1:H-1

MSEJ(:,:,i)=MSEJ(:,:,i)+PHI(:,:,j)*P(:,i)*P(:,i)'* PHI(:,:,j)';

MSE_single(:,i)=diag(MSEJ(:,:,i));    %% 每一个变量对提前H期的MSE的贡献

end                                      %%是对角线上的元素