time-shift
Johannes Pfeifer 2013-07-05 10:38:43 +02:00
commit c2b7a43c8a
7 changed files with 325 additions and 11 deletions

View File

@ -18,7 +18,7 @@ function disp(d)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isempty(d)
fprintf('%s is an empty dynDate object.\n', inputname(1));
fprintf('Empty dynDate object.\n');
else
fprintf('%s = <dynDate: %s>\n', inputname(1), format(d));
fprintf('<dynDate: %s>\n', format(d));
end

View File

@ -18,14 +18,14 @@ function disp(dd)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isempty(dd)
fprintf('%s is an empty dynDates object.\n', inputname(1));
fprintf('Empty dynDates object.\n');
return
end
max_displayed = 5;
first_displayed = 2;
fprintf('%s = <dynDates: ', inputname(1));
fprintf('<dynDates: ');
if dd.ndat<=max_displayed
for i=1:dd.ndat

View File

@ -105,7 +105,9 @@ switch nargin
return
elseif ischar(varargin{1})
% Create a dynSeries object loading data in a file (*.csv, *.m, *.mat).
if check_file_extension(varargin{1},'m')
if isempty(varargin{1})
error('dynSeries:: Wrong calling sequence! Input argument cannot be an empty string.')
elseif check_file_extension(varargin{1},'m')
[freq,init,data,varlist,tex] = load_m_file_data(varargin{1});
elseif check_file_extension(varargin{1},'mat')
[freq,init,data,varlist,tex] = load_mat_file_data(varargin{1});

View File

@ -148,8 +148,12 @@ switch length(S)
case 2
merge_dynSeries_objects = 0;
if ((isequal(S(1).type,'{}') || isequal(S(1).type,'.')) && isequal(S(2).type,'()'))
sA = extract(A,S(1).subs{:});
if (isa(B,'dynSeries') && isequal(sA.vobs,B.vobs)) || (isnumeric(B) && isequal(sA.vobs,columns(B)))
if isequal(S(1).type,'{}')
sA = extract(A,S(1).subs{:});
else
sA = extract(A,S(1).subs);
end
if (isa(B,'dynSeries') && isequal(sA.vobs,B.vobs)) || (isnumeric(B) && isequal(sA.vobs,columns(B))) || (isnumeric(B) && isequal(columns(B),1))
if isa(S(2).subs{1},'dynDates') || isa(S(2).subs{1},'dynDate')
[junk, tdx] = intersect(sA.time.time,S(2).subs{1}.time,'rows');
if isa(B,'dynSeries')
@ -163,11 +167,19 @@ switch length(S)
if isequal(length(tdx),rows(B))
if isequal(columns(sA.data),columns(B))
sA.data(tdx,:) = B;
elseif isequal(size(B,2),1)
sA.data(tdx,:) = repmat(B,1,columns(sA.data));
else
error('dynSeries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
end
else
error('dynSeries::subsassgn: Dimension error! The number of periods on the left and right hand side must match.')
if isequal(columns(sA.data),columns(B)) && isequal(rows(B),1)
sA.data(tdx,:) = repmat(B,length(tdx),1);
elseif isequal(rows(B),1)
sA.data(tdx,:) = B;
else
error('dynSeries::subsassgn: Dimension error! The number of periods on the left and right hand side must match.')
end
end
else
error('dynSeries::subsasgn: The object on the right hand side must be a dynSeries object or a numeric array!')
@ -524,4 +536,159 @@ end
%$ t(7) = dyn_assert(ts1.data,[[A(1:2,1); B(3:7); A(8:end,1)], A(:,2:3)],1e-15);
%$ end
%$ T = all(t);
%@eof:13
%@eof:13
%@test:14
%$ % Define a datasets.
%$ A = rand(40,3); B = rand(40,1);
%$
%$ % Instantiate two dynSeries object.
%$ ts1 = dynSeries(A,'1950Q1',{'A1';'A2';'A3'},[]);
%$ ts2 = dynSeries(B,'1950Q1',{'B1'},[]);
%$
%$ % modify first object.
%$ try
%$ d1 = dynDate('1950Q3');
%$ d2 = dynDate('1951Q3');
%$ rg = d1:d2;
%$ ts1.A1(rg) = B(3:7);
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ % Instantiate a time series object.
%$ if t(1)
%$ t(2) = dyn_assert(ts1.vobs,3);
%$ t(3) = dyn_assert(ts1.nobs,40);
%$ t(4) = dyn_assert(ts1.name{2},'A2');
%$ t(5) = dyn_assert(ts1.name{1},'A1');
%$ t(6) = dyn_assert(ts1.name{3},'A3');
%$ t(7) = dyn_assert(ts1.data,[[A(1:2,1); B(3:7); A(8:end,1)], A(:,2:3)],1e-15);
%$ end
%$ T = all(t);
%@eof:14
%@test:15
%$ % Define a datasets.
%$ A = rand(40,3); B = rand(40,1);
%$
%$ % Instantiate two dynSeries object.
%$ ts1 = dynSeries(A,'1950Q1',{'A1';'A2';'A3'},[]);
%$ ts2 = dynSeries(B,'1950Q1',{'B1'},[]);
%$
%$ % modify first object.
%$ try
%$ d1 = dynDate('1950Q3');
%$ d2 = dynDate('1951Q3');
%$ rg = d1:d2;
%$ ts1.A1(rg) = sqrt(pi);
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ % Instantiate a time series object.
%$ if t(1)
%$ t(2) = dyn_assert(ts1.vobs,3);
%$ t(3) = dyn_assert(ts1.nobs,40);
%$ t(4) = dyn_assert(ts1.name{2},'A2');
%$ t(5) = dyn_assert(ts1.name{1},'A1');
%$ t(6) = dyn_assert(ts1.name{3},'A3');
%$ t(7) = dyn_assert(ts1.data,[[A(1:2,1); repmat(sqrt(pi),5,1); A(8:end,1)], A(:,2:3)],1e-15);
%$ end
%$ T = all(t);
%@eof:15
%@test:16
%$ % Define a datasets.
%$ A = rand(40,3); B = rand(40,1);
%$
%$ % Instantiate two dynSeries object.
%$ ts1 = dynSeries(A,'1950Q1',{'A1';'A2';'A3'},[]);
%$ ts2 = dynSeries(B,'1950Q1',{'B1'},[]);
%$
%$ % modify first object.
%$ try
%$ d1 = dynDate('1950Q3');
%$ d2 = dynDate('1951Q3');
%$ rg = d1:d2;
%$ ts1{'A1','A2'}(rg) = sqrt(pi);
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ % Instantiate a time series object.
%$ if t(1)
%$ t(2) = dyn_assert(ts1.vobs,3);
%$ t(3) = dyn_assert(ts1.nobs,40);
%$ t(4) = dyn_assert(ts1.name{2},'A2');
%$ t(5) = dyn_assert(ts1.name{1},'A1');
%$ t(6) = dyn_assert(ts1.name{3},'A3');
%$ t(7) = dyn_assert(ts1.data,[[A(1:2,1); repmat(sqrt(pi),5,1); A(8:end,1)], [A(1:2,2); repmat(sqrt(pi),5,1); A(8:end,2)], A(:,3)],1e-15);
%$ end
%$ T = all(t);
%@eof:16
%@test:17
%$ % Define a datasets.
%$ A = rand(40,3); B = rand(40,1);
%$
%$ % Instantiate two dynSeries object.
%$ ts1 = dynSeries(A,'1950Q1',{'A1';'A2';'A3'},[]);
%$ ts2 = dynSeries(B,'1950Q1',{'B1'},[]);
%$
%$ % modify first object.
%$ try
%$ d1 = dynDate('1950Q3');
%$ d2 = dynDate('1951Q3');
%$ rg = d1:d2;
%$ ts1{'A1','A2'}(rg) = [sqrt(pi), pi];
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ % Instantiate a time series object.
%$ if t(1)
%$ t(2) = dyn_assert(ts1.vobs,3);
%$ t(3) = dyn_assert(ts1.nobs,40);
%$ t(4) = dyn_assert(ts1.name{2},'A2');
%$ t(5) = dyn_assert(ts1.name{1},'A1');
%$ t(6) = dyn_assert(ts1.name{3},'A3');
%$ t(7) = dyn_assert(ts1.data,[[A(1:2,1); repmat(sqrt(pi),5,1); A(8:end,1)], [A(1:2,2); repmat(pi,5,1); A(8:end,2)], A(:,3)],1e-15);
%$ end
%$ T = all(t);
%@eof:17
%@test:18
%$ % Define a datasets.
%$ A = rand(40,3); B = rand(40,1);
%$
%$ % Instantiate two dynSeries object.
%$ ts1 = dynSeries(A,'1950Q1',{'A1';'A2';'A3'},[]);
%$ ts2 = dynSeries(B,'1950Q1',{'B1'},[]);
%$
%$ % modify first object.
%$ try
%$ d1 = dynDate('1950Q3');
%$ d2 = dynDate('1951Q3');
%$ rg = d1:d2;
%$ ts1{'A1','A2'}(rg) = ones(5,1);
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ % Instantiate a time series object.
%$ if t(1)
%$ t(2) = dyn_assert(ts1.vobs,3);
%$ t(3) = dyn_assert(ts1.nobs,40);
%$ t(4) = dyn_assert(ts1.name{2},'A2');
%$ t(5) = dyn_assert(ts1.name{1},'A1');
%$ t(6) = dyn_assert(ts1.name{3},'A3');
%$ t(7) = dyn_assert(ts1.data,[[A(1:2,1); ones(5,1); A(8:end,1)], [A(1:2,2); ones(5,1); A(8:end,2)], A(:,3)],1e-15);
%$ end
%$ T = all(t);
%@eof:18

145
matlab/@dynSeries/vertcat.m Normal file
View File

@ -0,0 +1,145 @@
function a = vertcat(varargin)
%@info:
%! @deftypefn {Function file} {@var{a} =} vertcat (@var{b},@var{c}, ...)
%! @anchor{horzcat}
%! @sp 1
%! Method of the dynSeries class.
%! @sp 1
%! This method overloads the vertical concatenation operator, so that
%! two (or more) time series objects containing the same variables
%! can be merged using the following syntax:
%!
%! a = [b; c; d];
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item b
%! Dynare time series object, instantiated by @ref{dynSeries}.
%! @item c
%! Dynare time series object, instantiated by @ref{dynSeries}.
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @var
%! @item a
%! Dynare time series object.
%! @end table
%! @end deftypefn
%@eod:
% Copyright (C) 2011-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 nargin==0
a = DynSeries();
elseif nargin == 1
a = varargin{1};
elseif nargin>1
a = varargin{1};
for i=2:nargin
a = vertcat_(a,varargin{i});
end
end
end
function d = vertcat_(b, c)
d = NaN;
if ~isequal(b.freq, c.freq)
error('dynSeries::vertcat: Frequencies must be common!')
end
if ~isequal(b.vobs, c.vobs)
error('dynSeries::vertcat: Number of variables must be common!')
end
if ~isequal(b.name, c.name)
error('dynSeries::vertcat: Variables must be common!')
end
d = b;
d.data = [b.data; c.data];
d.nobs = b.nobs+c.nobs;
end
%@test:1
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$ B = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$ B_name = {'A1';'A2'};
%$
%$ % Define expected results.
%$ e.time = dynDate(1);
%$ e.freq = 1;
%$ e.name = {'A1';'A2'};
%$ e.data = [A;B];
%$
%$ % Instantiate two time series objects.
%$ ts1 = dynSeries(A,[],A_name,[]);
%$ ts2 = dynSeries(B,[],B_name,[]);
%$
%$ % Call the tested method.
%$ ts3 = [ts1;ts2];
%$
%$ % Check the results.
%$
%$ t(1) = dyn_assert(ts3.init,e.time);
%$ t(2) = dyn_assert(ts3.freq,e.freq);
%$ t(3) = dyn_assert(ts3.data,e.data);
%$ t(4) = dyn_assert(ts3.name,e.name);
%$ t(5) = dyn_assert(ts3.nobs,20);
%$ T = all(t);
%@eof:1
%@test:2
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$ B = [transpose(1:10),2*transpose(1:10)];
%$ C = [transpose(1:10),3*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$ B_name = {'A1';'A2'};
%$ C_name = {'A1';'A2'};
%$
%$ % Define expected results.
%$ e.time = dynDate(1);
%$ e.freq = 1;
%$ e.name = {'A1';'A2'};
%$ e.data = [A;B;C];
%$
%$ % Instantiate two time series objects.
%$ ts1 = dynSeries(A,[],A_name,[]);
%$ ts2 = dynSeries(B,[],B_name,[]);
%$ ts3 = dynSeries(C,[],C_name,[]);
%$
%$ % Call the tested method.
%$ ts4 = [ts1; ts2; ts3];
%$
%$ % Check the results.
%$
%$ t(1) = dyn_assert(ts4.init,e.time);
%$ t(2) = dyn_assert(ts4.freq,e.freq);
%$ t(3) = dyn_assert(ts4.data,e.data);
%$ t(4) = dyn_assert(ts4.name,e.name);
%$ t(5) = dyn_assert(ts4.nobs,30);
%$ T = all(t);
%@eof:2

View File

@ -1,4 +1,4 @@
function evaluate_smoother(parameters,var_list)
function oo_=evaluate_smoother(parameters,var_list)
% Evaluate the smoother at parameters.
%
% INPUTS

View File

@ -41,8 +41,8 @@ for j=1:nvar
end
fhandle = dyn_figure(DynareOptions,'Name',['Shock decomposition: ',endo_names(i_var(j),:)]);
ax=axes('Position',[0.1 0.1 0.6 0.8]);
axis(ax,[xmin xmax ymin ymax]);
plot(ax,x(2:end),z1(end,:),'k-','LineWidth',2)
axis(ax,[xmin xmax ymin ymax]);
hold on;
for i=1:gend
i_1 = i-1;