Attachment 'ModSimul.m'

Download

   1 function [RMSE,biais,ErreursPrev]=ModSimul(J)
   2 global options_ M_ oo_ estim_params_ bayestopt_
   3 
   4 horizon=8;
   5 
   6 % options_.logdata
   7 % options_.loglinear
   8 BeginSample = 5;
   9 EndSample = 51;
  10 nb_prevs = EndSample-BeginSample+1;
  11 train = options_.bvar_prior_train;
  12 idx = options_.first_obs+options_.presample-train-4:options_.first_obs+options_.nobs-1;
  13 
  14 % chargement des données
  15 rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range);
  16 nb_points=size(rawdata,1);
  17 if options_.loglinear == 1 & ~options_.logdata
  18   rawdata = log(rawdata);
  19 end
  20 % if options_.prefilter == 1
  21 %    bayestopt_.mean_varobs = mean(rawdata,1);
  22 %    data = transpose(rawdata-ones(nb_points,1)*bayestopt_.mean_varobs);
  23 % else
  24   data = transpose(rawdata);
  25 % end
  26 if ~isreal(rawdata)
  27   error(['There are complex values in the data. Probably  a wrong' ...
  28 	 ' transformation'])
  29 end
  30 
  31 
  32 % chargement du mode postérieur des paramètres
  33 load ACDM_mode.mat
  34 
  35 % simulations
  36 nb_obs = size(bayestopt_.mf,2);
  37 Y = zeros(nb_obs,horizon+1,nb_prevs);
  38 %indx = GetObsIndex();
  39 for gend = BeginSample:EndSample  %51 ; options_.nobs; On veut commencer la prev en 2004Q1 => gend=51
  40     X = zeros(M_.endo_nbr,horizon+1);
  41     databoucle = data(:,options_.first_obs:options_.first_obs+gend-1);
  42     [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,A,B] = DsgeSmoother(xparam1,gend,databoucle);
  43     X(:,1) = alphahat(:,end);    
  44     for k=2:horizon+1
  45         X(:,k) = A*X(:,k-1) ;
  46     end
  47     Y(:,:,gend-BeginSample+1) = X(bayestopt_.mf,:) ;
  48 end
  49 
  50 % M_.endo_names(oo_.dr.order_var,:) Les variables endogènes sont classées
  51 % suivant oo_.dr.order_var dans la matrice de transition -> utile pour
  52 % prevs conditionnelles
  53 
  54 % function RMSE(Y)
  55 
  56 % global data nb_obs
  57 
  58 
  59 ErreursPrev = zeros(nb_prevs,horizon+1,nb_obs);
  60 for i = 1:nb_obs
  61     for h = 1:horizon+1
  62         for gend = BeginSample:EndSample
  63            ErreursPrev(gend-BeginSample+1,h,i) = Y(i,h,gend-BeginSample+1) - data(i,options_.first_obs+gend+h-2) ;
  64         end
  65     end
  66 end
  67 
  68 % nb_prevs
  69 
  70 
  71 % figure('Name','pi')
  72 % for boucle = 1:(horizon+1)
  73 %     subplot(3,3,boucle)
  74 % %     Go(end-boucle+1,:)
  75 % %     data(4,end-boucle+1-8:end-boucle+1)
  76 % %     J(end-boucle+1,:,4)
  77 %     plot(Go(end-boucle+1,:),'color','r');
  78 %     hold on
  79 %     plot(data(4,end-boucle+1-8:end-boucle+1));
  80 %     hold on
  81 %     plot(J(end-boucle+1,:,4),'color','g');
  82 % end
  83 
  84 % vecteur de dates
  85 vecteurdates = [];
  86 for an = 1993:2:2006
  87     vecteurdates=[vecteurdates ; int2str(an) 'Q' int2str(1) ];
  88 end
  89 
  90 data
  91 options_.first_obs+BeginSample-1
  92 
  93 for variable=1:7
  94     Go=permute(Y(variable,:,:),[3 2 1]);
  95     figure('Name', options_.varobs(variable,:))
  96     plot(data(variable,options_.first_obs+BeginSample-1:end),'LineWidth',1.5,'Color','k')
  97     hold on
  98     for boucle = 3:4:nb_prevs
  99         plot([boucle:boucle+8],Go(boucle,:),'Color','k')
 100         hold on
 101         plot([boucle:boucle+8],J(boucle,:,variable),'Color','k','LineStyle',':')
 102         legend('données','modèle','bvar','Location','SouthOutside','Orientation','horizontal')
 103         hold on
 104     end
 105     set(gca,'Xtick',4:8:55,'XTickLabel',{vecteurdates},'FontSize',9)
 106     grid on
 107     hold off
 108 end
 109 
 110 
 111 
 112 % Go=permute(Y(7,:,:),[3 2 1]);
 113 % figure('Name','w')
 114 % for boucle = 1:(horizon+1)
 115 %     subplot(3,3,boucle)
 116 % %     Go(end-boucle+1,:)
 117 % %     data(7,end-boucle+1-8:end-boucle+1)
 118 %     plot(Go(end-boucle+1,:),'color','r');
 119 %     hold on
 120 %     plot(data(7,end-boucle+1-8:end-boucle+1));
 121 %     hold on
 122 %     plot(J(end-boucle+1,:,7),'color','g');
 123 % end
 124 % Go=permute(Y(1,:,:),[3 2 1]);
 125 % figure('Name','Y')
 126 % for boucle = 1:(horizon+1)
 127 %     subplot(3,3,boucle)
 128 % %     Go(end-boucle+1,:)
 129 % %     data(1,end-boucle+1-8:end-boucle+1)
 130 %     plot(Go(end-boucle+1,:),'color','r');
 131 %     hold on
 132 %     plot(data(1,end-boucle+1-8:end-boucle+1));
 133 %     hold on
 134 %     plot(J(end-boucle+1,:,1),'color','g');
 135 % end
 136 
 137 % figure(2)
 138 % Go=permute(Y(4,2,:),[2 3 1]);
 139 % plot(Go)
 140 % hold on
 141 % plot(data(4,52:end))
 142 % pause
 143 
 144 % RMSE et biais par horizon de prev
 145 
 146 RMSE = zeros(nb_obs,horizon+1);
 147 biais = zeros(nb_obs,horizon+1);
 148 for i = 1:nb_obs
 149     RMSE(i,:) = sqrt(diag(ErreursPrev(:,:,i)'*ErreursPrev(:,:,i))/nb_prevs);
 150     biais(i,:) = mean(ErreursPrev(:,:,i));
 151 end
 152 
 153 RMSE=RMSE(:,2:horizon+1);
 154 biais=biais(:,2:horizon+1);
 155 ErreursPrev=ErreursPrev(:,2:horizon+1,:);
 156 % RMSE moyen et biais sur tous les exercices de prev
 157 
 158 % RMSEtot = zeros(nb_obs,1);
 159 % biaistot = zeros(nb_obs,1); 
 160 % for i = 1:nb_obs
 161 %     RMSEtot(i) = mean(sqrt(diag(ErreursPrev(:,:,i)*ErreursPrev(:,:,i)')/horizon));
 162 %     biaistot(i) = mean(mean(ErreursPrev(:,:,i)'));
 163 % end
 164 options_.varobs
 165 RMSE
 166 %RMSEtot
 167 %biais
 168 %biaistot
 169 
 170 
 171 % function indx = GetObsIndex()
 172 % global options_ M_ oo_
 173 % names = options_.varobs;
 174 % n = size(names,1);
 175 % indx = zeros(n,1);
 176 % for i = 1:n
 177 %     indx(i) = strmatch(deblank(names(i,:)),deblank(M_.endo_names(oo_.dr.order_var,:)),'exact');
 178 % end

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-10-02 14:29:51, 15.6 KB) [[attachment:ACDM.mod]]
  • [get | view] (2008-10-02 14:30:56, 0.9 KB) [[attachment:DieboldMariano.m]]
  • [get | view] (2008-10-02 14:30:27, 4.7 KB) [[attachment:ModSimul.m]]
  • [get | view] (2008-10-02 14:30:41, 3.1 KB) [[attachment:PrevBVAR.m]]
  • [get | view] (2008-10-02 14:11:27, 250.7 KB) [[attachment:m07-196z.pdf]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.