v4: corrected osr

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@924 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
michel 2006-09-21 15:48:01 +00:00
parent ff075bcfa6
commit 1f56e496b1
6 changed files with 37 additions and 18 deletions

Binary file not shown.

View File

@ -1,4 +1,4 @@
function [vx,i_ns] = get_variance_of_endogenous_variables(dr,i_var)
function [vx1,i_ns] = get_variance_of_endogenous_variables(dr,i_var)
global M_ options_
@ -9,17 +9,21 @@ function [vx,i_ns] = get_variance_of_endogenous_variables(dr,i_var)
ghx = dr.ghx(i_var,:);
ghu = dr.ghu(i_var,:);
nc = size(ghx,2);
n = length(i_var);
[A,B] = kalman_transition_matrix(dr,nstatic+(1:npred),1:nc,dr.transition_auxiliary_variables);
[vx,u] = lyapunov_symm(A,B*Sigma_e*B');
i_ns = find(any(abs(ghx*u) > options_.Schur_vec_tol,2));
if size(u,2) > 0
i_stat = find(any(abs(ghx*u) < options_.Schur_vec_tol,2));
ghx = ghx(i_ns,:);
ghu = ghu(i_ns,:);
ghx = ghx(i_stat,:);
ghu = ghu(i_stat,:);
else
i_stat = (1:n)';
end
n = length(i_var);
vx = Inf*ones(n,n);
vx(i_ns,i_ns) = ghx*vx*ghx'+ghu*Sigma_e*ghu';
vx1 = Inf*ones(n,n);
vx1(i_stat,i_stat) = ghx*vx*ghx'+ghu*Sigma_e*ghu';

View File

@ -15,9 +15,12 @@ function global_initialization()
options_.gstep = 1e-2;
options_.debug = 0
options_.initval_file = 0;
optinos_.Schur_vec_tol = 1e-8; % used to find nonstationary variables
options_.Schur_vec_tol = 1e-8; % used to find nonstationary variables
% in Schur decomposition of the
% transition matrix
options_.solve_tolf = eps^(2/3);
options_.solve_tolx = 3.7e-11;
options_.solve_maxit = 500;
if exist([M_.fname '_steadystate'])
options_.steadystate_flag = 1;

View File

@ -1,6 +1,6 @@
% Copyright (C) 2001 Michel Juillard
%
function osr(var_list,params,W)
function osr(var_list,params,i_var,W)
global M_ options_ oo_
options_.order = 1;
@ -36,7 +36,7 @@ function osr(var_list,params,W)
disp(' ')
disp('OPTIMAL SIMPLE RULE')
disp(' ')
osr1(i_params,W);
osr1(i_params,i_var,W);
disp('MODEL SUMMARY')
disp(' ')
disp([' Number of variables: ' int2str(M_.endo_nbr)])

View File

@ -1,4 +1,4 @@
function osr1(i_params,weights)
function osr1(i_params,i_var,weights)
global M_ oo_ options_ it_
klen = M_.maximum_lag + M_.maximum_lead + 1;
@ -21,6 +21,9 @@ function osr1(i_params,weights)
end
exe =zeros(M_.exo_nbr,1);
oo_.dr = set_state_space(oo_.dr);
% check if ys is steady state
fh = str2func([M_.fname '_static']);
if max(abs(feval(fh,oo_.steady_state,exe))) > options_.dynatol
@ -29,17 +32,26 @@ function osr1(i_params,weights)
error('OLR: convergence problem in DYNARE_SOLVE')
end
else
dr.ys = oo_.steady_state;
oo_.dr = dr;
oo_.dr.ys = oo_.steady_state;
end
np = size(i_params,1);
t0 = M_.params(i_params);
options = optimset('fminunc');
options = optimset('display','iter');
[p,f]=fminunc(@osr_obj,t0,options,i_params,weights);
inv_order_var = oo_.dr.inv_order_var;
H0 = 1e-4*eye(np);
crit = 1e-7;
nit = 1000;
verbose = 2;
[f,p]=csminwel('osr_obj',t0,H0,[],crit,nit,i_params,...
inv_order_var(i_var),weights(i_var,i_var));
% options = optimset('fminunc');
% options = optimset('display','iter');
% [p,f]=fminunc(@osr_obj,t0,options,i_params,...
% inv_order_var(i_var),weights(i_var,i_var));

View File

@ -59,7 +59,7 @@ function [Gamma_y,ivar]=th_autocovariances(dr,ivar)
[vx, u] = lyapunov_symm(A,B*M_.Sigma_e*B');
iky = iv(ivar);
if ~isempty(u)
iky = iky(find(any(abs(ghx(iky,:)*u) < 1e-8,2)));
iky = iky(find(any(abs(ghx(iky,:)*u) < options_.Schur_vec_tol,2)));
ivar = dr.order_var(iky);
end
aa = ghx(iky,:);