Skip to content

Commit

Permalink
Recommit
Browse files Browse the repository at this point in the history
Lesson well learned from Kenneth, SeHyoun, Karsten and Leif
  • Loading branch information
jmaih committed Mar 25, 2019
1 parent d12eee5 commit 62891b7
Show file tree
Hide file tree
Showing 896 changed files with 15,223 additions and 77,645 deletions.
Binary file modified classes/models/+dsge_tools/ctw_endogenous_priors.p
Binary file not shown.
86 changes: 42 additions & 44 deletions classes/models/+dsge_tools/identification.m
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
%--- help for rfvar/identification ---
%
% --- help for rfvar/identification ---
%
% Parses identifying restrictions into RISE interpretable identification function
%
% Note:
% This function is a part of a general workflow. See XXXXXXXXXX to check the workflow.
%
% ::
%
% Rfunc = identification(var, restr, shock_names, varargin);
%
% Args:
% var (rfvar object): rfvar object
% restr : restrictions can take two forms
%
% - **'choleski'**: choleski identification. Supply the ordering as a cell array as varargin{1}
% - **cellstr**: n x 2 cell array, with n the number of restrictions.
% A typical restriction takes the form:
% - 'vbl@shk','sign'
% - 'vbl{lags}@shk','sign'
% where sign = +|-
% where shk is the name of the shock
% where vbl is the name of the endogenous variable affected by
% shock
% lags with defaut 0 is the list of lags at which the shock
% affects the variable with a 'sign' sign. lags is any valid
% expression that matlab can evaluate such as 0, 0:3, [1,4,5],
% [1,inf,2,5] or more generally a:b, [a:b,c,d], etc.
%
% shock_names (cellstr): cell of structural shock names
%
% Returns:
% :
%
% - **Rfunc** (function handle): a function that takes parameters and then returns structural shock matrix. This function function is not intended to be used used on its own, and supposed to be used as an argument in different functions.
%
% See also:
% - :func:`autocov <var.autocov>`
% - :func:`forecast <var.forecast>`
% - :func:`historical_decomposition <var.historical_decomposition>`
% - :func:`irf <var.irf>`
% - :func:`variance_decomposition <var.variance_decomposition>`
%
%
% Parses identifying restrictions into RISE interpretable identification function
%
% Note:
% This function is a part of a general workflow. See XXXXXXXXXX to check the workflow.
%
% ::
%
% Rfunc = identification(var, restr, shock_names, varargin);
%
% Args:
% var (rfvar object): rfvar object
% restr : restrictions can take two forms
%
% - **'choleski'**: choleski identification. Supply the ordering as a cell array as varargin{1}
% - **cellstr**: n x 2 cell array, with n the number of restrictions.
% A typical restriction takes the form:
% - 'vbl@shk','sign'
% - 'vbl{lags}@shk','sign'
% where sign = +|-
% where shk is the name of the shock
% where vbl is the name of the endogenous variable affected by
% shock
% lags with defaut 0 is the list of lags at which the shock
% affects the variable with a 'sign' sign. lags is any valid
% expression that matlab can evaluate such as 0, 0:3, [1,4,5],
% [1,inf,2,5] or more generally a:b, [a:b,c,d], etc.
%
% shock_names (cellstr): cell of structural shock names
%
% Returns:
% :
%
% - **Rfunc** (function handle): a function that takes parameters and then returns structural shock matrix. This function function is not intended to be used used on its own, and supposed to be used as an argument in different functions.
%
% See also:
% - :func:`autocov <var.autocov>`
% - :func:`forecast <var.forecast>`
% - :func:`historical_decomposition <var.historical_decomposition>`
% - :func:`irf <var.irf>`
% - :func:`variance_decomposition <var.variance_decomposition>`
%
%
Binary file modified classes/models/+dsge_tools/identification.p
Binary file not shown.
Binary file modified classes/models/+dsge_tools/linear_dsge_generator.p
Binary file not shown.
118 changes: 92 additions & 26 deletions classes/models/+vartools/autocorr.m
Original file line number Diff line number Diff line change
@@ -1,27 +1,93 @@
function [C,R,info]=autocorr(varargin)
% INTERNAL FUNCTION
% AUTOCORR Sample autocorrelation
%
% Syntax:
%
% [acf,lags,bounds] = autocorr(y)
% [acf,lags,bounds] = autocorr(y,param,val,...)
% [acf,lags,bounds,h] = autocorr(...)
% [acf,lags,bounds,h] = autocorr(ax,...)
% autocorr(...)
%
% Description:
%
% Compute the sample autocorrelation function (ACF) of a univariate,
% stochastic time series y. AUTOCORR optionally plots the ACF sequence
% with confidence bounds.
%
% Input Arguments:
%
% y - Vector of observations of a univariate time series. The last
% element of y contains the most recent observation.
%
% ax - Axes object in which to plot. If unspecified, AUTOCORR plots to
% the current axes (gca).
%
% Optional Input Parameter Name/Value Pairs:
%
% 'NumLags' Positive integer that determines the number of lags at which the
% ACF is computed. The lags used to compute the ACF are 0:NumLags.
% The default is min[20,N-1], where N is the effective sample size
% of y.
%
% 'NumMA' For computing confidence bounds, a nonnegative integer less
% than NumLags specifying the number of lags in a theoretical
% MA(NumMA) model of y. For lags > NumMA, AUTOCORR uses
% Bartlett's approximation [1] to compute the standard error
% under the model assumption. The default is 0, in which case
% the standard error is 1/sqrt(N), for Gaussian white noise.
%
% 'NumSTD' For computing confidence bounds, a nonnegative scalar multiple
% specifying an interval of +/-(NumSTD) times the computed
% standard error. The default is 2 (approximate 95% confidence).
%
% Output Arguments:
%
% acf - Sample ACF. Vector of length NumLags+1 of values computed at lags
% 0,1,2,...,NumLags. For all y, acf(1) = 1 at lag 0.
%
% lags - Vector of lag numbers of length NumLags+1 used to compute acf.
%
% bounds - Two-element vector of approximate upper and lower confidence
% bounds, assuming that y is an MA(NumMA) process.
%
% h - Vector of handles to plotted graphics objects. AUTOCORR plots the
% ACF when the number of output arguments is 0 or 4.
%
% Notes:
%
% o Specify missing observations of y using NaN. AUTOCORR treats these
% values as "missing completely at random."
%
% o If y is fully observed, without NaNs, AUTOCORR uses a Fourier
% transform to compute the ACF in the frequency domain, then converts
% back to the time domain using an inverse Fourier transform.
%
% o In the presence of NaNs, AUTOCORR computes the ACF at lag k in the
% time domain, including in the sample average only those terms for
% which the cross product y(t)*y(t+k) exists, so that the effective
% sample size at any lag is a random variable.
%
% Example:
%
% % Create an MA(2) process from a sequence of 1000 Gaussian deviates,
% % and assess whether the ACF is effectively zero for lags > 2:
%
% x = randn(1000,1); % 1000 Gaussian deviates ~ N(0,1)
% y = filter([1 -1 1],1,x); % Create an MA(2) process
% autocorr(y,'NumMA',2) % Inspect the ACF with 95% confidence
%
% References:
%
% [1] Box, G. E. P., G. M. Jenkins, and G. C. Reinsel. Time Series
% Analysis: Forecasting and Control. 3rd edition. Upper Saddle River,
% NJ: Prentice-Hall, 1994.
%
% [2] Hamilton, J.D. Time Series Analysis. Princeton, NJ: Princeton
% University Press, 1994.
%
% See also PARCORR, CROSSCORR, FILTER.
%

[C,info]=vartools.autocov(varargin{:});

stdevmat=sqrt(diag(C(:,:,1)));

bad=stdevmat<=0;

if any(bad)

warning([mfilename,':: have zero or negative theoretical standard deviation'])

end

stdevmat=stdevmat*stdevmat';

R=C;

for ii=1:size(C,3)

R(:,:,ii)=R(:,:,ii)./stdevmat;

end

end
% Reference page in Doc Center
% doc autocorr
%
%
Binary file added classes/models/+vartools/autocorr.p
Binary file not shown.
52 changes: 25 additions & 27 deletions classes/models/+vartools/autocov.m
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
%--- help for abstvar/autocov ---
%
% --- help for abstvar/autocov ---
%
% Compute the autocovariances (and the auto-correlation) of endogenous variables given the parameter values
%
% ::
%
% [C,R] = autocov(self);
% [C,R] = autocov(self, params);
% [C,R] = autocov(self, params, max_periods);
%
% Args:
% self (var object): var object
% params (cell of struct): struct containing var model related parameters (default: [])
% max_periods (integer): maximum number of period to calculate auto-covariance (default: 5)
%
% Returns:
% :
%
% - **C** [4-dimensional array]: auto-covariance where dimensions correspond to
%
% - 1,2: covariance
% - 3: time lags
% - 4: Number of parameters
%
% - **R** [4-dimensional array]: auto-correlation with same dimensions
%
%
% Compute the autocovariances (and the auto-correlation) of endogenous variables given the parameter values
%
% ::
%
% [C,R] = autocov(self);
% [C,R] = autocov(self, params);
% [C,R] = autocov(self, params, max_periods);
%
% Args:
% self (var object): var object
% params (cell of struct): struct containing var model related parameters (default: [])
% max_periods (integer): maximum number of period to calculate auto-covariance (default: 5)
%
% Returns:
% :
%
% - **C** [4-dimensional array]: auto-covariance where dimensions correspond to
%
% - 1,2: covariance
% - 3: time lags
% - 4: Number of parameters
%
% - **R** [4-dimensional array]: auto-correlation with same dimensions
%
%
Binary file modified classes/models/+vartools/autocov.p
Binary file not shown.
44 changes: 5 additions & 39 deletions classes/models/+vartools/data.m
Original file line number Diff line number Diff line change
@@ -1,45 +1,11 @@
%--- help for ts ---
%--- help for date ---
%
% Constructor for the time series (ts) object
%
% ::
%
% self=ts(); % construct a time series with no observations
% self=ts(start_date,data);
% self=ts(start_date,data,varnames);
% self=ts(start_date,data,varnames,description);
% self=ts(start_date,data,varnames,description,trailnans);
%
% Args:
%
% start_date (integer | char | serial date): start date of
% the time series. The following are admitted:
%
% - annual data : e.g. 1990 or '1990'
% - bi-annual data : e.g. '1990H1'
% - Quarterly data : e.g. '1990Q3'
% - monthly data : e.g. '1990M12'
%
% data (numeric): the format is nobs x nvars x npages,
% where:
%
% - **nobs** is the number of observations
% - **nvars** is the number of variables
% - **npages** is the number of pages (3rd dimension)
%
% varnames (char | cellstr): names of the variables in the
% database
% description (char | cellstr | {''}): comments on each
% variable in the database
% trailnans (true|{false}): keep or remove nans (missing observations)
%
% Returns:
% :
%
% - **self** [ts] : time series
% DATE Current date as character vector.
% S = DATE returns a character vector containing the date in dd-mmm-yyyy format.
%
% See also NOW, CLOCK, DATENUM.
%
% Reference page in Doc Center
% doc ts
% doc date
%
%
Loading

0 comments on commit 62891b7

Please sign in to comment.