-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain_MC.m
128 lines (93 loc) · 2.51 KB
/
main_MC.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Master file for GMA estimation of bivariate system
% data simulated from DGP based on one Gaussian basis function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
close all;
clc;
tic
addpath('lib');
%we will use 2 obs
size_obs=2;
%length of simulation
length_simul=200;
%number of lags in moving average
lags=40;
% Generate data from DGP with 1 Gaussian basis function
%storing across simulations
Atrue(:,:)=[2 1;-.5 2];
B(:,:)=[5 10; 7 -10];
C(:,:)=[300/2 200/2; 200/2 900/2];
INIT(:,:)=[1 0;-.1 1];
shocks=zeros(size_obs,length_simul+lags);
shocks(:,lags+1:end)=randn([size_obs length_simul]); %initial shocks set to 0
SHOCKS(:,:)=shocks;
data=zeros(size_obs,length_simul);
for ll=1:lags
Sigma(:,:,ll)=SL_NL_symmetric( Atrue(:,:),B(:,:),C(:,:),ll );
end
A_NEG(:,:)=Atrue(:,:);
B_NEG(:,:)=B(:,:);
C_NEG(:,:)=C(:,:);
INIT_NEG(:,:)=INIT(:,:);
%creating asymmetry in DGP
A_POS(:,:)=Atrue(:,:);
A_POS(:,2)=3*A_POS(:,2);
B_POS(:,:)=B(:,:);
B_POS(:,:)=B_POS(:,:);
C_POS(:,:)=C(:,:);
INIT_POS(:,:)=INIT(:,:);
INIT_POS(:,2)=3*INIT_POS(:,2);
for ll=1:lags
Sigma_pos(:,:,ll)=SL_NL_symmetric( A_POS(:,:),B_POS(:,:),C_POS(:,:),ll);
end
SIGMA_POS(:,:,:)=Sigma_pos;
for ll=1:lags
Sigma_neg(:,:,ll)=SL_NL_symmetric(A_NEG(:,:),B_NEG(:,:),C_NEG(:,:),ll );
end
SIGMA_NEG(:,:,:)=Sigma_neg;
data=zeros(size_obs,length_simul);
figure;
for pp=1:4
ind_vec=[1 3 2 4];
subplot(2,2,pp);
[I, J]=ind2sub([2,2],ind_vec(pp));
plot([INIT_POS(ind_vec(pp)) squeeze(SIGMA_POS(I,J,:))'],'LineWidth',2)
grid on
title('true response to positive shocks')
end
figure;
for pp=1:4
subplot(2,2,pp);
[I, J]=ind2sub([2,2],ind_vec(pp));
plot([INIT_NEG(ind_vec(pp)) squeeze(SIGMA_NEG(I,J,:))'],'LineWidth',2)
grid on
title('true response to negative shocks')
end
for kk=1:length_simul
if shocks(2,kk+lags)>0
data(:,kk)=INIT_POS(:,:)*shocks(:,kk+lags);
else
data(:,kk)=INIT_NEG(:,:)*shocks(:,kk+lags);
end
for jj=1:lags
if shocks(2,kk+lags-jj)>0
data(:,kk)=Sigma_pos(:,:,jj)*shocks(:,kk+lags-jj)+data(:,kk);
else
data(:,kk)=Sigma_neg(:,:,jj)*shocks(:,kk+lags-jj)+data(:,kk);
end
end
end
true_pos=zeros(2,2,lags+1);
true_pos(:,:,2:end)=SIGMA_POS(:,:,:);
true_pos(:,:,1)=INIT_POS(:,:);
true_neg=zeros(2,2,lags+1);
true_neg(:,:,2:end)=SIGMA_NEG(:,:,:);
true_neg(:,:,1)=INIT_NEG(:,:);
save ('data/true_asymmetry.mat', 'true_pos', 'true_neg')
save(['data/data_file2.mat'],'data');
%estimation
Principal_MC;
plots_irfs_MC
toc
save results/MC_results_GB