Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • giovanma/dynare
  • giorgiomas/dynare
  • Vermandel/dynare
  • Dynare/dynare
  • normann/dynare
  • MichelJuillard/dynare
  • wmutschl/dynare
  • FerhatMihoubi/dynare
  • sebastien/dynare
  • lnsongxf/dynare
  • rattoma/dynare
  • CIMERS/dynare
  • FredericKarame/dynare
  • SumuduK/dynare
  • MinjeJeon/dynare
  • camilomrch/dynare
  • DoraK/dynare
  • avtishin/dynare
  • selma/dynare
  • claudio_olguin/dynare
  • jeffjiang07/dynare
  • EthanSystem/dynare
  • stepan-a/dynare
  • wjgatt/dynare
  • JohannesPfeifer/dynare
  • gboehl/dynare
  • chskcau/dynare-doc-fixes
27 results
Select Git revision
Loading items
Show changes
Showing
with 601 additions and 166 deletions
function C = setdiff(A,B) % --*-- Unitary tests --*--
%@info:
%! @deftypefn {Function File} {@var{C} =} setdiff (@var{A},@var{B})
%! @anchor{@dates/intersect}
%! @sp 1
%! C of B and A.
%! if A and B are not disjoints.
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item A
%! @ref{dates} object.
%! @item B
%! @ref{dates} object.
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item C
%! @ref{dates} object.
%! @end table
%! @end deftypefn
%@eod:
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~isa(A,'dates') || ~isa(B,'dates')
error(['dates::plus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must be dates objects!'])
end
if eq(A,B)
C = A;
return
end
if ~isequal(A.freq,B.freq)
C = dates();
return
end
if isoctave || matlab_ver_less_than('8.1.0')
time = setdiff(A.time,B.time,'rows');
else
time = setdiff(A.time,B.time,'rows','legacy');
end
C = dates();
if isempty(time)
return
end
C.freq = A.freq;
C.time = time;
C.ndat = rows(time);
%@test:1
%$ % Define some dates objects
%$ d1 = dates('1950Q1'):dates('1969Q4') ;
%$ d2 = dates('1960Q1'):dates('1969Q4') ;
%$ d3 = dates('1970Q1'):dates('1979Q4') ;
%$
%$ % Call the tested routine.
%$ c1 = intersect(d1,d2);
%$ c2 = intersect(d1,d3);
%$
%$ % Check the results.
%$ t(1) = dyn_assert(isequal(c1,d2),1);
%$ t(2) = dyn_assert(isempty(c2),1);
%$ T = all(t);
%@eof:1
\ No newline at end of file
...@@ -23,7 +23,7 @@ separator = repmat(' | ',A.nobs+1,1); ...@@ -23,7 +23,7 @@ separator = repmat(' | ',A.nobs+1,1);
vspace = ' '; vspace = ' ';
TABLE = ' '; TABLE = ' ';
for t=1:A.nobs for t=1:A.nobs
TABLE = char(TABLE, format(A.dates(t))); TABLE = char(TABLE, date2string(A.dates(t)));
end end
for i = 1:A.vobs for i = 1:A.vobs
TABLE = horzcat(TABLE,separator); TABLE = horzcat(TABLE,separator);
......
...@@ -97,7 +97,7 @@ switch nargin ...@@ -97,7 +97,7 @@ switch nargin
if isdates(varargin{1}) if isdates(varargin{1})
switch length(varargin{1}) switch length(varargin{1})
case 0 case 0
error(['dseries::dseries: Input ' inputname(1) ' (identified as a dates object) must be non empty!']) error(['dseries::dseries: Input (identified as a dates object) must be non empty!'])
case 1 case 1
% Create an empty dseries object with an initial date. % Create an empty dseries object with an initial date.
ts.init = varargin{1}; ts.init = varargin{1};
...@@ -131,7 +131,7 @@ switch nargin ...@@ -131,7 +131,7 @@ switch nargin
[freq,init,data,varlist] = load_xls_file_data(varargin{1}, sheet, range); [freq,init,data,varlist] = load_xls_file_data(varargin{1}, sheet, range);
tex = []; tex = [];
else else
error(['dseries:: I''m not able to load data from ' inputname(1) '!']) error(['dseries:: I''m not able to load data from ' varargin{1} '!'])
end end
ts.init = init; ts.init = init;
ts.freq = freq; ts.freq = freq;
......
...@@ -23,7 +23,7 @@ function A = minus(B,C) % --*-- Unitary tests --*-- ...@@ -23,7 +23,7 @@ function A = minus(B,C) % --*-- Unitary tests --*--
%! @end deftypefn %! @end deftypefn
%@eod: %@eod:
% Copyright (C) 2012-2013 Dynare Team % Copyright (C) 2012-2014, Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -40,38 +40,22 @@ function A = minus(B,C) % --*-- Unitary tests --*-- ...@@ -40,38 +40,22 @@ function A = minus(B,C) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isnumeric(B) && isreal(B) && isequal(length(B),1) && isdseries(C) if isnumeric(B) && (isscalar(B) || isvector(B))
A = dseries(); if ~isdseries(C)
A.freq = C.freq; error('dseries::minus: Second input argument must be a dseries object!')
A.init = C.init;
A.dates = C.dates;
A.nobs = C.nobs;
A.vobs = C.vobs;
A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1);
for i=1:A.vobs
A.name(i) = {['minus(' num2str(B) ',' C.name{i} ')']};
A.tex(i) = {['(' num2str(B) '-' C.tex{i} ')']};
end end
A.data = bsxfun(@minus, B, C.data); A = C;
A.data = bsxfun(@minus,C.data,B);
return; return;
end end
if isnumeric(C) && isreal(C) && isequal(length(C),1) && isdseries(B) if isnumeric(C) && (isscalar(C) || isvector(C))
A = dseries(); if ~isdseries(B)
A.freq = B.freq; error('dseries::minus: First input argument must be a dseries object!')
A.init = B.init;
A.dates = B.dates;
A.nobs = B.nobs;
A.vobs = B.vobs;
A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1);
for i=1:A.vobs
A.name(i) = {['minus(' B.name{i} ',' num2str(C) ')']};
A.tex(i) = {['(' B.tex{i} '-' num2str(C) ')']};
end end
A = B;
A.data = bsxfun(@minus,B.data,C); A.data = bsxfun(@minus,B.data,C);
return; return
end end
if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1)) if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
...@@ -117,7 +101,7 @@ A.vobs = max(B.vobs,C.vobs); ...@@ -117,7 +101,7 @@ A.vobs = max(B.vobs,C.vobs);
A.name = cell(A.vobs,1); A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1); A.tex = cell(A.vobs,1);
for i=1:A.vobs for i=1:A.vobs
A.name(i) = {['minus(' B.name{idB(i)} ',' C.name{idC(i)} ')']}; A.name(i) = {['minus(' B.name{idB(i)} ';' C.name{idC(i)} ')']};
A.tex(i) = {['(' B.tex{idB(i)} '-' C.tex{idC(i)} ')']}; A.tex(i) = {['(' B.tex{idB(i)} '-' C.tex{idC(i)} ')']};
end end
A.data = bsxfun(@minus,B.data,C.data); A.data = bsxfun(@minus,B.data,C.data);
...@@ -145,7 +129,7 @@ A.data = bsxfun(@minus,B.data,C.data); ...@@ -145,7 +129,7 @@ A.data = bsxfun(@minus,B.data,C.data);
%$ t(2) = dyn_assert(ts3.vobs,2); %$ t(2) = dyn_assert(ts3.vobs,2);
%$ t(3) = dyn_assert(ts3.nobs,10); %$ t(3) = dyn_assert(ts3.nobs,10);
%$ t(4) = dyn_assert(ts3.data,[A(:,1)-B, A(:,2)-B],1e-15); %$ t(4) = dyn_assert(ts3.data,[A(:,1)-B, A(:,2)-B],1e-15);
%$ t(5) = dyn_assert(ts3.name,{'minus(A1,B1)';'minus(A2,B1)'}); %$ t(5) = dyn_assert(ts3.name,{'minus(A1;B1)';'minus(A2;B1)'});
%$ end %$ end
%$ T = all(t); %$ T = all(t);
%@eof:1 %@eof:1
...@@ -173,7 +157,7 @@ A.data = bsxfun(@minus,B.data,C.data); ...@@ -173,7 +157,7 @@ A.data = bsxfun(@minus,B.data,C.data);
%$ t(2) = dyn_assert(ts3.vobs,2); %$ t(2) = dyn_assert(ts3.vobs,2);
%$ t(3) = dyn_assert(ts3.nobs,10); %$ t(3) = dyn_assert(ts3.nobs,10);
%$ t(4) = dyn_assert(ts3.data,[A(1:5,1)-B(1:5), A(1:5,2)-B(1:5) ; NaN(5,2)],1e-15); %$ t(4) = dyn_assert(ts3.data,[A(1:5,1)-B(1:5), A(1:5,2)-B(1:5) ; NaN(5,2)],1e-15);
%$ t(5) = dyn_assert(ts3.name,{'minus(A1,B1)';'minus(A2,B1)'}); %$ t(5) = dyn_assert(ts3.name,{'minus(A1;B1)';'minus(A2;B1)'});
%$ end %$ end
%$ T = all(t); %$ T = all(t);
%@eof:3 %@eof:3
function A = mpower(B,C) % --*-- Unitary tests --*--
%@info:
%! @deftypefn {Function File} {@var{A} =} mpower (@var{B},@var{C})
%! @anchor{@dseries/mpower}
%! @sp 1
%! Overloads the mpower method for the Dynare time series class (@ref{dseries}).
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item B
%! Dynare time series object instantiated by @ref{dseries}, with T observations and N variables.
%! @item C
%! Real scalar or a dseries object with T observations and N variables.
%! @end table
%! @sp 1
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item A
%! dseries object with T observations and N variables.
%! @end deftypefn
%@eod:
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C)
A = dseries();
A.freq = B.freq;
A.init = B.init;
A.dates = B.dates;
A.nobs = B.nobs;
A.vobs = B.vobs;
A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1);
for i=1:A.vobs
A.name(i) = {['power(' B.name{i} ';' num2str(C) ')']};
A.tex(i) = {[B.tex{i} '^' num2str(C) ]};
end
A.data = B.data.^C;
return
end
if isdseries(B) && isdseries(C)
if isequal(B.nobs,C.nobs) && isequal(B.vobs,C.vobs) && isequal(B.freq,C.freq)
A = dseries();
A.freq = B.freq;
A.init = B.init;
A.dates = B.dates;
A.nobs = B.nobs;
A.vobs = B.vobs;
A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1);
for i=1:A.vobs
A.name(i) = {['power(' B.name{i} ';' C.name{i} ')']};
A.tex(i) = {[B.tex{i} '^{' C.tex{i} '}']};
end
A.data = B.data.^C.data;
else
error('dseries::mpower: If both input arguments are dseries objects, they must have the same numbers of variables and observations and common frequency!')
end
return
end
error(['dseries::mpower: Wrong calling sequence!'])
%@test:1
%$ % Define a datasets.
%$ A = rand(10,2); B = randn(10,2);
%$
%$ % Define names
%$ A_name = {'A1';'A2'}; B_name = {'B1';'B2'};
%$
%$
%$ % Instantiate a time series object.
%$ try
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts2 = dseries(B,[],B_name,[]);
%$ ts3 = ts1^ts2;
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dyn_assert(ts3.vobs,2);
%$ t(3) = dyn_assert(ts3.nobs,10);
%$ t(4) = dyn_assert(ts3.data,A.^B,1e-15);
%$ t(5) = dyn_assert(ts3.name,{'power(A1;B1)';'power(A2;B2)'});
%$ t(6) = dyn_assert(ts3.tex,{'A1^{B1}';'A2^{B2}'});
%$ end
%$ T = all(t);
%@eof:1
%@test:2
%$ % Define a datasets.
%$ A = rand(10,2);
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$
%$
%$ % Instantiate a time series object.
%$ try
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts3 = ts1^2;
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dyn_assert(ts3.vobs,2);
%$ t(3) = dyn_assert(ts3.nobs,10);
%$ t(4) = dyn_assert(ts3.data,A.^2,1e-15);
%$ t(5) = dyn_assert(ts3.name,{'power(A1;2)';'power(A2;2)'});
%$ t(6) = dyn_assert(ts3.tex,{'A1^2';'A2^2'});
%$ end
%$ T = all(t);
%@eof:2
...@@ -23,7 +23,7 @@ function A = mrdivide(B,C) % --*-- Unitary tests --*-- ...@@ -23,7 +23,7 @@ function A = mrdivide(B,C) % --*-- Unitary tests --*--
%! @end deftypefn %! @end deftypefn
%@eod: %@eod:
% Copyright (C) 2012-2013 Dynare Team % Copyright (C) 2012-2014 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -40,6 +40,24 @@ function A = mrdivide(B,C) % --*-- Unitary tests --*-- ...@@ -40,6 +40,24 @@ function A = mrdivide(B,C) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isnumeric(B) && (isscalar(B) || isvector(B))
if ~isdseries(C)
error('dseries::mrdivide: Second input argument must be a dseries object!')
end
A = C;
A.data = bsxfun(@rdivide,B,C.data);
return;
end
if isnumeric(C) && (isscalar(C) || isvector(C))
if ~isdseries(B)
error('dseries::mrdivide: First input argument must be a dseries object!')
end
A = B;
A.data = bsxfun(@rdivide,B.data,C);
return
end
if isdseries(B) && isdseries(C) if isdseries(B) && isdseries(C)
% Element by element divisions of two dseries object % Element by element divisions of two dseries object
if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1)) if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
...@@ -71,40 +89,10 @@ if isdseries(B) && isdseries(C) ...@@ -71,40 +89,10 @@ if isdseries(B) && isdseries(C)
A.name = cell(A.vobs,1); A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1); A.tex = cell(A.vobs,1);
for i=1:A.vobs for i=1:A.vobs
A.name(i) = {['divide(' B.name{idB(i)} ',' C.name{idC(i)} ')']}; A.name(i) = {['divide(' B.name{idB(i)} ';' C.name{idC(i)} ')']};
A.tex(i) = {['(' B.tex{idB(i)} '/' C.tex{idC(i)} ')']}; A.tex(i) = {['(' B.tex{idB(i)} '/' C.tex{idC(i)} ')']};
end end
A.data = bsxfun(@rdivide,B.data,C.data); A.data = bsxfun(@rdivide,B.data,C.data);
elseif isnumeric(C) && isreal(C) && isequal(length(C),1) && isdseries(B)
% division of a dseries object by a real scalar.
A = dseries();
A.freq = B.freq;
A.dates = B.dates;
A.init = B.init;
A.nobs = B.nobs;
A.vobs = B.vobs;
A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1);
for i=1:A.vobs
A.name(i) = {['divide(' B.name{i} ',' num2str(C) ')']};
A.tex(i) = {['(' B.tex{i} '/' num2str(C) ')']};
end
A.data = B.data/C;
elseif isnumeric(B) && isreal(B) && isequal(length(B),1) && isdseries(C)
% division of a real scalar by a dseries object.
A = dseries();
A.freq = C.freq;
A.dates = C.dates;
A.init = C.init;
A.nobs = C.nobs;
A.vobs = C.vobs;
A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1);
for i=1:A.vobs
A.name(i) = {['divide(' num2str(B) ',' C.name{i} ')']};
A.tex(i) = {['(' num2str(B) '/' C.tex{i} ')']};
end
A.data = B./C.data;
else else
error() error()
end end
......
...@@ -23,7 +23,7 @@ function A = mtimes(B,C) % --*-- Unitary tests --*-- ...@@ -23,7 +23,7 @@ function A = mtimes(B,C) % --*-- Unitary tests --*--
%! @end deftypefn %! @end deftypefn
%@eod: %@eod:
% Copyright (C) 2012-2013 Dynare Team % Copyright (C) 2012-2014 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -40,6 +40,24 @@ function A = mtimes(B,C) % --*-- Unitary tests --*-- ...@@ -40,6 +40,24 @@ function A = mtimes(B,C) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isnumeric(B) && (isscalar(B) || isvector(B))
if ~isdseries(C)
error('dseries::mtimes: Second input argument must be a dseries object!')
end
A = C;
A.data = bsxfun(@times,C.data,B);
return;
end
if isnumeric(C) && (isscalar(C) || isvector(C))
if ~isdseries(B)
error('dseries::mtimes: First input argument must be a dseries object!')
end
A = B;
A.data = bsxfun(@times,B.data,C);
return
end
if isdseries(B) && isdseries(C) if isdseries(B) && isdseries(C)
% Element by element multiplication of two dseries object % Element by element multiplication of two dseries object
if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1)) if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
...@@ -71,40 +89,10 @@ if isdseries(B) && isdseries(C) ...@@ -71,40 +89,10 @@ if isdseries(B) && isdseries(C)
A.name = cell(A.vobs,1); A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1); A.tex = cell(A.vobs,1);
for i=1:A.vobs for i=1:A.vobs
A.name(i) = {['multiply(' B.name{idB(i)} ',' C.name{idC(i)} ')']}; A.name(i) = {['multiply(' B.name{idB(i)} ';' C.name{idC(i)} ')']};
A.tex(i) = {['(' B.tex{idB(i)} '*' C.tex{idC(i)} ')']}; A.tex(i) = {['(' B.tex{idB(i)} '*' C.tex{idC(i)} ')']};
end end
A.data = bsxfun(@times,B.data,C.data); A.data = bsxfun(@times,B.data,C.data);
elseif isnumeric(C) && isreal(C) && isequal(length(C),1) && isdseries(B)
% Multiplication of a dseries object by a real scalar.
A = dseries();
A.freq = B.freq;
A.init = B.init;
A.dates = B.dates;
A.nobs = B.nobs;
A.vobs = B.vobs;
A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1);
for i=1:A.vobs
A.name(i) = {['multiply(' B.name{i} ',' num2str(C) ')']};
A.tex(i) = {['(' B.tex{i} '*' num2str(C) ')']};
end
A.data = B.data*C;
elseif isnumeric(B) && isreal(B) && isequal(length(B),1) && isdseries(C)
% Multiplication of a dseries object by a real scalar.
A = dseries();
A.freq = C.freq;
A.init = C.init;
A.dates = C.dates;
A.nobs = C.nobs;
A.vobs = C.vobs;
A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1);
for i=1:A.vobs
A.name(i) = {['multiply(' num2str(B) ',' C.name{i} ')']};
A.tex(i) = {['(' num2str(B) '*' C.tex{i} ')']};
end
A.data = C.data*B;
else else
error() error()
end end
...@@ -131,7 +119,7 @@ end ...@@ -131,7 +119,7 @@ end
%$ t(2) = dyn_assert(ts3.vobs,2); %$ t(2) = dyn_assert(ts3.vobs,2);
%$ t(3) = dyn_assert(ts3.nobs,10); %$ t(3) = dyn_assert(ts3.nobs,10);
%$ t(4) = dyn_assert(ts3.data,[A(:,1).*B, A(:,2).*B],1e-15); %$ t(4) = dyn_assert(ts3.data,[A(:,1).*B, A(:,2).*B],1e-15);
%$ t(5) = dyn_assert(ts3.name,{'multiply(A1,B1)';'multiply(A2,B1)'}); %$ t(5) = dyn_assert(ts3.name,{'multiply(A1;B1)';'multiply(A2;B1)'});
%$ end %$ end
%$ T = all(t); %$ T = all(t);
%@eof:1 %@eof:1
...@@ -157,7 +145,6 @@ end ...@@ -157,7 +145,6 @@ end
%$ t(2) = dyn_assert(ts2.vobs,2); %$ t(2) = dyn_assert(ts2.vobs,2);
%$ t(3) = dyn_assert(ts2.nobs,10); %$ t(3) = dyn_assert(ts2.nobs,10);
%$ t(4) = dyn_assert(ts2.data,A*B,1e-15); %$ t(4) = dyn_assert(ts2.data,A*B,1e-15);
%$ t(5) = dyn_assert(ts2.name,{['multiply(A1,' num2str(pi) ')'];['multiply(A2,' num2str(pi) ')']});
%$ end %$ end
%$ T = all(t); %$ T = all(t);
%@eof:2 %@eof:2
...@@ -183,7 +170,31 @@ end ...@@ -183,7 +170,31 @@ end
%$ t(2) = dyn_assert(ts2.vobs,2); %$ t(2) = dyn_assert(ts2.vobs,2);
%$ t(3) = dyn_assert(ts2.nobs,10); %$ t(3) = dyn_assert(ts2.nobs,10);
%$ t(4) = dyn_assert(ts2.data,A*B,1e-15); %$ t(4) = dyn_assert(ts2.data,A*B,1e-15);
%$ t(5) = dyn_assert(ts2.name,{['multiply(' num2str(pi) ',A1)'];['multiply(' num2str(pi) ',A2)']});
%$ end %$ end
%$ T = all(t); %$ T = all(t);
%@eof:3 %@eof:3
%@test:4
%$ % Define a datasets.
%$ A = rand(10,2); B = A(1,:);
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$
%$
%$ % Instantiate a time series object.
%$ try
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts2 = B*ts1;
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dyn_assert(ts2.vobs,2);
%$ t(3) = dyn_assert(ts2.nobs,10);
%$ t(4) = dyn_assert(ts2.data,bsxfun(@times,A,B),1e-15);
%$ end
%$ T = all(t);
%@eof:4
...@@ -56,6 +56,7 @@ switch ndseries ...@@ -56,6 +56,7 @@ switch ndseries
end end
hh = plot(ts.data); hh = plot(ts.data);
end end
axis tight;
id = get(gca,'XTick'); id = get(gca,'XTick');
if isequal(id(1),0) if isequal(id(1),0)
dates = strings([ts.dates(1)-1,ts.dates(id(2:end))]); dates = strings([ts.dates(1)-1,ts.dates(id(2:end))]);
......
...@@ -23,7 +23,7 @@ function A = plus(B,C) % --*-- Unitary tests --*-- ...@@ -23,7 +23,7 @@ function A = plus(B,C) % --*-- Unitary tests --*--
%! @end deftypefn %! @end deftypefn
%@eod: %@eod:
% Copyright (C) 2011-2013 Dynare Team % Copyright (C) 2011-2014 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -40,37 +40,21 @@ function A = plus(B,C) % --*-- Unitary tests --*-- ...@@ -40,37 +40,21 @@ function A = plus(B,C) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isnumeric(B) && isscalar(B) if isnumeric(B) && (isscalar(B) || isvector(B))
if ~isdseries(C) if ~isdseries(C)
error('dseries::plus: Second input argument must be a dseries object!') error('dseries::plus: Second input argument must be a dseries object!')
end end
b(1:size(C)) = B; A = C;
BB = dseries(b, C.dates(1)); A.data = bsxfun(@plus,C.data,B);
BB.freq = C.freq;
BB.dates = C.dates;
BB.nobs = C.nobs;
BB.vobs = C.vobs;
BB.name = cell(BB.vobs,1);
BB.tex = cell(BB.vobs,1);
BB.name(1) = {num2str(B)};
A = BB + C;
return; return;
end end
if isnumeric(C) && isscalar(C) if isnumeric(C) && (isscalar(C) || isvector(C))
if ~isdseries(B) if ~isdseries(B)
error('dseries::plus: First input argument must be a dseries object!') error('dseries::plus: First input argument must be a dseries object!')
end end
c(1:size(C)) = C; A = B;
CC = dseries(C, B.dates(1)); A.data = bsxfun(@plus,B.data,C);
CC.freq = B.freq;
CC.dates = B.dates;
CC.nobs = B.nobs;
CC.vobs = B.vobs;
CC.name = cell(CC.vobs,1);
CC.tex = cell(CC.vobs,1);
CC.name(1) = {num2str(C)};
A = B + CC;
return return
end end
...@@ -116,7 +100,7 @@ A.vobs = max(B.vobs,C.vobs); ...@@ -116,7 +100,7 @@ A.vobs = max(B.vobs,C.vobs);
A.name = cell(A.vobs,1); A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1); A.tex = cell(A.vobs,1);
for i=1:A.vobs for i=1:A.vobs
A.name(i) = {['plus(' B.name{idB(i)} ',' C.name{idC(i)} ')']}; A.name(i) = {['plus(' B.name{idB(i)} ';' C.name{idC(i)} ')']};
A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']}; A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']};
end end
A.data = bsxfun(@plus,B.data,C.data); A.data = bsxfun(@plus,B.data,C.data);
...@@ -145,7 +129,7 @@ A.dates = A.init:A.init+(A.nobs-1); ...@@ -145,7 +129,7 @@ A.dates = A.init:A.init+(A.nobs-1);
%$ t(2) = dyn_assert(ts3.vobs,2); %$ t(2) = dyn_assert(ts3.vobs,2);
%$ t(3) = dyn_assert(ts3.nobs,10); %$ t(3) = dyn_assert(ts3.nobs,10);
%$ t(4) = dyn_assert(ts3.data,[A(:,1)+B, A(:,2)+B],1e-15); %$ t(4) = dyn_assert(ts3.data,[A(:,1)+B, A(:,2)+B],1e-15);
%$ t(5) = dyn_assert(ts3.name,{'plus(A1,B1)';'plus(A2,B1)'}); %$ t(5) = dyn_assert(ts3.name,{'plus(A1;B1)';'plus(A2;B1)'});
%$ end %$ end
%$ T = all(t); %$ T = all(t);
%@eof:1 %@eof:1
...@@ -174,7 +158,7 @@ A.dates = A.init:A.init+(A.nobs-1); ...@@ -174,7 +158,7 @@ A.dates = A.init:A.init+(A.nobs-1);
%$ t(2) = dyn_assert(ts4.vobs,2); %$ t(2) = dyn_assert(ts4.vobs,2);
%$ t(3) = dyn_assert(ts4.nobs,10); %$ t(3) = dyn_assert(ts4.nobs,10);
%$ t(4) = dyn_assert(ts4.data,[A(:,1)+B, A(:,2)+B]+A,1e-15); %$ t(4) = dyn_assert(ts4.data,[A(:,1)+B, A(:,2)+B]+A,1e-15);
%$ t(5) = dyn_assert(ts4.name,{'plus(plus(A1,B1),A1)';'plus(plus(A2,B1),A2)'}); %$ t(5) = dyn_assert(ts4.name,{'plus(plus(A1;B1);A1)';'plus(plus(A2;B1);A2)'});
%$ end %$ end
%$ T = all(t); %$ T = all(t);
%@eof:2 %@eof:2
...@@ -203,7 +187,7 @@ A.dates = A.init:A.init+(A.nobs-1); ...@@ -203,7 +187,7 @@ A.dates = A.init:A.init+(A.nobs-1);
%$ t(2) = dyn_assert(ts3.vobs,2); %$ t(2) = dyn_assert(ts3.vobs,2);
%$ t(3) = dyn_assert(ts3.nobs,10); %$ t(3) = dyn_assert(ts3.nobs,10);
%$ t(4) = dyn_assert(ts3.data,[A(1:5,1)+B(1:5), A(1:5,2)+B(1:5) ; NaN(5,2)],1e-15); %$ t(4) = dyn_assert(ts3.data,[A(1:5,1)+B(1:5), A(1:5,2)+B(1:5) ; NaN(5,2)],1e-15);
%$ t(5) = dyn_assert(ts3.name,{'plus(A1,B1)';'plus(A2,B1)'}); %$ t(5) = dyn_assert(ts3.name,{'plus(A1;B1)';'plus(A2;B1)'});
%$ end %$ end
%$ T = all(t); %$ T = all(t);
%@eof:3 %@eof:3
...@@ -255,3 +239,53 @@ A.dates = A.init:A.init+(A.nobs-1); ...@@ -255,3 +239,53 @@ A.dates = A.init:A.init+(A.nobs-1);
%$ %$
%$ T = all(t); %$ T = all(t);
%@eof:5 %@eof:5
%@test:6
%$ t = zeros(8,1);
%$
%$ try
%$ ts = dseries(transpose(1:5),'1950q1',{'Output'}, {'Y_t'});
%$ us = dseries(transpose(1:7),'1950q1',{'Consumption'}, {'C_t'});
%$ vs = ts+us('1950q1').data;
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if length(t)>1
%$ t(2) = dyn_assert(ts.freq,4);
%$ t(3) = dyn_assert(us.freq,4);
%$ t(4) = dyn_assert(ts.init.time,[1950, 1]);
%$ t(5) = dyn_assert(us.init.time,[1950, 1]);
%$ t(6) = dyn_assert(vs.init.time,[1950, 1]);
%$ t(7) = dyn_assert(vs.nobs,5);
%$ t(8) = dyn_assert(vs.data,ts.data+1);
%$ end
%$
%$ T = all(t);
%@eof:6
%@test:7
%$ t = zeros(8,1);
%$
%$ try
%$ ts = dseries([transpose(1:5), transpose(1:5)],'1950q1');
%$ us = dseries([transpose(1:7),2*transpose(1:7)],'1950q1');
%$ vs = ts+us('1950q1').data;
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if length(t)>1
%$ t(2) = dyn_assert(ts.freq,4);
%$ t(3) = dyn_assert(us.freq,4);
%$ t(4) = dyn_assert(ts.init.time,[1950, 1]);
%$ t(5) = dyn_assert(us.init.time,[1950, 1]);
%$ t(6) = dyn_assert(vs.init.time,[1950, 1]);
%$ t(7) = dyn_assert(vs.nobs,5);
%$ t(8) = dyn_assert(vs.data,bsxfun(@plus,ts.data,[1, 2]));
%$ end
%$
%$ T = all(t);
%@eof:7
...@@ -8,7 +8,7 @@ function A = subsasgn(A,S,B) % --*-- Unitary tests --*-- ...@@ -8,7 +8,7 @@ function A = subsasgn(A,S,B) % --*-- Unitary tests --*--
%! @end deftypefn %! @end deftypefn
%@eod: %@eod:
% Copyright (C) 2012-2013 Dynare Team % Copyright (C) 2012-2014 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -131,10 +131,15 @@ switch length(S) ...@@ -131,10 +131,15 @@ switch length(S)
end end
end end
case '()' % Date(s) selection case '()' % Date(s) selection
if isdates(S(1).subs{1}) if isdates(S(1).subs{1}) || isdate(S(1).subs{1})
[junk, tdx] = intersect(A.dates.time,S(1).subs{1}.time,'rows'); if isdate(S(1).subs{1})
Dates = dates(S(1).subs{1});
else
Dates = S(1).subs{1};
end
[junk, tdx] = intersect(A.dates.time,Dates.time,'rows');
if isdseries(B) if isdseries(B)
[junk, tdy] = intersect(B.dates.time,S(1).subs{1}.time,'rows'); [junk, tdy] = intersect(B.dates.time,Dates.time,'rows');
if isempty(tdy) if isempty(tdy)
error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!') error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!')
end end
...@@ -214,6 +219,12 @@ switch length(S) ...@@ -214,6 +219,12 @@ switch length(S)
error('dseries::subsasgn: Wrong syntax!') error('dseries::subsasgn: Wrong syntax!')
end end
if isempty(A)
% Assign variables to an empty dseries object.
A = B;
return
end
if merge_dseries_objects if merge_dseries_objects
A = merge(A,B); A = merge(A,B);
end end
......
...@@ -175,7 +175,7 @@ switch S(1).type ...@@ -175,7 +175,7 @@ switch S(1).type
end end
end end
case '()' case '()'
if ischar(S(1).subs{1}) if ischar(S(1).subs{1}) && ~isdate(S(1).subs{1})
% If ts is an empty dseries object, populate this object by reading data in a file. % If ts is an empty dseries object, populate this object by reading data in a file.
if isempty(A) if isempty(A)
B = dseries(S(1).subs{1}); B = dseries(S(1).subs{1});
...@@ -203,9 +203,21 @@ switch S(1).type ...@@ -203,9 +203,21 @@ switch S(1).type
% Do nothing. % Do nothing.
B = A; B = A;
end end
elseif isdates(S(1).subs{1}) elseif isdates(S(1).subs{1}) || isdate(S(1).subs{1})
if isdate(S(1).subs{1})
Dates = dates(S(1).subs{1});
else
Dates = S(1).subs{1};
end
% Test if Dates is out of bounds
if min(Dates)<min(A.dates)
error(['dseries::subsref: Indices are out of bounds! Subsample cannot start before ' date2string(A.dates(1)) '.'])
end
if max(Dates)>max(A.dates)
error(['dseries::subsref: Indices are out of bounds! Subsample cannot end after ' date2string(A.dates(end)) '.'])
end
% Extract a subsample using a dates object % Extract a subsample using a dates object
[junk,tdx] = intersect(A.dates.time,S(1).subs{1}.time,'rows'); [junk,tdx] = intersect(A.dates.time,Dates.time,'rows');
B = dseries(); B = dseries();
B.data = A.data(tdx,:); B.data = A.data(tdx,:);
B.name = A.name; B.name = A.name;
...@@ -223,6 +235,7 @@ switch S(1).type ...@@ -223,6 +235,7 @@ switch S(1).type
if size(A.data,2)>1 if size(A.data,2)>1
S(1).subs = [S(1).subs, ':']; S(1).subs = [S(1).subs, ':'];
end end
B = dseries();
B.data = builtin('subsref', A.data, S(1)); B.data = builtin('subsref', A.data, S(1));
B.nobs = size(B.data,1); B.nobs = size(B.data,1);
B.vobs = A.vobs; B.vobs = A.vobs;
...@@ -633,3 +646,56 @@ end ...@@ -633,3 +646,56 @@ end
%$ %$
%$ T = all(t); %$ T = all(t);
%@eof:14 %@eof:14
%@test:15
%$ try
%$ ds = dseries(transpose(1:5));
%$ ts = ds(2:3);
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ if t(1)>1
%$ t(2) = isdseries(ts);
%$ t(3) = isequal(ts.data,ds.data(2:3));
%$ end
%$
%$ T = all(t);
%@eof:15
%@test:16
%$ try
%$ ds = dseries(transpose(1:5));
%$ ts = ds(2:6);
%$ t(1) = 0;
%$ catch
%$ t(1) = 1;
%$ end
%$
%$ T = all(t);
%@eof:16
%@test:17
%$ try
%$ ds = dseries(transpose(1:5));
%$ ts = ds(dates('1Y'):dates('6Y'));
%$ t(1) = 0;
%$ catch
%$ t(1) = 1;
%$ end
%$
%$ T = all(t);
%@eof:17
%@test:18
%$ try
%$ ds = dseries(transpose(1:5));
%$ ts = ds(dates('-2Y'):dates('4Y'));
%$ t(1) = 0;
%$ catch
%$ t(1) = 1;
%$ end
%$
%$ T = all(t);
%@eof:18
\ No newline at end of file
function DirectoryName = CheckPath(type,dname) function [DirectoryName, info] = CheckPath(type,dname)
% Creates the subfolder "./M_.dname/type" if it does not exist yet. % Creates the subfolder "./M_.dname/type" if it does not exist yet.
% %
% INPUTS % INPUTS
...@@ -6,12 +6,13 @@ function DirectoryName = CheckPath(type,dname) ...@@ -6,12 +6,13 @@ function DirectoryName = CheckPath(type,dname)
% dname [string] Name of the directory % dname [string] Name of the directory
% %
% OUTPUTS % OUTPUTS
% none. % DirectoryName string, name of the directory (with path).
% info integer scalar, equal to 1 if the routine creates directory dname/type, zero otherwise.
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2005-2012 Dynare Team % Copyright (C) 2005-2013 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -28,6 +29,8 @@ function DirectoryName = CheckPath(type,dname) ...@@ -28,6 +29,8 @@ function DirectoryName = CheckPath(type,dname)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
info = 0;
DirectoryName = [ dname '/' type ]; DirectoryName = [ dname '/' type ];
if ~isdir(dname) if ~isdir(dname)
...@@ -44,4 +47,5 @@ if ~isdir(DirectoryName) ...@@ -44,4 +47,5 @@ if ~isdir(DirectoryName)
delete(DirectoryName) delete(DirectoryName)
end end
mkdir('.',DirectoryName); mkdir('.',DirectoryName);
info = 1;
end end
...@@ -116,7 +116,15 @@ if options_.lik_init == 1 % Kalman filter ...@@ -116,7 +116,15 @@ if options_.lik_init == 1 % Kalman filter
if kalman_algo ~= 2 if kalman_algo ~= 2
kalman_algo = 1; kalman_algo = 1;
end end
Pstar = lyapunov_symm(T,R*Q*transpose(R),options_.qz_criterium,options_.lyapunov_complex_threshold); if options_.lyapunov_fp == 1
Pstar = lyapunov_symm(T,Q,options_.lyapunov_fixed_point_tol,options_.lyapunov_complex_threshold, 3, R);
elseif options_.lyapunov_db == 1
Pstar = disclyap_fast(T,R*Q*R',options_.lyapunov_doubling_tol);
elseif options_.lyapunov_srs == 1
Pstar = lyapunov_symm(T,Q,options_.lyapunov_fixed_point_tol,options_.lyapunov_complex_threshold, 4, R);
else
Pstar = lyapunov_symm(T,R*Q*R',options_.qz_criterium,options_.lyapunov_complex_threshold);
end;
Pinf = []; Pinf = [];
elseif options_.lik_init == 2 % Old Diffuse Kalman filter elseif options_.lik_init == 2 % Old Diffuse Kalman filter
if kalman_algo ~= 2 if kalman_algo ~= 2
......
...@@ -75,6 +75,14 @@ catch ...@@ -75,6 +75,14 @@ catch
[marginal,oo_] = marginal_density(M_, options_, estim_params_, oo_); [marginal,oo_] = marginal_density(M_, options_, estim_params_, oo_);
disp(sprintf('Log data density is %f.',oo_.MarginalDensity.ModifiedHarmonicMean)) disp(sprintf('Log data density is %f.',oo_.MarginalDensity.ModifiedHarmonicMean))
end end
num_draws=NumberOfDraws*options_.mh_nblck;
hpd_draws = round((1-options_.mh_conf_sig)*num_draws);
if hpd_draws<2
fprintf('posterior_moments: There are not enough draws computes to compute HPD Intervals. Skipping their computation.\n')
end
if num_draws<9
fprintf('posterior_moments: There are not enough draws computes to compute deciles. Skipping their computation.\n')
end
if np if np
type = 'parameters'; type = 'parameters';
if TeX if TeX
......
...@@ -69,17 +69,26 @@ if issue_an_error_message ...@@ -69,17 +69,26 @@ if issue_an_error_message
error('Estimation::mcmc::diagnostics: I cannot proceed because some MCMC files are missing. Check your MCMC files...') error('Estimation::mcmc::diagnostics: I cannot proceed because some MCMC files are missing. Check your MCMC files...')
end end
PastDraws = sum(record.MhDraws,1);
LastFileNumber = PastDraws(2);
LastLineNumber = record.MhDraws(end,3);
NumberOfDraws = PastDraws(1);
if NumberOfDraws<=2000
warning(['estimation:: MCMC convergence diagnostics are not computed because the total number of iterations is less than 2000!'])
return
end
if nblck == 1 % Brooks and Gelman tests need more than one block if nblck == 1 % Brooks and Gelman tests need more than one block
convergence_diagnostics_geweke=zeros(npar,4+2*length(options_.convergence.geweke.taper_steps)); convergence_diagnostics_geweke=zeros(npar,4+2*length(options_.convergence.geweke.taper_steps));
if any(options_.convergence.geweke.geweke_interval<0) || any(options_.convergence.geweke.geweke_interval>1) || length(any(options_.convergence.geweke.geweke_interval<0))~=2 ... if any(options_.convergence.geweke.geweke_interval<0) || any(options_.convergence.geweke.geweke_interval>1) || length(options_.convergence.geweke.geweke_interval)~=2 ...
|| (options_.convergence.geweke.geweke_interval(2)-options_.convergence.geweke.geweke_interval(1)<0) || (options_.convergence.geweke.geweke_interval(2)-options_.convergence.geweke.geweke_interval(1)<0)
fprintf('\nCONVERGENCE DIAGNOSTICS: Invalid option for geweke_interval. Using the default of [0.2 0.5].\n') fprintf('\nCONVERGENCE DIAGNOSTICS: Invalid option for geweke_interval. Using the default of [0.2 0.5].\n')
options_.convergence.geweke.geweke_interval=[0.2 0.5]; options_.convergence.geweke.geweke_interval=[0.2 0.5];
end end
first_obs_begin_sample = max(1,ceil(options_.mh_drop*options_.mh_replic)); first_obs_begin_sample = max(1,ceil(options_.mh_drop*options_.mh_replic));
last_obs_begin_sample = first_obs_begin_sample+round(options_.convergence.geweke.geweke_interval(1)*options_.mh_replic*options_.mh_drop); last_obs_begin_sample = first_obs_begin_sample+round(options_.convergence.geweke.geweke_interval(1)*options_.mh_replic*(1-options_.mh_drop));
first_obs_end_sample = first_obs_begin_sample+round(options_.convergence.geweke.geweke_interval(2)*options_.mh_replic*options_.mh_drop); first_obs_end_sample = first_obs_begin_sample+round(options_.convergence.geweke.geweke_interval(2)*options_.mh_replic*(1-options_.mh_drop));
param_name=[]; param_name=[];
for jj=1:npar for jj=1:npar
param_name = strvcat(param_name,get_the_name(jj,options_.TeX,M_,estim_params_,options_)); param_name = strvcat(param_name,get_the_name(jj,options_.TeX,M_,estim_params_,options_));
...@@ -121,11 +130,6 @@ if nblck == 1 % Brooks and Gelman tests need more than one block ...@@ -121,11 +130,6 @@ if nblck == 1 % Brooks and Gelman tests need more than one block
return; return;
end end
PastDraws = sum(record.MhDraws,1);
LastFileNumber = PastDraws(2);
LastLineNumber = record.MhDraws(end,3);
NumberOfDraws = PastDraws(1);
Origin = 1000; Origin = 1000;
StepSize = ceil((NumberOfDraws-Origin)/100);% So that the computational time does not StepSize = ceil((NumberOfDraws-Origin)/100);% So that the computational time does not
ALPHA = 0.2; % increase too much with the number of simulations. ALPHA = 0.2; % increase too much with the number of simulations.
......
function plan = basic_plan(plan, exogenous, expectation_type, date, value)
% Adds a simple shock to the forecast scenario plan
%
% INPUTS
% o plan [structure] A structure describing the different shocks and the implied variables, the date of the shocks and the path of the shock (forecast scenario).
% The plan structure is created by the functions init_plan, basic_plan and flip_plan
% o exogenous [string] A string containing the name of the exognous shock.
% o expectation_type [string] A string indicating the type of expectation: 'surprise' for an unexpected shock, and 'perfect_foresight' for a perfectly anticpated shock.
% o date [dates] The period of the shock
% o value [array of double] A vector of double containing the values of the exogenous variable
%
%
% OUTPUTS
% plan [structure] Returns a structure containing the updated forecast scenario.
%
%
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~ischar(expectation_type) || size(expectation_type,1) ~= 1
error(['in basic_plan the third argument should be a string containing the simulation type (''perfect_foresight'' or ''surprise'')']);
end
exogenous = strtrim(exogenous);
ix = find(strcmp(exogenous, plan.exo_names));
if isempty(ix)
error(['in basic_plan the second argument ' exogenous ' is not an exogenous variable']);
end;
sdate = length(date);
if sdate > 1
if date(1) < plan.date(1) || date(end) > plan.date(end)
error(['in basic_plan the fourth argument (date=' date ') must lay inside the plan.date ' plan.date]);
end
else
if date < plan.date(1) || date > plan.date(end)
error(['in basic_plan the fourth argument (date=' date ') must lay iside the plan.date ' plan.date]);
end
end
if length(date) ~= length(value)
error(['in basic_plan the number of dates (' int2str(length(date)) ') is not equal to the numbers of shock (' int2str(length(value)) ') for exogenous variable ' exogenous]);
end
if ~isempty(plan.options_cond_fcst_.controlled_varexo)
common_var = find(ix == plan.options_cond_fcst_.controlled_varexo);
if ~isempty(common_var)
common_date = intersect(date, plan.constrained_date_{common_var});
if ~isempty(common_date)
date = setdiff(date, common_date);
if common_date.length > 1
the_dates = [cell2mat(strings(common_date(1))) ':' cell2mat(strings(common_date(end)))];
else
the_dates = cell2mat(strings(common_date));
end
warning(['Impossible case: ' plan.exo_names{plan.options_cond_fcst_.controlled_varexo(common_var)} ' is used both as a shock and as an endogenous variable to control the path of ' plan.endo_names{plan.constrained_vars_(common_var)} ' at the dates ' the_dates]);
end
end
end
if isempty(plan.shock_vars_)
plan.shock_vars_ = ix;
if strcmp(expectation_type, 'perfect_foresight')
plan.shock_perfect_foresight_ = 1;
else
plan.shock_perfect_foresight_ = 0;
end
else
plan.shock_vars_ = [plan.shock_vars_ ; ix];
if strcmp(expectation_type, 'perfect_foresight')
plan.shock_perfect_foresight_ = [plan.shock_perfect_foresight_ ; 1];
else
plan.shock_perfect_foresight_ = [plan.shock_perfect_foresight_ ; 0];
end
end
plan.shock_date_{length(plan.shock_date_) + 1} = date;
plan.shock_paths_{length(plan.shock_paths_) + 1} = value;
...@@ -65,6 +65,11 @@ global options_ ...@@ -65,6 +65,11 @@ global options_
dataset = read_variables(options_.datafile, options_.varobs, [], options_.xls_sheet, options_.xls_range); dataset = read_variables(options_.datafile, options_.varobs, [], options_.xls_sheet, options_.xls_range);
options_ = set_default_option(options_, 'nobs', size(dataset,1)-options_.first_obs+1); options_ = set_default_option(options_, 'nobs', size(dataset,1)-options_.first_obs+1);
if (options_.first_obs+options_.nobs-1)> size(dataset,1)
fprintf('Incorrect or missing specification of the number of observations. nobs can be at most %4u\n',size(dataset,1)-options_.first_obs+1);
error('Inconsistent number of observations.')
end
% Parameters for prior % Parameters for prior
if options_.first_obs + options_.presample <= nlags if options_.first_obs + options_.presample <= nlags
error('first_obs+presample should be > nlags (for initializing the VAR)') error('first_obs+presample should be > nlags (for initializing the VAR)')
......
...@@ -73,7 +73,7 @@ oo.dr=set_state_space(oo.dr,M,options); ...@@ -73,7 +73,7 @@ oo.dr=set_state_space(oo.dr,M,options);
[dr,info,M,options,oo] = resol(1,M,options,oo); [dr,info,M,options,oo] = resol(1,M,options,oo);
if info(1) ~= 0 && info(1) ~= 3 && info(1) ~= 4 if info(1) ~= 0 && info(1) ~= 3 && info(1) ~= 4
print_info(info, options.noprint, options); print_info(info, 0, options);
end end
eigenvalues_ = dr.eigval; eigenvalues_ = dr.eigval;
...@@ -107,7 +107,7 @@ if options.noprint == 0 ...@@ -107,7 +107,7 @@ if options.noprint == 0
if result if result
disp('The rank condition is verified.') disp('The rank condition is verified.')
else else
disp('The rank conditions ISN''T verified!') disp('The rank condition ISN''T verified!')
end end
skipline() skipline()
end end
...@@ -14,7 +14,7 @@ function varlist = check_list_of_variables(options_, M_, varlist) ...@@ -14,7 +14,7 @@ function varlist = check_list_of_variables(options_, M_, varlist)
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% Copyright (C) 2003-2012 Dynare Team % Copyright (C) 2003-2014 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -86,7 +86,7 @@ if isempty(varlist) ...@@ -86,7 +86,7 @@ if isempty(varlist)
if isempty(cas) if isempty(cas)
cas = 'Forecasts'; cas = 'Forecasts';
else else
cas = [ cas , ' and forecats']; cas = [ cas , ' and forecasts'];
end end
end end
if ~isempty(cas) if ~isempty(cas)
......
...@@ -22,16 +22,19 @@ if nargout>1 ...@@ -22,16 +22,19 @@ if nargout>1
description = ''; description = '';
end end
%% Get informations about mcmc files. [MetropolisFolder, info] = CheckPath('metropolis',M_.dname);
if ~exist([ M_.dname '/metropolis'],'dir')
% Get informations about mcmc files.
if info
disp('check_posterior_analysis_data:: Can''t find any mcmc file!') disp('check_posterior_analysis_data:: Can''t find any mcmc file!')
return return
end end
mhname = get_name_of_the_last_mh_file(M_); mhname = get_name_of_the_last_mh_file(M_);
mhdate = get_date_of_a_file(mhname); mhdate = get_date_of_a_file([MetropolisFolder filesep mhname]);
%% Get informations about _posterior_draws files. % Get informations about _posterior_draws files.
drawsinfo = dir([ M_.dname '/metropolis/' M_.fname '_posterior_draws*.mat']); drawsinfo = dir([ MetropolisFolder filesep M_.fname '_posterior_draws*.mat']);
if isempty(drawsinfo) if isempty(drawsinfo)
info = 1; % select_posterior_draws has to be called first. info = 1; % select_posterior_draws has to be called first.
if nargout>1 if nargout>1
...@@ -40,8 +43,7 @@ if isempty(drawsinfo) ...@@ -40,8 +43,7 @@ if isempty(drawsinfo)
return return
else else
number_of_last_posterior_draws_file = length(drawsinfo); number_of_last_posterior_draws_file = length(drawsinfo);
pddate = get_date_of_a_file([ M_.dname '/metropolis/' M_.fname '_posterior_draws'... pddate = get_date_of_a_file([ MetropolisFolder filesep M_.fname '_posterior_draws' int2str(number_of_last_posterior_draws_file) '.mat']);
int2str(number_of_last_posterior_draws_file) '.mat']);
if pddate<mhdate if pddate<mhdate
info = 2; % _posterior_draws files have to be updated. info = 2; % _posterior_draws files have to be updated.
if nargout>1 if nargout>1
...@@ -56,7 +58,7 @@ else ...@@ -56,7 +58,7 @@ else
end end
end end
%% Get informations about posterior data files. % Get informations about posterior data files.
switch type switch type
case 'variance' case 'variance'
generic_post_data_file_name = 'Posterior2ndOrderMoments'; generic_post_data_file_name = 'Posterior2ndOrderMoments';
...@@ -69,7 +71,7 @@ switch type ...@@ -69,7 +71,7 @@ switch type
otherwise otherwise
disp('This feature is not yest implemented!') disp('This feature is not yest implemented!')
end end
pdfinfo = dir([ M_.dname '/metropolis/' M_.fname '_' generic_post_data_file_name '*']); pdfinfo = dir([ MetropolisFolder filesep M_.fname '_' generic_post_data_file_name '*']);
if isempty(pdfinfo) if isempty(pdfinfo)
info = 4; % posterior draws have to be processed. info = 4; % posterior draws have to be processed.
if nargout>1 if nargout>1
...@@ -79,8 +81,7 @@ if isempty(pdfinfo) ...@@ -79,8 +81,7 @@ if isempty(pdfinfo)
else else
number_of_the_last_post_data_file = length(pdfinfo); number_of_the_last_post_data_file = length(pdfinfo);
name_of_the_last_post_data_file = ... name_of_the_last_post_data_file = ...
[ pwd filesep M_.dname ... [ pwd filesep MetropolisFolder filesep ...
filesep 'metropolis' filesep ...
M_.fname '_' ... M_.fname '_' ...
generic_post_data_file_name ... generic_post_data_file_name ...
int2str(number_of_the_last_post_data_file) ... int2str(number_of_the_last_post_data_file) ...
......