Removed matlab/@dseries and utilities/dseries subfolders.
parent
bc90d1d6da
commit
4d669a4312
|
@ -1,107 +0,0 @@
|
|||
function A = abs(B) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{A} =} abs (@var{B})
|
||||
%! @anchor{@dseries/uminus}
|
||||
%! @sp 1
|
||||
%! Overloads the abs 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}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item A
|
||||
%! Dynare time series object.
|
||||
%! @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/>.
|
||||
|
||||
A = dseries();
|
||||
|
||||
A.data = abs(B.data);
|
||||
A.dates = B.dates;
|
||||
|
||||
A.name = cell(vobs(A), 1);
|
||||
A.tex = cell(vobs(A), 1);
|
||||
for i = 1:vobs(A)
|
||||
A.name(i) = {[ 'abs(' B.name{i} ')']};
|
||||
A.tex(i) = {[ '|' B.tex{i} '|']};
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = randn(10,2);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$ A_tex = {'A_1';'A_2'};
|
||||
%$ t = zeros(6,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object and compute the absolute value.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,A_tex);
|
||||
%$ ts2 = abs(ts1);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.data,abs(A),1e-15);
|
||||
%$ t(5) = dassert(ts2.name,{'abs(A1)';'abs(A2)'});
|
||||
%$ t(6) = dassert(ts2.tex,{'|A_1|';'|A_2|'});
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a datasets.
|
||||
%$ A = randn(10,2);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$ A_tex = {'A_1';'A_2'};
|
||||
%$ t = zeros(6,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object and compute the absolute value.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,A_tex);
|
||||
%$ ts2 = ts1.abs();
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.data,abs(A),1e-15);
|
||||
%$ t(5) = dassert(ts2.name,{'abs(A1)';'abs(A2)'});
|
||||
%$ t(6) = dassert(ts2.tex,{'|A_1|';'|A_2|'});
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,182 +0,0 @@
|
|||
function [a,b] = align(a, b) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {[@var{a}, @var{b}] =} align (@var{a}, @var{b})
|
||||
%! @anchor{dseries/align}
|
||||
%! @sp 1
|
||||
%! If dseries objects @var{a} and @var{b} are defined on different time ranges, extend @var{a} and/or
|
||||
%! @var{b} with NaNs so that they are defined on the same time range.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item a
|
||||
%! Object instantiated by @ref{dseries}.
|
||||
%! @item b
|
||||
%! Object instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item a
|
||||
%! Object instantiated by @ref{dseries}.
|
||||
%! @item b
|
||||
%! Object instantiated by @ref{dseries}.
|
||||
%! @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 ~isequal(frequency(a),frequency(b))
|
||||
error(['dseries::align: ''' inputname(1) ''' and ''' inputname(2) ''' dseries objects must have common frequencies!'])
|
||||
end
|
||||
|
||||
init = min(firstdate(a),firstdate(b));
|
||||
last = max(lastdate(a),lastdate(b));
|
||||
|
||||
if isempty(intersect(a.dates,b.dates))
|
||||
error(['dseries::align: ''' inputname(1) ''' and ''' inputname(2) ''' dseries object must have at least one common date!'])
|
||||
end
|
||||
|
||||
a_init = init;
|
||||
b_init = init;
|
||||
a_last = last;
|
||||
b_last = last;
|
||||
|
||||
if firstdate(b)>init
|
||||
n = firstdate(b)-init;
|
||||
b.data = [NaN(n, vobs(b)); b.data];
|
||||
b_init = init;
|
||||
end
|
||||
|
||||
if firstdate(a)>init
|
||||
n = firstdate(a)-init;
|
||||
a.data = [NaN(n, vobs(a)); a.data];
|
||||
a_init = init;
|
||||
end
|
||||
|
||||
if lastdate(b)<last
|
||||
n = last-lastdate(b);
|
||||
b.data = [b.data; NaN(n, vobs(b))];
|
||||
end
|
||||
|
||||
if lastdate(a)<last
|
||||
n = last-lastdate(a);
|
||||
a.data = [a.data; NaN(n, vobs(a))];
|
||||
end
|
||||
|
||||
a.dates = a_init:a_init+(nobs(a)-1);
|
||||
b.dates = b_init:b_init+(nobs(b)-1);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(8,3); B = rand(7,2);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'A3'};
|
||||
%$ B_name = {'B1';'B2'};
|
||||
%$
|
||||
%$ % Define initial dates
|
||||
%$ A_init = '1990Q1';
|
||||
%$ B_init = '1989Q2';
|
||||
%$
|
||||
%$ % Instantiate two dseries objects
|
||||
%$ ts1 = dseries(A,A_init,A_name);
|
||||
%$ ts2 = dseries(B,B_init,B_name);
|
||||
%$
|
||||
%$ try
|
||||
%$ [ts1, ts2] = align(ts1, ts2);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.nobs,ts2.nobs);
|
||||
%$ t(3) = dassert(ts1.init,ts2.init);
|
||||
%$ t(4) = dassert(ts1.data,[NaN(3,3); A], 1e-15);
|
||||
%$ t(5) = dassert(ts2.data,[B; NaN(4,2)], 1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(8,3); B = rand(7,2);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'A3'};
|
||||
%$ B_name = {'B1';'B2'};
|
||||
%$
|
||||
%$ % Define initial dates
|
||||
%$ A_init = '1990Q1';
|
||||
%$ B_init = '1990Q1';
|
||||
%$
|
||||
%$ % Instantiate two dseries objects
|
||||
%$ ts1 = dseries(A,A_init,A_name);
|
||||
%$ ts2 = dseries(B,B_init,B_name);
|
||||
%$
|
||||
%$ try
|
||||
%$ [ts1, ts2] = align(ts1, ts2);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.nobs,ts2.nobs);
|
||||
%$ t(3) = dassert(ts1.init,ts2.init);
|
||||
%$ t(4) = dassert(ts1.data,A, 1e-15);
|
||||
%$ t(5) = dassert(ts2.data,[B; NaN(1,2)], 1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(8,3); B = rand(7,2);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'A3'};
|
||||
%$ B_name = {'B1';'B2'};
|
||||
%$
|
||||
%$ % Define initial dates
|
||||
%$ A_init = '1990Q1';
|
||||
%$ B_init = '1990Q1';
|
||||
%$
|
||||
%$ % Instantiate two dseries objects
|
||||
%$ ts1 = dseries(A,A_init,A_name);
|
||||
%$ ts2 = dseries(B,B_init,B_name);
|
||||
%$
|
||||
%$ try
|
||||
%$ [ts2, ts1] = align(ts2, ts1);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.nobs,ts2.nobs);
|
||||
%$ t(3) = dassert(ts1.init,ts2.init);
|
||||
%$ t(4) = dassert(ts1.data,A, 1e-15);
|
||||
%$ t(5) = dassert(ts2.data,[B; NaN(1,2)], 1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
|
@ -1,148 +0,0 @@
|
|||
function ts = baxter_king_filter(ts, high_frequency, low_frequency, K) % --*-- Unitary tests --*--
|
||||
|
||||
% ts = baxter_king_filter(ts, high_frequency, low_frequency, K)
|
||||
%
|
||||
% Implementation of Baxter and King (1999) band pass filter for dseries objects. The code is adapted from
|
||||
% the one provided by Baxter and King. This filter isolates business cycle fluctuations with a period of length
|
||||
% ranging between high_frequency to low_frequency (quarters).
|
||||
%
|
||||
% INPUTS
|
||||
% o ts dseries object.
|
||||
% o high_frequency positive scalar, period length (default value is 6).
|
||||
% o low_frequency positive scalar, period length (default value is 32).
|
||||
% o K positive scalar integer, truncation parameter (default value is 12).
|
||||
%
|
||||
% OUTPUTS
|
||||
% o ts dseries object.
|
||||
%
|
||||
% REMARKS
|
||||
% This filter use a (symmetric) moving average smoother, so that K observations at the beginning and at the end of the
|
||||
% sample are lost in the computation of the filter.
|
||||
|
||||
% 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 nargin<4 || isempty(truncature)
|
||||
K = 12;
|
||||
if nargin<3 || isempty(low_frequency)
|
||||
% Set default number of periods corresponding to the lowest frequency.
|
||||
low_frequency = 32;
|
||||
if nargin<2 || isempty(high_frequency)
|
||||
% Set default number of periods corresponding to the highest frequency.
|
||||
high_frequency = 6;
|
||||
if nargin<1
|
||||
error('dseries::baxter_king_filter: I need at least one argument')
|
||||
end
|
||||
else
|
||||
if high_frequency<2
|
||||
error('dseries::baxter_king_filter: Second argument must be greater than 2!')
|
||||
end
|
||||
if high_frequency>low_frequency
|
||||
error('dseries::baxter_king_filter: Second argument must be smaller than the third argument!')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
% translate periods into frequencies.
|
||||
hf=2.0*pi/high_frequency;
|
||||
lf=2.0*pi/low_frequency;
|
||||
|
||||
% Set weights for the band-pass filter's lag polynomial.
|
||||
weights = zeros(K+1,1); lpowers = transpose(1:K);
|
||||
weights(2:K+1) = (sin(lpowers*hf)-sin(lpowers*lf))./(lpowers*pi);
|
||||
weights(1) = (hf-lf)/pi;
|
||||
|
||||
% Set the constraint on the sum of weights.
|
||||
if low_frequency>1000
|
||||
% => low pass filter.
|
||||
sum_of_weights_constraint = 1.0;
|
||||
else
|
||||
sum_of_weights_constraint = 0.0;
|
||||
end
|
||||
|
||||
% Compute the sum of weights.
|
||||
sum_of_weights = weights(1) + 2*sum(weights(2:K+1));
|
||||
|
||||
% Correct the weights.
|
||||
weights = weights + (sum_of_weights_constraint - sum_of_weights)/(2*K+1);
|
||||
|
||||
% Weights are symmetric!
|
||||
weights = [flipud(weights(2:K+1)); weights];
|
||||
|
||||
tmp = zeros(size(ts.data));
|
||||
|
||||
% Filtering step.
|
||||
for t = K+1:nobs(ts)-K
|
||||
tmp(t,:) = weights'*ts.data(t-K:t+K,:);
|
||||
end
|
||||
|
||||
% Update dseries object.
|
||||
ts.data = tmp(K+1:end-K,:);
|
||||
init = firstdate(ts)+K;
|
||||
ts.dates = init:init+(nobs(ts)-1);
|
||||
|
||||
%@test:1
|
||||
%$ plot_flag = 0;
|
||||
%$
|
||||
%$ % Create a dataset.
|
||||
%$ e = .2*randn(200,1);
|
||||
%$ u = randn(200,1);
|
||||
%$ stochastic_trend = cumsum(e);
|
||||
%$ deterministic_trend = .1*transpose(1:200);
|
||||
%$ x = zeros(200,1);
|
||||
%$ for i=2:200
|
||||
%$ x(i) = .75*x(i-1) + e(i);
|
||||
%$ end
|
||||
%$ y = x + stochastic_trend + deterministic_trend;
|
||||
%$
|
||||
%$ % Test the routine.
|
||||
%$ try
|
||||
%$ ts = dseries(y,'1950Q1');
|
||||
%$ ts = ts.baxter_king_filter();
|
||||
%$ xx = dseries(x,'1950Q1');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1953, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,1);
|
||||
%$ t(6) = dassert(ts.nobs,176);
|
||||
%$ end
|
||||
%$
|
||||
%$ % Show results
|
||||
%$ if plot_flag
|
||||
%$ plot(xx(ts.dates).data,'-k');
|
||||
%$ hold on
|
||||
%$ plot(ts.data,'--r');
|
||||
%$ hold off
|
||||
%$ axis tight
|
||||
%$ id = get(gca,'XTick');
|
||||
%$ set(gca,'XTickLabel',strings(ts.dates(id)));
|
||||
%$ legend({'Stationary component of y', 'Filtered y'})
|
||||
%$ print('-depsc2','../doc/dynare.plots/BaxterKingFilter.eps')
|
||||
%$ system('convert -density 300 ../doc/dynare.plots/BaxterKingFilter.eps ../doc/dynare.plots/BaxterKingFilter.png');
|
||||
%$ system('convert -density 300 ../doc/dynare.plots/BaxterKingFilter.eps ../doc/dynare.plots/BaxterKingFilter.pdf');
|
||||
%$ system('convert -density 300 ../doc/dynare.plots/BaxterKingFilter.eps ../doc/dynare.plots/BaxterKingFilter.jpg');
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,61 +0,0 @@
|
|||
function vs = chain(ts,us) % --*-- Unitary tests --*--
|
||||
|
||||
% Copyright (C) 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 vobs(ts)-vobs(us)
|
||||
error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have the same number of variables!'])
|
||||
end
|
||||
|
||||
if frequency(ts)-frequency(us)
|
||||
error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have common frequencies!'])
|
||||
end
|
||||
|
||||
if lastdate(ts)<firstdate(us)
|
||||
error(['dseries::chain: The last date in ' inputname(1) ' (' date2string(ts.dates(end)) ') must not preceed the first date in ' inputname(2) ' (' date2string(us.dates(1)) ')!'])
|
||||
end
|
||||
|
||||
tdx = find(sum(bsxfun(@eq,us.dates.time,ts.dates.time(end,:)),2)==2);
|
||||
GrowthFactor = us.data(tdx+1:end,:)./us.data(tdx:end-1,:);
|
||||
CumulatedGrowthFactors = cumprod(GrowthFactor);
|
||||
|
||||
vs = ts;
|
||||
vs.data = [vs.data; bsxfun(@times,CumulatedGrowthFactors,vs.data(end,:))];
|
||||
|
||||
vs.dates = firstdate(vs):firstdate(vs)+nobs(vs);
|
||||
|
||||
%@test:1
|
||||
%$ try
|
||||
%$ ts = dseries([1; 2; 3; 4],dates('1950Q1')) ;
|
||||
%$ us = dseries([3; 4; 5; 6],dates('1950Q3')) ;
|
||||
%$ vs = chain(ts,us);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(vs.freq,4);
|
||||
%$ t(3) = dassert(vs.init.freq,4);
|
||||
%$ t(4) = dassert(vs.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,1);
|
||||
%$ t(6) = dassert(vs.nobs,6);
|
||||
%$ t(7) = isequal(vs.data,transpose(1:6));
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,86 +0,0 @@
|
|||
function [error_flag,message] = check(A)
|
||||
|
||||
% 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/>.
|
||||
|
||||
error_flag = 0;
|
||||
|
||||
[n,m] = size(A.data);
|
||||
|
||||
if ~isequal(m, vobs(A));
|
||||
error_flag = 1;
|
||||
if nargout>1
|
||||
message = ['dseries: Wrong number of variables in dseries object ''' inputname(1) '''!'];
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(n,nobs(A));
|
||||
error_flag = 1;
|
||||
if nargout>1
|
||||
message = ['dseries: Wrong number of observations in dseries object ''' inputname(1) '''!'];
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(m,numel(A.name));
|
||||
error_flag = 1;
|
||||
if nargout>1
|
||||
message = ['dseries: Wrong number of variable names in dseries object ''' inputname(1) '''!'];
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(m,numel(A.tex));
|
||||
error_flag = 1;
|
||||
if nargout>1
|
||||
message = ['dseries: Wrong number of variable tex names in dseries object ''' inputname(1) '''!'];
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(numel(A.name),numel(A.tex));
|
||||
error_flag = 1;
|
||||
if nargout>1
|
||||
message = ['dseries: The number of variable tex names has to be equal to the number of variable names in dseries object ''' inputname(1) '''!'];
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(numel(unique(A.name)),numel(A.name));
|
||||
error_flag = 1;
|
||||
if nargout>1
|
||||
message = ['dseries: The variable names in dseries object ''' inputname(1) ''' are not unique!'];
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(numel(unique(A.tex)),numel(A.tex));
|
||||
error_flag = 1;
|
||||
if nargout>1
|
||||
message = ['dseries: The variable tex names in dseries object ''' inputname(1) ''' are not unique!'];
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(A.dates,firstdate(A):firstdate(A)+nobs(A))
|
||||
error_flag = 1;
|
||||
if nargout>1
|
||||
message = ['dseries: Wrong definition of the dates member in dseries object ''' inputname(1) '''!'];
|
||||
end
|
||||
return
|
||||
end
|
|
@ -1,234 +0,0 @@
|
|||
function B = cumprod(varargin) % --*-- Unitary tests --*--
|
||||
|
||||
% Overloads matlab's cumprod function for dseries objects.
|
||||
%
|
||||
% INPUTS
|
||||
% o A dseries object [mandatory].
|
||||
% o d dates object [optional]
|
||||
% o v dseries object with one observation [optional]
|
||||
%
|
||||
% OUTPUTS
|
||||
% o B dseries object.
|
||||
|
||||
% Copyright (C) 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/>.
|
||||
|
||||
% Get indices of the columns without NaNs
|
||||
idx = find(~any(isnan(varargin{1}.data)));
|
||||
|
||||
if isempty(idx)
|
||||
error('dseries::cumprod: All the variables have NaNs. The cumulated product cannot be computed!')
|
||||
end
|
||||
|
||||
if ~isequal(idx(:),transpose(1:vobs(varargin{1})))
|
||||
warning('dseries::cumprod: The cumulated product is not computed for some variables because they have NaNs!')
|
||||
end
|
||||
|
||||
switch nargin
|
||||
case 1
|
||||
% Initialize the output.
|
||||
B = varargin{1};
|
||||
% Perform the cumulated sum
|
||||
B.data(:,idx) = cumprod(B.data(:,idx));
|
||||
% Change the name of the variables
|
||||
for i=1:vobs(B)
|
||||
B.name(i) = {['cumprod(' B.name{i} ')']};
|
||||
B.tex(i) = {['\prod_t ' B.tex{i}]};
|
||||
end
|
||||
case 2
|
||||
if isdseries(varargin{2})
|
||||
if ~isequal(vobs(varargin{1}), vobs(varargin{2}))
|
||||
error('dseries::cumprod: First and second input arguments must be dseries objects with the same number of variables!')
|
||||
end
|
||||
if ~isequal(varargin{1}.name, varargin{2}.name)
|
||||
warning('dseries::cumprod: First and second input arguments must be dseries objects do not have the same variables!')
|
||||
end
|
||||
if ~isequal(nobs(varargin{2}),1)
|
||||
error('dseries::cumprod: Second input argument must be a dseries object with only one observation!')
|
||||
end
|
||||
B = cumprod(varargin{1});
|
||||
B.data = bsxfun(@rdivide,B.data,B.data(1,:));
|
||||
B.data = bsxfun(@times,B.data,varargin{2}.data);
|
||||
elseif isdates(varargin{2})
|
||||
B = cumprod(varargin{1});
|
||||
t = find(B.dates==varargin{2});
|
||||
if isempty(t)
|
||||
if varargin{2}==(firstdate(B)-1)
|
||||
return
|
||||
else
|
||||
error(['dseries::cumprod: date ' date2string(varargin{2}) ' is not in the sample!'])
|
||||
end
|
||||
end
|
||||
B.data = bsxfun(@rdivide,B.data,B.data(t,:));
|
||||
else
|
||||
error('dseries::cumprod: Second input argument must be a dseries object or a dates object!')
|
||||
end
|
||||
case 3
|
||||
if ~isdates(varargin{2})
|
||||
error('dseries::cumprod: Second input argument must be a dates object!')
|
||||
end
|
||||
if ~isdseries(varargin{3})
|
||||
error('dseries::cumprod: Third input argument must be a dseries object!')
|
||||
end
|
||||
if ~isequal(vobs(varargin{1}), vobs(varargin{3}))
|
||||
error('dseries::cumprod: First and third input arguments must be dseries objects with the same number of variables!')
|
||||
end
|
||||
if ~isequal(varargin{1}.name, varargin{3}.name)
|
||||
warning('dseries::cumprod: First and third input arguments must be dseries objects do not have the same variables!')
|
||||
end
|
||||
if ~isequal(nobs(varargin{3}),1)
|
||||
error('dseries::cumprod: Third input argument must be a dseries object with only one observation!')
|
||||
end
|
||||
B = cumprod(varargin{1});
|
||||
t = find(B.dates==varargin{2});
|
||||
if isempty(t)
|
||||
if varargin{2}==(firstdate(B)-1)
|
||||
B.data = bsxfun(@times,B.data,varargin{3}.data);
|
||||
return
|
||||
else
|
||||
error(['dseries::cumprod: date ' date2string(varargin{2}) ' is not in the sample!'])
|
||||
end
|
||||
end
|
||||
B.data = bsxfun(@rdivide, B.data, B.data(t,:));
|
||||
B.data = bsxfun(@times, B.data, varargin{3}.data);
|
||||
otherwise
|
||||
error('dseries::cumprod: Wrong number of input arguments!')
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a data set.
|
||||
%$ A = 2*ones(4,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ try
|
||||
%$ ts = cumprod(ts);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = isequal(ts.data,cumprod(A));
|
||||
%$ t(3) = isequal(ts.name{1},'cumprod(A1)');
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a data set.
|
||||
%$ A = 2*ones(4,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ try
|
||||
%$ ts = ts.cumprod();
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = isequal(ts.data,cumprod(A));
|
||||
%$ t(3) = isequal(ts.name{1},'cumprod(A1)');
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
|
||||
%@test:3
|
||||
%$ % Define a data set.
|
||||
%$ A = 2*ones(7,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts = cumprod(ts,dates('3Y'));
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ ds = dseries([.25; .5; 1; 2; 4; 8; 16], [], A_name, []);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ warning off, % Because the names of the variables are not the same...
|
||||
%$ t(1) = dassert(ts,ts);
|
||||
%$ warning_config
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ % Define a data set.
|
||||
%$ A = 2*ones(7,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(pi, [], A_name, []);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts3 = cumprod(ts1,dates('3Y'),ts2);
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ ts4 = dseries([.25; .5; 1; 2; 4; 8; 16]*pi, [], A_name, []);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ warning off, % Because the names of the variables are not the same...
|
||||
%$ t(1) = dassert(ts3,ts4);
|
||||
%$ warning_config
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ % Define a data set.
|
||||
%$ A = 2*ones(7,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(pi, [], A_name, []);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts3 = ts1.cumprod(dates('3Y'),ts2);
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ ts4 = dseries([.25; .5; 1; 2; 4; 8; 16]*pi, [], A_name, []);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ warning off, % Because the names of the variables are not the same...
|
||||
%$ t(1) = dassert(ts3,ts4);
|
||||
%$ warning_config
|
||||
%$ T = all(t);
|
||||
%@eof:5
|
|
@ -1,225 +0,0 @@
|
|||
function B = cumsum(varargin) % --*-- Unitary tests --*--
|
||||
|
||||
% Overloads matlab's cumsum function for dseries objects.
|
||||
%
|
||||
% INPUTS
|
||||
% o A dseries object [mandatory].
|
||||
% o d dates object [optional]
|
||||
% o v dseries object with one observation [optional]
|
||||
%
|
||||
% OUTPUTS
|
||||
% o B dseries object.
|
||||
|
||||
% 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/>.
|
||||
|
||||
% Get indices of the columns without NaNs
|
||||
idx = find(~any(isnan(varargin{1}.data)));
|
||||
|
||||
if isempty(idx)
|
||||
error('dseries::cumsum: All the variables have NaNs. The cumulated sum cannot be computed!')
|
||||
end
|
||||
|
||||
if ~isequal(idx(:),transpose(1:vobs(varargin{1})))
|
||||
warning('dseries::cumsum: The cumulated sum is not computed for some variables because they have NaNs!')
|
||||
end
|
||||
|
||||
switch nargin
|
||||
case 1
|
||||
% Initialize the output.
|
||||
B = varargin{1};
|
||||
% Perform the cumulated sum
|
||||
B.data(:,idx) = cumsum(B.data(:,idx));
|
||||
% Change the name of the variables
|
||||
for i=1:vobs(B)
|
||||
B.name(i) = {['cumsum(' B.name{i} ')']};
|
||||
B.tex(i) = {['\sum_t ' B.tex{i}]};
|
||||
end
|
||||
case 2
|
||||
if isdseries(varargin{2})
|
||||
if ~isequal(vobs(varargin{1}), vobs(varargin{2}))
|
||||
error('dseries::cumsum: First and second input arguments must be dseries objects with the same number of variables!')
|
||||
end
|
||||
if ~isequal(varargin{1}.name, varargin{2}.name)
|
||||
warning('dseries::cumsum: First and second input arguments must be dseries objects do not have the same variables!')
|
||||
end
|
||||
if ~isequal(nobs(varargin{2}),1)
|
||||
error('dseries::cumsum: Second input argument must be a dseries object with only one observation!')
|
||||
end
|
||||
B = cumsum(varargin{1});
|
||||
B.data = bsxfun(@plus,B.data,varargin{2}.data);
|
||||
elseif isdates(varargin{2})
|
||||
B = cumsum(varargin{1});
|
||||
t = find(B.dates==varargin{2});
|
||||
if isempty(t)
|
||||
if varargin{2}==(firstdate(B)-1)
|
||||
return
|
||||
else
|
||||
error(['dseries::cumsum: date ' date2string(varargin{2}) ' is not in the sample!'])
|
||||
end
|
||||
end
|
||||
B.data = bsxfun(@minus,B.data,B.data(t,:));
|
||||
else
|
||||
error('dseries::cumsum: Second input argument must be a dseries object or a dates object!')
|
||||
end
|
||||
case 3
|
||||
if ~isdates(varargin{2})
|
||||
error('dseries::cumsum: Second input argument must be a dates object!')
|
||||
end
|
||||
if ~isdseries(varargin{3})
|
||||
error('dseries::cumsum: Third input argument must be a dseries object!')
|
||||
end
|
||||
if ~isequal(vobs(varargin{1}), vobs(varargin{3}))
|
||||
error('dseries::cumsum: First and third input arguments must be dseries objects with the same number of variables!')
|
||||
end
|
||||
if ~isequal(varargin{1}.name, varargin{3}.name)
|
||||
warning('dseries::cumsum: First and third input arguments must be dseries objects do not have the same variables!')
|
||||
end
|
||||
if ~isequal(nobs(varargin{3}),1)
|
||||
error('dseries::cumsum: Third input argument must be a dseries object with only one observation!')
|
||||
end
|
||||
B = cumsum(varargin{1});
|
||||
t = find(B.dates==varargin{2});
|
||||
if isempty(t)
|
||||
if varargin{2}==(firstdate(B)-1)
|
||||
B.data = bsxfun(@plus,B.data,varargin{3}.data);
|
||||
return
|
||||
else
|
||||
error(['dseries::cumsum: date ' date2string(varargin{2}) ' is not in the sample!'])
|
||||
end
|
||||
end
|
||||
B.data = bsxfun(@plus,B.data,varargin{3}.data-B.data(t,:));
|
||||
otherwise
|
||||
error('dseries::cumsum: Wrong number of input arguments!')
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a data set.
|
||||
%$ A = ones(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts1 = cumsum(ts1);
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ ts2 = dseries(transpose(1:10), [], A_name, []);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ warning off, % Because the names of the variables are not the same...
|
||||
%$ t(1) = dassert(ts1,ts2);
|
||||
%$ warning_config
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a data set.
|
||||
%$ A = ones(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts1 = ts1.cumsum();
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ ts2 = dseries(transpose(1:10), [], A_name, []);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ warning off, % Because the names of the variables are not the same...
|
||||
%$ t(1) = dassert(ts1,ts2);
|
||||
%$ warning_config
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ % Define a data set.
|
||||
%$ A = ones(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts1 = cumsum(ts1,dates('3Y'));
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ ts2 = dseries([-2; -1; 0; 1; 2; 3; 4; 5; 6; 7], [], A_name, []);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ warning off, % Because the names of the variables are not the same...
|
||||
%$ t(1) = dassert(ts1,ts2);
|
||||
%$ warning_config
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ % Define a data set.
|
||||
%$ A = ones(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(pi, [], A_name, []);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts3 = cumsum(ts1,dates('3Y'),ts2);
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ ts4 = dseries([-2; -1; 0; 1; 2; 3; 4; 5; 6; 7]+pi, [], A_name, []);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ warning off, % Because the names of the variables are not the same...
|
||||
%$ t(1) = dassert(ts3,ts4);
|
||||
%$ warning_config
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ % Define a data set.
|
||||
%$ A = ones(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(pi, [], A_name, []);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts3 = ts1.cumsum(dates('3Y'),ts2);
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ ts4 = dseries([-2; -1; 0; 1; 2; 3; 4; 5; 6; 7]+pi, [], A_name, []);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ warning off, % Because the names of the variables are not the same...
|
||||
%$ t(1) = dassert(ts3,ts4);
|
||||
%$ warning_config
|
||||
%$ T = all(t);
|
||||
%@eof:5
|
|
@ -1,110 +0,0 @@
|
|||
function o = detrend(o, model) % --*-- Unitary tests --*--
|
||||
|
||||
% Copyright (C) 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/>.
|
||||
|
||||
% Set default for the order of the polynomial trend (constant).
|
||||
if nargin<2
|
||||
model = 0;
|
||||
end
|
||||
|
||||
data = o.data;
|
||||
|
||||
if isnumeric(model)
|
||||
if isscalar(model) && isint(model)
|
||||
switch model
|
||||
case 0
|
||||
data = demean(data);
|
||||
otherwise
|
||||
x = NaN(nobs(o), model+1);
|
||||
x(:,1) = ones(nobs(o), 1);
|
||||
x(:,2) = transpose(1:nobs(o));
|
||||
for c=3:model+1
|
||||
x(:,c) = x(:,c-1).*x(:,2);
|
||||
end
|
||||
data = data - x*(x\data);
|
||||
end
|
||||
else
|
||||
error('dseries::detrend: Second argument must be a positive integer scalar!')
|
||||
end
|
||||
else
|
||||
error('dseries::detrend: Second argument must be a positive integer scalar!')
|
||||
end
|
||||
|
||||
o = dseries(data, o.dates, o.name, o.tex);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a dataset.
|
||||
%$ a = dseries(randn(1000,3));
|
||||
%$
|
||||
%$ % detrend (default).
|
||||
%$ try
|
||||
%$ b1 = a.detrend();
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % detrend (constant).
|
||||
%$ if t(1)
|
||||
%$ try
|
||||
%$ b2 = a.detrend(0);
|
||||
%$ t(2) = 1;
|
||||
%$ catch
|
||||
%$ t(2) = 0;
|
||||
%$ end
|
||||
%$ end
|
||||
%$
|
||||
%$ % detrend (linear).
|
||||
%$ if t(2)
|
||||
%$ try
|
||||
%$ b3 = a.detrend(1);
|
||||
%$ t(3) = 1;
|
||||
%$ catch
|
||||
%$ t(3) = 0;
|
||||
%$ end
|
||||
%$ end
|
||||
%$
|
||||
%$ % detrend (quadratic).
|
||||
%$ if t(3)
|
||||
%$ try
|
||||
%$ b4 = a.detrend(2);
|
||||
%$ t(4) = 1;
|
||||
%$ catch
|
||||
%$ t(4) = 0;
|
||||
%$ end
|
||||
%$ end
|
||||
%$
|
||||
%$ % detrend (cubic).
|
||||
%$ if t(4)
|
||||
%$ try
|
||||
%$ b5 = a.detrend(3);
|
||||
%$ t(5) = 1;
|
||||
%$ catch
|
||||
%$ t(5) = 0;
|
||||
%$ end
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(5)
|
||||
%$ t(6) = dassert(max(mean(b1.data)),0,1e-12);
|
||||
%$ t(7) = dassert(max(mean(b2.data)),0,1e-12);
|
||||
%$ t(8) = dassert(max(mean(b3.data)),0,1e-12);
|
||||
%$ t(9) = dassert(max(mean(b4.data)),0,1e-12);
|
||||
%$ t(10) = dassert(max(mean(b5.data)),0,1e-12);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,40 +0,0 @@
|
|||
function disp(A)
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} disp (@var{A})
|
||||
%! @anchor{@dseries/disp}
|
||||
%! @sp 1
|
||||
%! Overloads the disp method for the Dynare time series class (@ref{dseries}).
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item A
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! None
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
separator = repmat(' | ', nobs(A)+1,1);
|
||||
vspace = ' ';
|
||||
TABLE = ' ';
|
||||
for t=1:nobs(A)
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
for i = 1:vobs(A)
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
end
|
||||
disp(vspace)
|
||||
disp([inputname(1) ' is a dseries object:'])
|
||||
disp(vspace);
|
||||
disp(TABLE);
|
||||
disp(vspace);
|
|
@ -1,128 +0,0 @@
|
|||
function display(A)
|
||||
%@info:
|
||||
%! @deftypefn {Function File} display (@var{A})
|
||||
%! @anchor{@dseries/display}
|
||||
%! @sp 1
|
||||
%! Overloads the disp method for the Dynare time series class (@ref{dseries}).
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item A
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! None
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
vspace = ' ';
|
||||
TABLE = ' ';
|
||||
|
||||
if vobs(A)<=10
|
||||
if nobs(A)<=40
|
||||
separator = repmat(' | ', nobs(A)+1,1);
|
||||
for t=1:nobs(A)
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
for i = 1:vobs(A)
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
end
|
||||
else
|
||||
n = 10;
|
||||
separator = repmat(' | ',2*n+3,1);
|
||||
for t=1:n
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
TABLE = char(TABLE,vspace);
|
||||
for t = nobs(A)-n:nobs(A)
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
for i=1:vobs(A)
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:10
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
tmp = char(tmp,vspace);
|
||||
for t=nobs(A)-10:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
end
|
||||
end
|
||||
else
|
||||
m = 4;
|
||||
if nobs(A)<=40
|
||||
separator = repmat(' | ', nobs(A)+1,1);
|
||||
for t=1:nobs(A)
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
for i = 1:m
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
end
|
||||
TABLE = horzcat(TABLE, separator, repmat(' ... ', nobs(A)+1,1));
|
||||
for i = vobs(A)-m+1:vobs(A)
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
end
|
||||
else
|
||||
n = 10;
|
||||
separator = repmat(' | ',2*n+3,1);
|
||||
for t=1:n
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
TABLE = char(TABLE,vspace);
|
||||
for t = nobs(A)-n:nobs(A)
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
for i=1:m
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:10
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
tmp = char(tmp,vspace);
|
||||
for t=nobs(A)-10:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
end
|
||||
TABLE = horzcat(TABLE, separator, repmat(' ... ', 2*n+3,1));
|
||||
for i=vobs(A)-m+1:vobs(A)
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:10
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
tmp = char(tmp,vspace);
|
||||
for t=nobs(A)-10:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
end
|
||||
end
|
||||
end
|
||||
disp(vspace)
|
||||
disp([inputname(1) ' is a dseries object:'])
|
||||
disp(vspace);
|
||||
if ~isempty(strtrim(TABLE))
|
||||
disp(TABLE);
|
||||
disp(vspace);
|
||||
end
|
|
@ -1,546 +0,0 @@
|
|||
function ts = dseries(varargin) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{ts} =} dseries (@var{a},@var{b},@var{c},@var{d})
|
||||
%! @anchor{dseries}
|
||||
%! @sp 1
|
||||
%! Constructor for the Dynare time series class.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 2
|
||||
%! If @code{nargin==0} then an empty dseries object is created. The object can be populated with data subsequently using the overloaded subsref method.
|
||||
%! @sp 2
|
||||
%! If @code{nargin==1} and if the input argument is a @ref{dates} object, then a dseries object without data is created. This object can be populated with the overload subsref method.
|
||||
%! @sp 2
|
||||
%! If @code{nargin==1} and if the input argument is a string for the name of a csv, m or mat file containing data, then a dseries object is created from these data.
|
||||
%! @sp 2
|
||||
%! If @code{nargin>1}:
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item a
|
||||
%! T*1 vector or T*N matrix of data.
|
||||
%! @item b
|
||||
%! Initial date. For Quaterly, Monthly or Weekly data, b must be a string. For yearly data or if the frequence is not defined b must be an integer.
|
||||
%! @item c
|
||||
%! N*1 cell array of strings or N*q array of strings. Names of the N time series.
|
||||
%! @item d
|
||||
%! N*1 cell array of strings or N*p array of characters. TeX names of the N time series.
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item ts
|
||||
%! Dynare time series object.
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Properties}
|
||||
%! @sp 1
|
||||
%! The constructor defines the following properties:
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item data
|
||||
%! Array of doubles (nobs*vobs).
|
||||
%! @item nobs
|
||||
%! Scalar integer, the number of observations.
|
||||
%! @item vobs
|
||||
%! Scalar integer, the number of variables.
|
||||
%! @item name
|
||||
%! Cell array of strings, names of the variables.
|
||||
%! @item tex
|
||||
%! Cell array of strings, tex names of the variables.
|
||||
%! @item freq
|
||||
%! Scalar integer, the frequency of the time series. @var{freq} is equal to 1 if data are on a yearly basis or if
|
||||
%! frequency is unspecified. @var{freq} is equal to 4 if data are on a quaterly basis. @var{freq} is equal to
|
||||
%! 12 if data are on a monthly basis. @var{freq} is equal to 52 if data are on a weekly basis.
|
||||
%! @item init
|
||||
%! @ref{dates} object, initial date of the dataset.
|
||||
%! @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 && ischar(varargin{1}) && isequal(varargin{1},'initialize')
|
||||
ts = struct;
|
||||
ts.data = [];
|
||||
ts.name = {};
|
||||
ts.tex = {};
|
||||
ts.dates = dates();
|
||||
ts = class(ts,'dseries');
|
||||
assignin('base','emptydseriesobject',ts);
|
||||
return
|
||||
end
|
||||
|
||||
ts = evalin('base','emptydseriesobject');
|
||||
|
||||
switch nargin
|
||||
case 0
|
||||
% Create an empty dseries object.
|
||||
return
|
||||
case 1
|
||||
if isdates(varargin{1})
|
||||
switch length(varargin{1})
|
||||
case 0
|
||||
error(['dseries::dseries: Input (identified as a dates object) must be non empty!'])
|
||||
case 1
|
||||
% Create an empty dseries object with an initial date.
|
||||
ts.dates = varargin{1};
|
||||
otherwise
|
||||
% A range of dates is passed to the constructor
|
||||
ts.dates = varargin{1};
|
||||
end
|
||||
return
|
||||
elseif ischar(varargin{1})
|
||||
% Create a dseries object loading data in a file (*.csv, *.m, *.mat).
|
||||
if isempty(varargin{1})
|
||||
error('dseries:: 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});
|
||||
elseif check_file_extension(varargin{1},'csv')
|
||||
[freq,init,data,varlist] = load_csv_file_data(varargin{1});
|
||||
tex = [];
|
||||
elseif check_file_extension(varargin{1},'xls') || check_file_extension(varargin{1},'xlsx')
|
||||
if isglobalinbase('options_')
|
||||
% Check that the object is instantiated within a dynare session so that options_ global structure exists.
|
||||
% Should provide latter a mechanism to pass range and sheet to dseries constructor...
|
||||
range = evalin('base','options_.xls_range');
|
||||
sheet = evalin('base','options_.xls_sheet');
|
||||
else
|
||||
% By default only the (whole) first sheet is loaded.
|
||||
range = [];
|
||||
sheet = [];
|
||||
end
|
||||
[freq,init,data,varlist] = load_xls_file_data(varargin{1}, sheet, range);
|
||||
tex = [];
|
||||
else
|
||||
error(['dseries:: I''m not able to load data from ' varargin{1} '!'])
|
||||
end
|
||||
ts.data = data;
|
||||
ts.name = varlist;
|
||||
ts.dates = init:init+(nobs(ts)-1);
|
||||
if isempty(tex)
|
||||
ts.tex = name2tex(varlist);
|
||||
else
|
||||
ts.tex = tex;
|
||||
end
|
||||
elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2)
|
||||
ts.data = varargin{1};
|
||||
ts.name = default_name(vobs(ts));
|
||||
ts.tex = name2tex(ts.name);
|
||||
ts.dates = dates(1,1):dates(1,1)+(nobs(ts)-1);
|
||||
end
|
||||
case {2,3,4}
|
||||
if isequal(nargin,2) && ischar(varargin{1}) && isdates(varargin{2})
|
||||
% Instantiate dseries object with a data file and force the initial date to be as given by the second input argument.
|
||||
ds = dseries(varargin{1});
|
||||
ts = dseries(ds.data, varargin{2}, ds.name, ds.tex);
|
||||
return
|
||||
end
|
||||
if isequal(nargin,2) && ischar(varargin{1}) && ischar(varargin{2}) && isdate(varargin{2})
|
||||
% Instantiate dseries object with a data file and force the initial date to be as given by the second input argument.
|
||||
ds = dseries(varargin{1});
|
||||
ts = dseries(ds.data, dates(varargin{2}), ds.name, ds.tex);
|
||||
return
|
||||
end
|
||||
a = varargin{1};
|
||||
b = varargin{2};
|
||||
if nargin<4
|
||||
d = {};
|
||||
else
|
||||
d = varargin{4};
|
||||
if ~iscell(d) && ~isempty(d)
|
||||
d = cellstr(d);
|
||||
end
|
||||
end
|
||||
if nargin<3
|
||||
c = {};
|
||||
else
|
||||
c = varargin{3};
|
||||
if ~iscell(c) && ~isempty(c)
|
||||
c = cellstr(c);
|
||||
end
|
||||
end
|
||||
% Get data, number of observations and number of variables.
|
||||
ts.data = a;
|
||||
% Get the first date and set the frequency.
|
||||
if isempty(b)
|
||||
init = dates(1,1);
|
||||
elseif (isdates(b) && isequal(length(b),1))
|
||||
init = b;
|
||||
elseif ischar(b) && isdate(b)% Weekly, Monthly, Quaterly or Annual data (string).
|
||||
init = dates(b);
|
||||
elseif (isnumeric(b) && isscalar(b) && isint(b)) % Yearly data.
|
||||
init = dates([num2str(b) 'Y']);
|
||||
elseif isdates(b) % Range of dates
|
||||
init = b(1);
|
||||
if nobs(ts)>1 && ~isequal(b.ndat,nobs(ts))
|
||||
message = 'dseries::dseries: If second input is a range, its number of elements must match ';
|
||||
message = char(message, ' the number of rows in the first input, unless the first input');
|
||||
message = char(message, ' has only one row.');
|
||||
skipline()
|
||||
disp(message);
|
||||
error(' ');
|
||||
elseif isequal(nobs(ts), 1)
|
||||
ts.data = repmat(ts.data,b.ndat,1);
|
||||
end
|
||||
ts.dates = b;
|
||||
elseif (isnumeric(b) && isint(b)) % Range of yearly dates.
|
||||
message = 'dseries::dseries: Not implemented! If you need to define a range of years';
|
||||
message = char(message, ' you have to pass a dates object as the second input argument.');
|
||||
disp(message)
|
||||
error(' ')
|
||||
else
|
||||
error('dseries::dseries: Wrong calling sequence!');
|
||||
end
|
||||
% Get the names of the variables.
|
||||
if ~isempty(c)
|
||||
if vobs(ts)==length(c)
|
||||
for i=1:vobs(ts)
|
||||
ts.name = vertcat(ts.name, c(i));
|
||||
end
|
||||
else
|
||||
error('dseries::dseries: The number of declared names does not match the number of variables!')
|
||||
end
|
||||
else
|
||||
ts.name = default_name(vobs(ts));
|
||||
end
|
||||
if ~isempty(d)
|
||||
if vobs(ts)==length(d)
|
||||
for i=1:vobs(ts)
|
||||
ts.tex = vertcat(ts.tex, d(i));
|
||||
end
|
||||
else
|
||||
error('dseries::dseries: The number of declared tex names does not match the number of variables!')
|
||||
end
|
||||
else
|
||||
ts.tex = name2tex(ts.name);
|
||||
end
|
||||
otherwise
|
||||
error('dseries::dseries: Can''t instantiate the class, wrong calling sequence!')
|
||||
end
|
||||
|
||||
if isempty(ts.dates)
|
||||
ts.dates = init:init+(nobs(ts)-1);
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Test if we can instantiate an empty dseries object.
|
||||
%$ try
|
||||
%$ ts = dseries();
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ aa = dates('1938M11');
|
||||
%$ ts = dseries(aa);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,12);
|
||||
%$ t(3) = dassert(ts.init.freq,12);
|
||||
%$ t(4) = dassert(ts.init.time,[1938, 11]);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ t = zeros(6,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ ts = dseries('dynseries_test_data.m');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1994, 3]);
|
||||
%$ t(5) = dassert(ts.vobs,2);
|
||||
%$ t(6) = dassert(ts.nobs,100);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ t = zeros(6,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ ts = dseries('dynseries_test_data.mat');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1994, 3]);
|
||||
%$ t(5) = dassert(ts.vobs,2);
|
||||
%$ t(6) = dassert(ts.nobs,100);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ t = zeros(8,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ ts = dseries('dynseries_test_data.csv');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1990, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,4);
|
||||
%$ t(6) = dassert(ts.nobs,4);
|
||||
%$ t(7) = dassert(ts.name,{'azert';'yuiop';'qsdfg';'jklm'});
|
||||
%$ t(8) = dassert(ts.tex,{'azert';'yuiop';'qsdfg';'jklm'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:5
|
||||
|
||||
%@test:6
|
||||
%$ t = zeros(8,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ ts = dseries(transpose(1:5),[]);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,1);
|
||||
%$ t(3) = dassert(ts.init.freq,1);
|
||||
%$ t(4) = dassert(ts.init.time,[1, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,1);
|
||||
%$ t(6) = dassert(ts.nobs,5);
|
||||
%$ t(7) = dassert(ts.name,{'Variable_1'});
|
||||
%$ t(8) = dassert(ts.tex,{'Variable\\_1'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:6
|
||||
|
||||
%@test:7
|
||||
%$ t = zeros(8,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ ts = dseries(transpose(1:5),'1950Q1');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,1);
|
||||
%$ t(6) = dassert(ts.nobs,5);
|
||||
%$ t(7) = dassert(ts.name,{'Variable_1'});
|
||||
%$ t(8) = dassert(ts.tex,{'Variable\\_1'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:7
|
||||
|
||||
%@test:8
|
||||
%$ t = zeros(8,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,2);
|
||||
%$ t(6) = dassert(ts.nobs,5);
|
||||
%$ t(7) = dassert(ts.name,{'Output'; 'Consumption'});
|
||||
%$ t(8) = dassert(ts.tex,{'Y_t'; 'C_t'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:8
|
||||
|
||||
%@test:9
|
||||
%$ try
|
||||
%$ ts = dseries('dynseries_test_data-1.xls');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1990, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,3);
|
||||
%$ t(6) = dassert(ts.nobs,5);
|
||||
%$ t(7) = dassert(ts.name,{'GDP';'Consumption';'CPI'});
|
||||
%$ t(8) = dassert(ts.tex,{'GDP';'Consumption';'CPI'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:9
|
||||
|
||||
%@test:10
|
||||
%$ try
|
||||
%$ ts = dseries('dynseries_test_data-2.xls');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1990, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,3);
|
||||
%$ t(6) = dassert(ts.nobs,5);
|
||||
%$ t(7) = dassert(ts.name,{'Variable_1';'Variable_2';'Variable_3'});
|
||||
%$ t(8) = dassert(ts.tex,{'Variable\\_1';'Variable\\_2';'Variable\\_3'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:10
|
||||
|
||||
%@test:11
|
||||
%$ try
|
||||
%$ ts = dseries('dynseries_test_data-3.xls');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts.freq,1);
|
||||
%$ t(3) = dassert(ts.init.freq,1);
|
||||
%$ t(4) = dassert(ts.init.time,[1, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,3);
|
||||
%$ t(6) = dassert(ts.nobs,5);
|
||||
%$ t(7) = dassert(ts.name,{'Variable_1';'Variable_2';'Variable_3'});
|
||||
%$ t(8) = dassert(ts.tex,{'Variable\\_1';'Variable\\_2';'Variable\\_3'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:11
|
||||
|
||||
%@test:12
|
||||
%$ try
|
||||
%$ ts = dseries('dynseries_test_data-4.xls');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts.freq,1);
|
||||
%$ t(3) = dassert(ts.init.freq,1);
|
||||
%$ t(4) = dassert(ts.init.time,[1, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,3);
|
||||
%$ t(6) = dassert(ts.nobs,5);
|
||||
%$ t(7) = dassert(ts.name,{'GDP';'Consumption';'CPI'});
|
||||
%$ t(8) = dassert(ts.tex,{'GDP';'Consumption';'CPI'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:12
|
||||
|
||||
%@test:13
|
||||
%$ t = zeros(6,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ ts = dseries(transpose(1:4),dates('1990Q1'):dates('1990Q4'));
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1990, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,1);
|
||||
%$ t(6) = dassert(ts.nobs,4);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:13
|
||||
|
||||
%@test:14
|
||||
%$ t = zeros(7,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ ts = dseries([1, 2],dates('1990Q1'):dates('1990Q4'));
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1990, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,2);
|
||||
%$ t(6) = dassert(ts.nobs,4);
|
||||
%$ t(7) = dassert(ts.data, [ones(4,1), 2*ones(4,1)]);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:14
|
||||
|
||||
%@test:15
|
||||
%$ try
|
||||
%$ ts = dseries([1; 2],dates('1990Q1'):dates('1990Q4'));
|
||||
%$ t = 0;
|
||||
%$ catch
|
||||
%$ t = 1;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:15
|
|
@ -1,21 +0,0 @@
|
|||
function lastIndex = end(o, k, n)
|
||||
|
||||
% Copyright (C) 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/>.
|
||||
|
||||
assert(k==1 && n==1, 'dseries::end: Wrong indexing!');
|
||||
lastIndex = vobs(o);
|
|
@ -1,89 +0,0 @@
|
|||
function C = eq(A,B) % --*-- Unitary tests --*--
|
||||
|
||||
% Overloads eq (==) operator.
|
||||
%
|
||||
% INPUTS
|
||||
% o A dseries object (T periods, N variables).
|
||||
% o B dseries object (T periods, N variables).
|
||||
%
|
||||
% OUTPUTS
|
||||
% o C T*N matrix of zeros and ones. Element C(t,n) is nonzero iff observation t of variable n in A and B are equal.
|
||||
%
|
||||
% REMARKS
|
||||
% If the number of variables, the number of observations or the frequencies are different in A and B, the function returns a zero scalar.
|
||||
|
||||
% 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 nargin~=2
|
||||
error('dseries::eq: I need exactly two input arguments!')
|
||||
end
|
||||
|
||||
if ~(isdseries(A) && isdseries(B))
|
||||
error('dseries::eq: Both input arguments must be dseries objects!')
|
||||
end
|
||||
|
||||
if ~isequal(nobs(A), nobs(B))
|
||||
warning('dseries::eq: Both input arguments should have the same number of observations!')
|
||||
C = 0;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(vobs(A), vobs(B))
|
||||
warning('dseries::eq: Both input arguments should have the same number of observations!')
|
||||
C = 0;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(frequency(A),frequency(B))
|
||||
warning('dseries::eq: Both input arguments should have the same frequencies!')
|
||||
C = 0;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(firstdate(A),firstdate(B))
|
||||
warning('dseries::eq: Both input arguments should have the same initial period!')
|
||||
C = 0;
|
||||
return
|
||||
end
|
||||
|
||||
C = eq(A.data, B.data);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'A3'};
|
||||
%$
|
||||
%$ t = zeros(2,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = ts1;
|
||||
%$ a = eq(ts1,ts2);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(a,logical(ones(10,3)));
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,57 +0,0 @@
|
|||
function l = exist(o, varname) % --*-- Unitary tests --*--
|
||||
|
||||
% Tests if a variable exists in dseries object o.
|
||||
%
|
||||
% INPUTS
|
||||
% - o [dseries], dseries object.
|
||||
% - varname [string], name of a variable.
|
||||
%
|
||||
% OUTPUTS
|
||||
% - l [logical], equal to 1 (true) iff varname is a variable in dseries object o.
|
||||
|
||||
% Copyright (C) 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(varname)
|
||||
error(['dseries::exist: Input arguments ''' inputname(2) ''' has to be string!'])
|
||||
end
|
||||
|
||||
l = ~isempty(strmatch(varname, o.name, 'exact'));
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ data = randn(10,4);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ names = {'Noddy';'Jumbo';'Sly';'Gobbo'};
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object and compute the absolute value.
|
||||
%$ try
|
||||
%$ ts = dseries(data,[],names,[]);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts.exist('Noddy'),true);
|
||||
%$ t(3) = dassert(ts.exist('noddy'),false);
|
||||
%$ t(4) = dassert(ts.exist('Boots'),false);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,52 +0,0 @@
|
|||
function ts = exp(ts)
|
||||
% Apply the exponential function to a Dynare time series object.
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{ts} =} log(@var{ts})
|
||||
%! @anchor{exp}
|
||||
%! Apply the exponential function to a Dynare time series object.
|
||||
%!
|
||||
%! @strong{Inputs}
|
||||
%! @table @var
|
||||
%! @item ts
|
||||
%! Dynare time series object, instantiated by @ref{dseries}
|
||||
%! @end table
|
||||
%!
|
||||
%! @strong{Outputs}
|
||||
%! @table @var
|
||||
%! @item ts
|
||||
%! Dynare time series object with transformed data field.
|
||||
%! @end table
|
||||
%!
|
||||
%! @strong{This function is called by:}
|
||||
%! None.
|
||||
%!
|
||||
%! @strong{This function calls:}
|
||||
%! None.
|
||||
%!
|
||||
%! @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/>.
|
||||
|
||||
ts.data = exp(ts.data);
|
||||
|
||||
for i=1:vobs(ts)
|
||||
ts.name(i) = {['exp(' ts.name{i} ')']};
|
||||
ts.tex(i) = {['\exp(' ts.tex{i} ')']};
|
||||
end
|
|
@ -1,230 +0,0 @@
|
|||
function A = extract(B,varargin) % --*-- Unitary tests --*--
|
||||
|
||||
% Extract some variables from a database.
|
||||
|
||||
% Copyright (C) 2012-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/>.
|
||||
|
||||
A = dseries();
|
||||
|
||||
% Get the names of the variables to be extracted from dseries object B.
|
||||
VariableName_ = {};
|
||||
for i=1:nargin-1
|
||||
VariableName = varargin{i};
|
||||
idArobase = strfind(VariableName,'@');
|
||||
if mod(length(idArobase),2)
|
||||
error('dseries::extract: (Implicit loops) The number of @ symbols must be even!')
|
||||
end
|
||||
idBracket.open = strfind(VariableName,'[');
|
||||
idBracket.close = strfind(VariableName,']');
|
||||
if ~isequal(length(idBracket.open),length(idBracket.open))
|
||||
error('dseries::extract: (Matlab/Octave''s regular expressions) Check opening and closing square brackets!')
|
||||
end
|
||||
if length(idArobase)
|
||||
NumberOfImplicitLoops = .5*length(idArobase);
|
||||
idComma = cell(NumberOfImplicitLoops,1);
|
||||
expressions = cell(NumberOfImplicitLoops,1);
|
||||
for i=0:NumberOfImplicitLoops-1
|
||||
idComma(i+1) = { strfind(VariableName(idArobase(2*i+1)+1:idArobase(2*i+2)-1),',') };
|
||||
expressions(i+1) = { VariableName(idArobase(2*i+1)+1:idArobase(2*i+2)-1) };
|
||||
end
|
||||
if any(cellfun(@isempty,idComma))
|
||||
error('dseries::extract: (Implicit loops) Wrong syntax!')
|
||||
end
|
||||
switch NumberOfImplicitLoops
|
||||
case 1
|
||||
expression = expressions{1};
|
||||
idVariables_ = [];
|
||||
while ~isempty(expression)
|
||||
[token, expression] = strtok(expression,',');
|
||||
candidate = [VariableName(1:idArobase(1)-1), token, VariableName(idArobase(2)+1:end)];
|
||||
id = find(strcmp(candidate,B.name));
|
||||
if isempty(id)
|
||||
error(['dseries::extract: (Implicit loops) Variable ''' candidate ''' does not exist in dseries object ''' inputname(1) '''!'])
|
||||
else
|
||||
idVariables_ = [idVariables_; id];
|
||||
end
|
||||
end
|
||||
VariableName = B.name(idVariables_);
|
||||
case 2
|
||||
idVariables_ = [];
|
||||
expression_1 = expressions{1};
|
||||
while ~isempty(expression_1)
|
||||
[token_1, expression_1] = strtok(expression_1,',');
|
||||
expression_2 = expressions{2};
|
||||
while ~isempty(expression_2)
|
||||
[token_2, expression_2] = strtok(expression_2,',');
|
||||
candidate = [VariableName(1:idArobase(1)-1), token_1, VariableName(idArobase(2)+1:idArobase(3)-1), token_2, VariableName(idArobase(4)+1:end)];
|
||||
id = find(strcmp(candidate,B.name));
|
||||
if isempty(id)
|
||||
error(['dseries::extract: (Implicit loops) Variable ''' candidate ''' does not exist in dseries object ''' inputname(1) '''!'])
|
||||
else
|
||||
idVariables_ = [idVariables_; id];
|
||||
end
|
||||
end
|
||||
end
|
||||
VariableName = B.name(idVariables_);
|
||||
otherwise
|
||||
error('dseries::extract: (Implicit loops) Cannot unroll more than two implicit loops!')
|
||||
end
|
||||
VariableName_ = vertcat(VariableName_,VariableName);
|
||||
elseif length(idBracket.open)
|
||||
% Matlab/Octave's regular expressions.
|
||||
first_block_id = 0;
|
||||
last_block_id = 0;
|
||||
idVariables = find(isnotempty_cell(regexp(B.name,VariableName,'match')));
|
||||
if isempty(idVariables)
|
||||
error(['dseries::extract: Can''t find any variable matching ' VariableName ' pattern!'])
|
||||
end
|
||||
idVariables_ = [];
|
||||
for j = 1:length(idVariables)
|
||||
first_block_flag = 0;
|
||||
if (first_block_id && strcmp(B.name{idVariables(j)}(1:first_block_id),VariableName(1:first_block_id))) || ~first_block_id
|
||||
first_block_flag = 1;
|
||||
end
|
||||
last_block_flag = 0;
|
||||
if (last_block_id && strcmp(B.name{idVariables(j)}(end-last_block_id:end),VariableName(end-last_block_id:end))) || ~last_block_id
|
||||
last_block_flag = 1;
|
||||
end
|
||||
if first_block_flag && last_block_flag
|
||||
idVariables_ = [idVariables_; idVariables(j)];
|
||||
end
|
||||
end
|
||||
VariableName = B.name(idVariables_);
|
||||
VariableName_ = vertcat(VariableName_,VariableName);
|
||||
else
|
||||
VariableName_ = varargin(:);
|
||||
end
|
||||
end
|
||||
|
||||
% Remove trailing white spaces if any
|
||||
VariableName_ = strtrim(VariableName_);
|
||||
|
||||
% Get indices of the selected variables
|
||||
idVariableName = NaN(length(VariableName_),1);
|
||||
for i = 1:length(idVariableName)
|
||||
idx = find(strcmp(VariableName_{i},B.name));
|
||||
if isempty(idx)
|
||||
error(['dseries::extract: Variable ' VariableName_{i} ' is not a member of ' inputname(1) '!'])
|
||||
end
|
||||
idVariableName(i) = idx;
|
||||
end
|
||||
|
||||
A.data = B.data(:,idVariableName);
|
||||
A.dates = B.dates;
|
||||
A.name = B.name(idVariableName);
|
||||
A.tex = B.tex(idVariableName);
|
||||
|
||||
function b = isnotempty_cell(CellArray)
|
||||
CellArrayDimension = size(CellArray);
|
||||
b = NaN(CellArrayDimension);
|
||||
for i=1:CellArrayDimension(1)
|
||||
for j = 1:CellArrayDimension(2)
|
||||
b(i,j) = ~isempty(CellArray{i,j});
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
%@test:1
|
||||
%$ % Define a data set.
|
||||
%$ A = rand(10,24);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'; 'HICP_1';'HICP_2';'HICP_3'; 'HICP_4'; 'HICP_5'; 'HICP_6'; 'HICP_7'; 'HICP_8'; 'HICP_9'; 'HICP_10'; 'HICP_11'; 'HICP_12';};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ a = ts1{'GDP_@1,2,3,4,5@'};
|
||||
%$ b = ts1{'@GDP,HICP@_1'};
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ e1.data = A(:,1:5);
|
||||
%$ e1.nobs = 10;
|
||||
%$ e1.vobs = 5;
|
||||
%$ e1.name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'};
|
||||
%$ e1.freq = 1;
|
||||
%$ e1.init = dates(1,1);
|
||||
%$ e2.data = A(:,[1, 13]);
|
||||
%$ e2.nobs = 10;
|
||||
%$ e2.vobs = 2;
|
||||
%$ e2.name = {'GDP_1';'HICP_1'};
|
||||
%$ e2.freq = 1;
|
||||
%$ e2.init = dates(1,1);
|
||||
%$
|
||||
%$ % Check results.
|
||||
%$ t(1) = dassert(e1.data,a.data);
|
||||
%$ t(2) = dassert(e1.nobs,a.nobs);
|
||||
%$ t(3) = dassert(e1.vobs,a.vobs);
|
||||
%$ t(4) = dassert(e1.name,a.name);
|
||||
%$ t(5) = dassert(e1.init,a.init);
|
||||
%$ t(6) = dassert(e2.data,b.data);
|
||||
%$ t(7) = dassert(e2.nobs,b.nobs);
|
||||
%$ t(8) = dassert(e2.vobs,b.vobs);
|
||||
%$ t(9) = dassert(e2.name,b.name);
|
||||
%$ t(10) = dassert(e2.init,b.init);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
|
||||
%@test:2
|
||||
%$ % Define a data set.
|
||||
%$ A = rand(10,24);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'; 'HICP_1';'HICP_2';'HICP_3'; 'HICP_4'; 'HICP_5'; 'HICP_6'; 'HICP_7'; 'HICP_8'; 'HICP_9'; 'HICP_10'; 'HICP_11'; 'HICP_12';};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ try
|
||||
%$ a = ts1{'GDP_@1,2,3,4,55@'};
|
||||
%$ t = 0;
|
||||
%$ catch
|
||||
%$ t = 1;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
|
||||
%@test:3
|
||||
%$ % Define a data set.
|
||||
%$ A = rand(10,24);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'; 'HICP_1';'HICP_2';'HICP_3'; 'HICP_4'; 'HICP_5'; 'HICP_6'; 'HICP_7'; 'HICP_8'; 'HICP_9'; 'HICP_10'; 'HICP_11'; 'HICP_12';};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ try
|
||||
%$ a = ts1{'@GDP,HICP@_@1,2,3,4,5@'};
|
||||
%$ t = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(a.name,{'GDP_1';'GDP_2';'GDP_3';'GDP_4';'GDP_5';'HICP_1';'HICP_2';'HICP_3';'HICP_4';'HICP_5'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
|
@ -1,20 +0,0 @@
|
|||
function f = firstdate(o)
|
||||
|
||||
% Copyright (C) 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/>.
|
||||
|
||||
f = o.dates(1);
|
|
@ -1,20 +0,0 @@
|
|||
function f = frequency(o)
|
||||
|
||||
% Copyright (C) 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/>.
|
||||
|
||||
f = o.dates.freq;
|
|
@ -1,317 +0,0 @@
|
|||
function B = horzcat(varargin) % --*-- Unitary tests --*--
|
||||
|
||||
% Overloads horzcat method for dseries objects.
|
||||
%
|
||||
% INPUTS
|
||||
% o A1 dseries object.
|
||||
% o A2 dseries object.
|
||||
% o ...
|
||||
%
|
||||
% OUTPUTS
|
||||
% o B dseries object.
|
||||
%
|
||||
% EXAMPLE 1
|
||||
% If A, B and C are dseries objects the following syntax:
|
||||
%
|
||||
% D = [A, B, C] ;
|
||||
%
|
||||
% Defines a dseries object D containing the variables appearing in A, B and C.
|
||||
%
|
||||
% REMARKS
|
||||
% o A1, A2, ... must not have common variables.
|
||||
|
||||
% 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/>.
|
||||
|
||||
switch nargin
|
||||
case 0
|
||||
B = dseries();
|
||||
case 1
|
||||
B = varargin{1};
|
||||
otherwise
|
||||
B = concatenate(varargin{1}, varargin{2});
|
||||
if nargin>2
|
||||
B = horzcat(B, varargin{3:end});
|
||||
end
|
||||
end
|
||||
|
||||
function a = concatenate(b,c)
|
||||
[n,message] = common_strings_in_cell_arrays(b.name,c.name);
|
||||
if isempty(b)
|
||||
a = c;
|
||||
return
|
||||
end
|
||||
if isempty(c)
|
||||
a = b;
|
||||
return
|
||||
end
|
||||
if n
|
||||
error(['dseries::horzcat: I cannot concatenate dseries objects with common variable names (' message ')!'])
|
||||
end
|
||||
if ~isequal(frequency(b),frequency(c))
|
||||
error('dseries::horzcat: All time series objects must have common frequency!')
|
||||
else
|
||||
a = dseries();
|
||||
end
|
||||
d_nobs_flag = 0;
|
||||
if ~isequal(nobs(b),nobs(c))
|
||||
d_nobs_flag = 1;
|
||||
end
|
||||
d_init_flag = 0;
|
||||
if ~isequal(firstdate(b),firstdate(c))
|
||||
d_init_flag = 1;
|
||||
end
|
||||
a.name = vertcat(b.name,c.name);
|
||||
a.tex = vertcat(b.tex,c.tex);
|
||||
if ~( d_nobs_flag(1) || d_init_flag(1) )
|
||||
a.data = [b.data,c.data];
|
||||
a.dates = b.dates;
|
||||
else
|
||||
nobs_b = nobs(b);
|
||||
nobs_c = nobs(c);
|
||||
if firstdate(b)<=firstdate(c)
|
||||
if firstdate(b)<firstdate(c)
|
||||
c.data = [NaN(firstdate(c)-firstdate(b), vobs(c)); c.data];
|
||||
end
|
||||
else
|
||||
b.data = [NaN(firstdate(b)-firstdate(c), vobs(b)); b.data];
|
||||
end
|
||||
b_last_date = firstdate(b)+nobs_b;
|
||||
c_last_date = firstdate(c)+nobs_c;
|
||||
if b_last_date<c_last_date
|
||||
b.data = [b.data; NaN(c_last_date-b_last_date, vobs(b))];
|
||||
elseif b_last_date>c_last_date
|
||||
c.data = [c.data; NaN(b_last_date-c_last_date, vobs(c))];
|
||||
end
|
||||
a.data = [b.data, c.data];
|
||||
a.dates = unique([b.dates, c.dates]);
|
||||
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 = {'B1';'B2'};
|
||||
%$
|
||||
%$ % Define expected results.
|
||||
%$ e.init = dates(1,1);
|
||||
%$ e.freq = 1;
|
||||
%$ e.name = {'A1';'A2';'B1';'B2'};
|
||||
%$ e.data = [A,B];
|
||||
%$
|
||||
%$ % Instantiate two time series objects.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts3 = [ts1,ts2];
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$
|
||||
%$ t(1) = dassert(ts3.init,e.init);
|
||||
%$ t(2) = dassert(ts3.freq,e.freq);
|
||||
%$ t(3) = dassert(ts3.data,e.data);
|
||||
%$ t(4) = dassert(ts3.name,e.name);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$ B = [transpose(5:12),2*transpose(5:12)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$ B_name = {'B1';'B2'};
|
||||
%$
|
||||
%$ % Define initial date
|
||||
%$ A_init = 2001;
|
||||
%$ B_init = 2005;
|
||||
%$
|
||||
%$ % Define expected results.
|
||||
%$ e.init = dates('2001Y');
|
||||
%$ e.freq = 1;
|
||||
%$ e.name = {'A1';'A2';'B1';'B2'};
|
||||
%$ e.data = [ [A; NaN(2,2)], [NaN(4,2); B]];
|
||||
%$
|
||||
%$ % Instantiate two time series objects.
|
||||
%$ ts1 = dseries(A,A_init,A_name,[]);
|
||||
%$ ts2 = dseries(B,B_init,B_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts3 = [ts1,ts2];
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = dassert(ts3.init,e.init);
|
||||
%$ t(2) = dassert(ts3.freq,e.freq);
|
||||
%$ t(3) = dassert(ts3.data,e.data);
|
||||
%$ t(4) = dassert(ts3.name,e.name);
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:7),2*transpose(1:7)];
|
||||
%$ B = [transpose(5:11),2*transpose(5:11)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$ B_name = {'B1';'B2'};
|
||||
%$
|
||||
%$ % Define initial date
|
||||
%$ A_init = '1950Q1';
|
||||
%$ B_init = '1950Q3';
|
||||
%$
|
||||
%$ % Define expected results.
|
||||
%$ e.freq = 4;
|
||||
%$ e.init = dates('1950Q1');
|
||||
%$ e.name = {'A1';'A2';'B1';'B2'};
|
||||
%$ e.data = [ [A; NaN(2,2)], [NaN(2,2); B]];
|
||||
%$
|
||||
%$ % Instantiate two time series objects.
|
||||
%$ ts1 = dseries(A,A_init,A_name,[]);
|
||||
%$ ts2 = dseries(B,B_init,B_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts3 = [ts1,ts2];
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = dassert(ts3.init,e.init);
|
||||
%$ t(2) = dassert(ts3.freq,e.freq);
|
||||
%$ t(3) = dassert(ts3.data,e.data);
|
||||
%$ t(4) = dassert(ts3.name,e.name);
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:7),2*transpose(1:7)];
|
||||
%$ B = [transpose(5:9),2*transpose(5:9)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$ B_name = {'B1';'B2'};
|
||||
%$
|
||||
%$ % Define initial date
|
||||
%$ A_init = '1950Q1';
|
||||
%$ B_init = '1950Q3';
|
||||
%$
|
||||
%$ % Define expected results.
|
||||
%$ e.init = dates(A_init);
|
||||
%$ e.freq = 4;
|
||||
%$ e.name = {'A1';'A2';'B1';'B2'};
|
||||
%$ e.data = [ A, [NaN(2,2); B]];
|
||||
%$
|
||||
%$ % Instantiate two time series objects.
|
||||
%$ ts1 = dseries(A,A_init,A_name,[]);
|
||||
%$ ts2 = dseries(B,B_init,B_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts3 = [ts1,ts2];
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = dassert(ts3.init,e.init);
|
||||
%$ t(2) = dassert(ts3.freq,e.freq);
|
||||
%$ t(3) = dassert(ts3.data,e.data);
|
||||
%$ t(4) = dassert(ts3.name,e.name);
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$ B = [transpose(1:10),3*transpose(1:10)];
|
||||
%$ C = [transpose(1:10),4*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$ B_name = {'B1';'B2'};
|
||||
%$ C_name = {'C1';'C2'};
|
||||
%$
|
||||
%$ % Define expected results.
|
||||
%$ e.init = dates(1,1);
|
||||
%$ e.freq = 1;
|
||||
%$ e.name = {'A1';'A2';'B1';'B2';'C1';'C2'};
|
||||
%$ e.data = [A,B,C];
|
||||
%$
|
||||
%$ % Instantiate two time series objects.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$ ts3 = dseries(C,[],C_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts4 = [ts1,ts2,ts3];
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = dassert(ts4.init,e.init);
|
||||
%$ t(2) = dassert(ts4.freq,e.freq);
|
||||
%$ t(3) = dassert(ts4.data,e.data);
|
||||
%$ t(4) = dassert(ts4.name,e.name);
|
||||
%$ T = all(t);
|
||||
%@eof:5
|
||||
|
||||
%@test:6
|
||||
%$ % 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 = {'B1';'A2'};
|
||||
%$
|
||||
%$ % Instantiate two time series objects.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ try
|
||||
%$ ts3 = [ts1,ts2];
|
||||
%$ t = 0;
|
||||
%$ catch
|
||||
%$ t = 1;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = t;
|
||||
%@eof:6
|
||||
|
||||
%@test:7
|
||||
%$ % Define X
|
||||
%$ X = randn(30,2);
|
||||
%$
|
||||
%$ % Instantiate two time series objects.
|
||||
%$ ts1 = dseries();
|
||||
%$ ts2 = dseries(randn(30,2),'1950Q2');
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ try
|
||||
%$ ts3 = [ts1,ts2];
|
||||
%$ t = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts3.freq,4);
|
||||
%$ t(3) = dassert(ts3.data,X);
|
||||
%$ t(4) = dassert(ts3.dates(1),dates('1950Q2'));
|
||||
%$ end
|
||||
%$
|
||||
%$ T = t;
|
||||
%@eof:7
|
|
@ -1,96 +0,0 @@
|
|||
function ts = hpcycle(ts, lambda) % --*-- Unitary tests --*--
|
||||
|
||||
% ts = hpcycle(ts, lambda)
|
||||
%
|
||||
% Extracts the cycle component from a dseries object using Hodrick Prescott filter.
|
||||
%
|
||||
% INPUTS
|
||||
% o ts dseries object.
|
||||
% o lambda positive scalar, trend smoothness parameter.
|
||||
%
|
||||
% OUTPUTS
|
||||
% o ts dseries object, with time series replaced by the cyclical component of the original time series.
|
||||
|
||||
% 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 nargin>1
|
||||
if lambda<=0
|
||||
error(['dseries::hpcycle: Lambda must be a positive integer!'])
|
||||
end
|
||||
else
|
||||
lambda = [];
|
||||
end
|
||||
|
||||
for i=1:vobs(ts)
|
||||
ts.name(i) = {['hpcycle(' ts.name{i} ')']};
|
||||
ts.tex(i) = {['\text{hpcycle}(' ts.tex{i} ')']};
|
||||
end
|
||||
|
||||
[junk, data] = sample_hp_filter(ts.data,lambda);
|
||||
ts.data = data;
|
||||
|
||||
%@test:1
|
||||
%$ plot_flag = 0;
|
||||
%$
|
||||
%$ % Create a dataset.
|
||||
%$ e = .2*randn(200,1);
|
||||
%$ u = randn(200,1);
|
||||
%$ stochastic_trend = cumsum(e);
|
||||
%$ deterministic_trend = .1*transpose(1:200);
|
||||
%$ x = zeros(200,1);
|
||||
%$ for i=2:200
|
||||
%$ x(i) = .9*x(i-1) + e(i);
|
||||
%$ end
|
||||
%$ y = x + stochastic_trend + deterministic_trend;
|
||||
%$
|
||||
%$ % Test the routine.
|
||||
%$ try
|
||||
%$ ts0 = dseries(y,'1950Q1');
|
||||
%$ ts1 = dseries(x,'1950Q1');
|
||||
%$ ts2 = ts0.hpcycle();
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts2.freq,4);
|
||||
%$ t(3) = dassert(ts2.init.freq,4);
|
||||
%$ t(4) = dassert(ts2.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(ts2.vobs,1);
|
||||
%$ t(6) = dassert(ts2.nobs,200);
|
||||
%$ end
|
||||
%$
|
||||
%$ % Show results
|
||||
%$ if plot_flag
|
||||
%$ plot(ts1.data,'-k'); % Plot of the stationary component.
|
||||
%$ hold on
|
||||
%$ plot(ts2.data,'--r'); % Plot of the filtered y.
|
||||
%$ hold off
|
||||
%$ axis tight
|
||||
%$ id = get(gca,'XTick');
|
||||
%$ set(gca,'XTickLabel',strings(ts1.dates(id)));
|
||||
%$ legend({'Stationary component of y', 'Filtered y'})
|
||||
%$ print('-depsc2','../doc/dynare.plots/HPCycle.eps')
|
||||
%$ system('convert -density 300 ../doc/dynare.plots/HPCycle.eps ../doc/dynare.plots/HPCycle.png');
|
||||
%$ system('convert -density 300 ../doc/dynare.plots/HPCycle.eps ../doc/dynare.plots/HPCycle.pdf');
|
||||
%$ system('convert -density 300 ../doc/dynare.plots/HPCycle.eps ../doc/dynare.plots/HPCycle.jpg');
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,94 +0,0 @@
|
|||
function ts = hptrend(ts, lambda) % --*-- Unitary tests --*--
|
||||
|
||||
% ts = hptrend(ts, lambda)
|
||||
%
|
||||
% Extracts the trend component from a dseries object using Hodrick Prescott filter.
|
||||
%
|
||||
% INPUTS
|
||||
% o ts dseries object.
|
||||
% o lambda positive scalar, trend smoothness parameter.
|
||||
%
|
||||
% OUTPUTS
|
||||
% o ts dseries object, with time series replaced by the trend component of the original time series.
|
||||
|
||||
% 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 nargin>1
|
||||
if lambda<=0
|
||||
error(['dseries::hptrend: Lambda must be a positive integer!'])
|
||||
end
|
||||
else
|
||||
lambda = [];
|
||||
end
|
||||
|
||||
for i=1:vobs(ts)
|
||||
ts.name(i) = {['hptrend(' ts.name{i} ')']};
|
||||
ts.tex(i) = {['\text{hptrend}(' ts.tex{i} ')']};
|
||||
end
|
||||
|
||||
ts.data = sample_hp_filter(ts.data,lambda);
|
||||
|
||||
%@test:1
|
||||
%$ plot_flag = 0;
|
||||
%$
|
||||
%$ % Create a dataset.
|
||||
%$ e = .2*randn(200,1);
|
||||
%$ u = randn(200,1);
|
||||
%$ stochastic_trend = cumsum(e);
|
||||
%$ deterministic_trend = .1*transpose(1:200);
|
||||
%$ x = zeros(200,1);
|
||||
%$ for i=2:200
|
||||
%$ x(i) = .75*x(i-1) + e(i);
|
||||
%$ end
|
||||
%$ y = x + stochastic_trend + deterministic_trend;
|
||||
%$
|
||||
%$ % Test the routine.
|
||||
%$ try
|
||||
%$ ts0 = dseries(y,'1950Q1');
|
||||
%$ ts1 = dseries(stochastic_trend+deterministic_trend,'1950Q1');
|
||||
%$ ts2 = ts0.hptrend(1600);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts2.freq,4);
|
||||
%$ t(3) = dassert(ts2.init.freq,4);
|
||||
%$ t(4) = dassert(ts2.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(ts2.vobs,1);
|
||||
%$ t(6) = dassert(ts2.nobs,200);
|
||||
%$ end
|
||||
%$
|
||||
%$ % Show results
|
||||
%$ if plot_flag
|
||||
%$ plot(ts1.data,'-k'); % Plot of the stationary component.
|
||||
%$ hold on
|
||||
%$ plot(ts2.data,'--r'); % Plot of the filtered y.
|
||||
%$ hold off
|
||||
%$ axis tight
|
||||
%$ id = get(gca,'XTick');
|
||||
%$ set(gca,'XTickLabel',strings(ts1.dates(id)));
|
||||
%$ legend({'Nonstationary component of y', 'Estimated trend of y'})
|
||||
%$ print('-depsc2','../doc/dynare.plots/HPTrend.eps')
|
||||
%$ system('convert -density 300 ../doc/dynare.plots/HPTrend.eps ../doc/dynare.plots/HPTrend.png');
|
||||
%$ system('convert -density 300 ../doc/dynare.plots/HPTrend.eps ../doc/dynare.plots/HPTrend.pdf');
|
||||
%$ system('convert -density 300 ../doc/dynare.plots/HPTrend.eps ../doc/dynare.plots/HPTrend.jpg');
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,107 +0,0 @@
|
|||
function ts = insert(ts,us,id) % --*-- Unitary tests --*--
|
||||
|
||||
% Add a variable in a dseries object.
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{ts} =} insert (@var{ts}, @var{us}, @var{id})
|
||||
%! @anchor{dseries/insert}
|
||||
%! @sp 1
|
||||
%! Insert method for the dseries class. Insert new variables (@var{us}) in a dseries object (@var{ts}) at
|
||||
%! positions @var{id}.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item ts
|
||||
%! Object instantiated by @ref{dseries}.
|
||||
%! @item us
|
||||
%! Object instantiated by @ref{dseries}.
|
||||
%! @item id
|
||||
%! vector of integers.
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item ts
|
||||
%! Object instantiated by @ref{dseries}, without variable (@var{a}).
|
||||
%! @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/>.
|
||||
|
||||
[n,message] = common_strings_in_cell_arrays(ts.name,us.name);
|
||||
|
||||
if n
|
||||
error(['dseries::insert: Variable(s) ' message ' already exist in ''' inputname(1) '''!'])
|
||||
end
|
||||
|
||||
if ~isequal(frequency(ts),frequency(us))
|
||||
error(['dseries::insert: ''' inputname(1) ''' and ''' inputname(2) ''' dseries objects must have common frequencies!'])
|
||||
end
|
||||
|
||||
[ts,us] = align(ts, us);
|
||||
|
||||
n = length(id);
|
||||
|
||||
if n>1
|
||||
[id, jd] = sort(id);
|
||||
us.data = us.data(:,jd);
|
||||
us.name = us.name(jd);
|
||||
us.tex = us.tex(jd);
|
||||
end
|
||||
|
||||
for i=1:n
|
||||
ts.data = insert_column_vector_in_a_matrix(ts.data,us.data(:,i),id(i));
|
||||
ts.name = insert_object_in_a_one_dimensional_cell_array(ts.name,us.name{i},id(i));
|
||||
ts.tex = insert_object_in_a_one_dimensional_cell_array(ts.tex,us.tex{i},id(i));
|
||||
id = id+1;
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3); B = rand(5,2);
|
||||
%$
|
||||
%$ % Define names.
|
||||
%$ A_name = {'A1'; 'A2';'A3'};
|
||||
%$ B_name = {'B1'; 'B2'};
|
||||
%$
|
||||
%$ % Define initial dates.
|
||||
%$ A_init = '1950Q1';
|
||||
%$ B_init = '1950Q3';
|
||||
%$
|
||||
%$ % Instantiate two dseries objects.
|
||||
%$ ts1 = dseries(A, A_init, A_name,[]);
|
||||
%$ ts2 = dseries(B, B_init, B_name,[]);
|
||||
%$
|
||||
%$ try
|
||||
%$ ts1 = insert(ts1,ts2,[1,2]);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts1.vobs,{'B1';'A1';'B2';'A3'});
|
||||
%$ t(3) = dassert(ts1.nobs,10);
|
||||
%$ eB = [NaN(2,2); B; NaN(3,2)];
|
||||
%$ t(4) = dassert(ts1.data,[eB(:,1), A(:,1), eB(:,2), A(:,2:3)], 1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,40 +0,0 @@
|
|||
function b = isempty(A)
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{b} =} isempty (@var{A})
|
||||
%! @anchor{@dseries/isempty}
|
||||
%! @sp 1
|
||||
%! Overloads the isempty function for the Dynare time series class (@ref{dseries}).
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item 1
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item b
|
||||
%! Scalar integer (0 or 1).
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2011-2012 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/>.
|
||||
|
||||
b = isempty(A.data);
|
|
@ -1,70 +0,0 @@
|
|||
function C = isequal(A, B, tol)
|
||||
|
||||
% Overloads the isequal Matlab/Octave's function.
|
||||
%
|
||||
% INPUTS
|
||||
% o A dseries object (T periods, N variables).
|
||||
% o B dseries object (T periods, N variables).
|
||||
% o tol tolerance parameter.
|
||||
%
|
||||
% OUTPUTS
|
||||
% o C Integer scalar equal to zero or one.
|
||||
|
||||
% 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 nargin~=2
|
||||
error('dseries::isequal: I need exactly two input arguments!')
|
||||
end
|
||||
|
||||
if ~isdseries(B)
|
||||
error('dseries::isequal: Both input arguments must be dseries objects!')
|
||||
end
|
||||
|
||||
if ~isequal(nobs(A), nobs(B))
|
||||
C = 0;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(vobs(A), vobs(B))
|
||||
C = 0;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(frequency(A),frequency(B))
|
||||
C = 0;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(A.dates,B.dates)
|
||||
C = 0;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(A.name,B.name)
|
||||
warning('dseries::isequal: Both input arguments do not have the same variables!')
|
||||
end
|
||||
|
||||
if ~isequal(A.tex,B.tex)
|
||||
warning('dseries::isequal: Both input arguments do not have the same tex names!')
|
||||
end
|
||||
|
||||
if nargin<3
|
||||
C = isequal(A.data, B.data);
|
||||
else
|
||||
C = ~(max(abs(A.data(:)-B.data(:)))>tol);
|
||||
end
|
|
@ -1,85 +0,0 @@
|
|||
function us = lag(ts,p) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{us} =} lag (@var{ts})
|
||||
%! @anchor{lag}
|
||||
%! @sp 1
|
||||
%! Computes lagged time series.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item ts
|
||||
%! Dynare time series object, instantiated by @ref{dseries}
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item us
|
||||
%! Dynare time series object with transformed data field.
|
||||
%! @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/>.
|
||||
|
||||
% Set default number of lags
|
||||
if nargin<2
|
||||
p = 1;
|
||||
end
|
||||
|
||||
if p<=0
|
||||
error('dseries::lag: Second input argument must be strictly positive! Use lead method instead.')
|
||||
end
|
||||
|
||||
% Copy of ts dseries object
|
||||
us = ts;
|
||||
|
||||
% Update data member
|
||||
us.data = [NaN(p, vobs(ts)); ts.data(1:end-p,:)];
|
||||
|
||||
for i=1:vobs(ts)
|
||||
us.name(i) = {[ 'lag(' ts.name{i} ',' int2str(p) ')']};
|
||||
us.tex(i) = {[ ts.tex{i} '_{-' int2str(p) '}']};
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = transpose(0:1:50);
|
||||
%$ ts = dseries(data,'1950Q1');
|
||||
%$ a = ts.lag;
|
||||
%$ b = ts.lag.lag;
|
||||
%$ c = lag(ts,2);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = [NaN(1,ts.vobs); transpose(0:1:49)];
|
||||
%$ t(2) = dassert(a.data,DATA,1e-15);
|
||||
%$ DATA = [NaN(2,ts.vobs); transpose(0:1:48)];
|
||||
%$ t(3) = dassert(b.data,DATA,1e-15);
|
||||
%$ t(4) = dassert(b.data,c.data,1e-15);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,20 +0,0 @@
|
|||
function l = lastdate(o)
|
||||
|
||||
% Copyright (C) 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/>.
|
||||
|
||||
l = o.dates(end);
|
|
@ -1,85 +0,0 @@
|
|||
function us = lead(ts,p) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{us} =} lead (@var{ts})
|
||||
%! @anchor{lag}
|
||||
%! @sp 1
|
||||
%! Computes leaded time series.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item ts
|
||||
%! Dynare time series object, instantiated by @ref{dseries}
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item us
|
||||
%! Dynare time series object with transformed data field.
|
||||
%! @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/>.
|
||||
|
||||
% Set default number of leads
|
||||
if nargin<2
|
||||
p = 1;
|
||||
end
|
||||
|
||||
if p<=0
|
||||
error('dseries::lead: Second input argument must be strictly positive! Use lag method instead.')
|
||||
end
|
||||
|
||||
% Copy of ts dseries object
|
||||
us = ts;
|
||||
|
||||
% Update data member
|
||||
us.data = [ ts.data(p+1:end,:); NaN(p, vobs(ts));];
|
||||
|
||||
for i=1:vobs(ts)
|
||||
us.name(i) = {[ 'lead(' ts.name{i} ',' int2str(p) ')']};
|
||||
us.tex(i) = {[ ts.tex{i} '_{+' int2str(p) '}']};
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = transpose(0:1:50);
|
||||
%$ ts = dseries(data,'1950Q1');
|
||||
%$ a = ts.lead;
|
||||
%$ b = ts.lead.lead;
|
||||
%$ c = lead(ts,2);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = [transpose(1:50); NaN(1,ts.vobs)];
|
||||
%$ t(2) = dassert(a.data,DATA,1e-15);
|
||||
%$ DATA = [transpose(2:50); NaN(2,ts.vobs)];
|
||||
%$ t(3) = dassert(b.data,DATA,1e-15);
|
||||
%$ t(4) = dassert(b.data,c.data,1e-15);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,55 +0,0 @@
|
|||
function ts = log(ts)
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{ts} =} log(@var{ts})
|
||||
%! @anchor{log}
|
||||
%! Apply the logarithm function to a Dynare time series object.
|
||||
%!
|
||||
%! @strong{Inputs}
|
||||
%! @table @var
|
||||
%! @item ts
|
||||
%! Dynare time series object, instantiated by @ref{dseries}
|
||||
%! @end table
|
||||
%!
|
||||
%! @strong{Outputs}
|
||||
%! @table @var
|
||||
%! @item ts
|
||||
%! Dynare time series object with transformed data field.
|
||||
%! @end table
|
||||
%!
|
||||
%! @strong{This function is called by:}
|
||||
%! None.
|
||||
%!
|
||||
%! @strong{This function calls:}
|
||||
%! None.
|
||||
%!
|
||||
%! @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 any(ts.data<eps)
|
||||
error('dseries::log: Input argument has to be strictly positive!')
|
||||
end
|
||||
|
||||
for i=1:vobs(ts)
|
||||
ts.name(i) = {['log(' ts.name{i} ')']};
|
||||
ts.tex(i) = {['\log(' ts.tex{i} ')']};
|
||||
end
|
||||
|
||||
ts.data = log(ts.data);
|
|
@ -1,146 +0,0 @@
|
|||
function A = merge(B,C) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{A} =} merge (@var{B},@var{C})
|
||||
%! @anchor{@dseries/plus}
|
||||
%! @sp 1
|
||||
%! Overloads the merge 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}.
|
||||
%! @item C
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item A
|
||||
%! Dynare time series object.
|
||||
%! @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(C)
|
||||
error('dseries::merge: Both inputs must be dseries objects!')
|
||||
end
|
||||
|
||||
if ~isequal(frequency(B),frequency(C))
|
||||
error(['dseries::merge: Cannot merge ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
|
||||
end
|
||||
|
||||
A = dseries();
|
||||
[A.name, IBC, junk] = unique([B.name; C.name], 'last');
|
||||
tex = [B.tex; C.tex];
|
||||
A.tex = tex(IBC);
|
||||
|
||||
if nobs(B) == 0
|
||||
A = C;
|
||||
elseif nobs(C) == 0
|
||||
A = B;
|
||||
elseif firstdate(B) >= firstdate(C)
|
||||
diff = firstdate(B) - firstdate(C);
|
||||
A_nobs = max(nobs(B) + diff, nobs(C));
|
||||
A.data = NaN(A_nobs, vobs(A));
|
||||
Z1 = [NaN(diff, vobs(B));B.data];
|
||||
if nobs(A) > nobs(B) + diff
|
||||
Z1 = [Z1; NaN(nobs(A)-(nobs(B) + diff), vobs(B))];
|
||||
end;
|
||||
Z2 = C.data;
|
||||
if nobs(A) > nobs(C)
|
||||
Z2 = [Z2; NaN(nobs(A) - nobs(C), vobs(C))];
|
||||
end;
|
||||
Z = [Z1 Z2];
|
||||
A.data = Z(:,IBC);
|
||||
A_init = firstdate(C);
|
||||
else
|
||||
diff = firstdate(C) - firstdate(B);
|
||||
A_nobs = max(nobs(C) + diff, nobs(B));
|
||||
A.data = NaN(A_nobs, vobs(A));
|
||||
Z1 = [NaN(diff, vobs(C)); C.data];
|
||||
if nobs(A) > nobs(C) + diff
|
||||
Z1 = [Z1; NaN(nobs(A)-(nobs(C) + diff), vobs(C))];
|
||||
end
|
||||
Z2 = B.data;
|
||||
if nobs(A) > nobs(B)
|
||||
Z2 = [Z2; NaN(nobs(A) - nobs(B), vobs(B))];
|
||||
end;
|
||||
Z = [Z2 Z1];
|
||||
A.data = Z(:,IBC);
|
||||
A_init = B.init;
|
||||
end
|
||||
|
||||
A.dates = A_init:A_init+(nobs(A)-1);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = randn(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'}; B_name = {'A1'};
|
||||
%$
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$ ts3 = merge(ts1,ts2);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts3.vobs,2);
|
||||
%$ t(3) = dassert(ts3.nobs,10);
|
||||
%$ t(4) = dassert(ts3.data,[B, A(:,2)],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = randn(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'}; B_name = {'B1'};
|
||||
%$
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$ ts3 = merge(ts1,ts2);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts3.vobs,3);
|
||||
%$ t(3) = dassert(ts3.nobs,10);
|
||||
%$ t(4) = dassert(ts3.data,[A, B],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,196 +0,0 @@
|
|||
function A = minus(B,C) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{A} =} minus (@var{B},@var{C})
|
||||
%! @anchor{@dseries/minus}
|
||||
%! @sp 1
|
||||
%! Overloads the minus 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}.
|
||||
%! @item C
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item A
|
||||
%! Dynare time series object.
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2012-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 isnumeric(B) && (isscalar(B) || isvector(B))
|
||||
if ~isdseries(C)
|
||||
error('dseries::minus: Second input argument must be a dseries object!')
|
||||
end
|
||||
A = C;
|
||||
A.data = bsxfun(@minus,B,C.data);
|
||||
return;
|
||||
end
|
||||
|
||||
if isnumeric(C) && (isscalar(C) || isvector(C))
|
||||
if ~isdseries(B)
|
||||
error('dseries::minus: First input argument must be a dseries object!')
|
||||
end
|
||||
A = B;
|
||||
A.data = bsxfun(@minus,B.data,C);
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B),1) || isequal(vobs(C),1))
|
||||
error(['dseries::minus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
|
||||
else
|
||||
if vobs(B)>vobs(C)
|
||||
idB = 1:vobs(B);
|
||||
idC = ones(1:vobs(B));
|
||||
elseif vobs(B)<vobs(C)
|
||||
idB = ones(1,vobs(C));
|
||||
idC = 1:vobs(C);
|
||||
else
|
||||
idB = 1:vobs(B);
|
||||
idC = 1:vobs(C);
|
||||
end
|
||||
end
|
||||
|
||||
if ~isequal(frequency(B),frequency(C))
|
||||
error(['dseries::plus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
|
||||
end
|
||||
|
||||
if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
|
||||
[B, C] = align(B, C);
|
||||
end
|
||||
|
||||
if isempty(B)
|
||||
A = -C;
|
||||
return
|
||||
end
|
||||
|
||||
if isempty(C)
|
||||
A = B;
|
||||
return
|
||||
end
|
||||
|
||||
A = dseries();
|
||||
|
||||
A.dates = B.dates;
|
||||
A_vobs = max(vobs(B), vobs(C));
|
||||
A.name = cell(A_vobs,1);
|
||||
A.tex = cell(A_vobs,1);
|
||||
for i=1:A_vobs
|
||||
A.name(i) = {['minus(' B.name{idB(i)} ';' C.name{idC(i)} ')']};
|
||||
A.tex(i) = {['(' B.tex{idB(i)} '-' C.tex{idC(i)} ')']};
|
||||
end
|
||||
A.data = bsxfun(@minus,B.data,C.data);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = randn(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'}; B_name = {'B1'};
|
||||
%$
|
||||
%$ t = zeros(5,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$ ts3 = ts1-ts2;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts3.vobs,2);
|
||||
%$ t(3) = dassert(ts3.nobs,10);
|
||||
%$ t(4) = dassert(ts3.data,[A(:,1)-B, A(:,2)-B],1e-15);
|
||||
%$ t(5) = dassert(ts3.name,{'minus(A1;B1)';'minus(A2;B1)'});
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:3
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = randn(5,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'}; B_name = {'B1'};
|
||||
%$
|
||||
%$ t = zeros(5,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$ ts3 = ts1-ts2;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts3.vobs,2);
|
||||
%$ t(3) = dassert(ts3.nobs,10);
|
||||
%$ t(4) = dassert(ts3.data,[A(1:5,1)-B(1:5), A(1:5,2)-B(1:5) ; NaN(5,2)],1e-15);
|
||||
%$ t(5) = dassert(ts3.name,{'minus(A1;B1)';'minus(A2;B1)'});
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ ts1 = dseries(ones(3,1));
|
||||
%$ ts2 = ts1-1;
|
||||
%$ ts3 = 2-ts1;
|
||||
%$ t(1) = isequal(ts2.data, zeros(3,1));
|
||||
%$ t(2) = isequal(ts3.data, ts1.data);
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ ts1 = dseries(ones(3,2));
|
||||
%$ ts2 = ts1-1;
|
||||
%$ ts3 = 2-ts1;
|
||||
%$ t(1) = isequal(ts2.data, zeros(3,2));
|
||||
%$ t(2) = isequal(ts3.data, ts1.data);
|
||||
%$ T = all(t);
|
||||
%@eof:5
|
||||
|
||||
%@test:6
|
||||
%$ ts1 = dseries(ones(3,2));
|
||||
%$ ts2 = ts1-ones(3,1);
|
||||
%$ ts3 = 2*ones(3,1)-ts1;
|
||||
%$ t(1) = isequal(ts2.data, zeros(3,2));
|
||||
%$ t(2) = isequal(ts3.data, ts1.data);
|
||||
%$ T = all(t);
|
||||
%@eof:6
|
||||
|
||||
%@test:7
|
||||
%$ ts1 = dseries(ones(3,2));
|
||||
%$ ts2 = ts1-ones(1,2);
|
||||
%$ ts3 = 2*ones(1,2)-ts1;
|
||||
%$ t(1) = isequal(ts2.data, zeros(3,2));
|
||||
%$ t(2) = isequal(ts3.data, ts1.data);
|
||||
%$ T = all(t);
|
||||
%@eof:7
|
|
@ -1,168 +0,0 @@
|
|||
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 isnumeric(B) && isvector(B) && length(B)>1
|
||||
if ~isdseries(C)
|
||||
error('dseries::mpower: Second input argument must be a dseries object!')
|
||||
end
|
||||
A = C;
|
||||
A.data = bsxfun(@power,C.data,B);
|
||||
return;
|
||||
end
|
||||
|
||||
if isnumeric(C) && isvector(C) && length(C)>1
|
||||
if ~isdseries(B)
|
||||
error('dseries::mpower: First input argument must be a dseries object!')
|
||||
end
|
||||
A = B;
|
||||
A.data = bsxfun(@power,B.data,C);
|
||||
return
|
||||
end
|
||||
|
||||
if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C)
|
||||
A = dseries();
|
||||
A.dates = B.dates;
|
||||
A.data = B.data.^C;
|
||||
A.name = cell(vobs(A),1);
|
||||
A.tex = cell(vobs(A),1);
|
||||
for i=1:vobs(A)
|
||||
A.name(i) = {['power(' B.name{i} ';' num2str(C) ')']};
|
||||
A.tex(i) = {[B.tex{i} '^' num2str(C) ]};
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if isdseries(B) && isdseries(C)
|
||||
if isequal(nobs(B),nobs(C)) && isequal(vobs(B), vobs(C)) && isequal(frequency(B),frequency(C))
|
||||
A = dseries();
|
||||
A.data = B.data.^C.data;
|
||||
A.dates = B.dates;
|
||||
A.name = cell(vobs(A),1);
|
||||
A.tex = cell(vobs(A),1);
|
||||
for i=1:vobs(A)
|
||||
A.name(i) = {['power(' B.name{i} ';' C.name{i} ')']};
|
||||
A.tex(i) = {[B.tex{i} '^{' C.tex{i} '}']};
|
||||
end
|
||||
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) = dassert(ts3.vobs,2);
|
||||
%$ t(3) = dassert(ts3.nobs,10);
|
||||
%$ t(4) = dassert(ts3.data,A.^B,1e-15);
|
||||
%$ t(5) = dassert(ts3.name,{'power(A1;B1)';'power(A2;B2)'});
|
||||
%$ t(6) = dassert(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) = dassert(ts3.vobs,2);
|
||||
%$ t(3) = dassert(ts3.nobs,10);
|
||||
%$ t(4) = dassert(ts3.data,A.^2,1e-15);
|
||||
%$ t(5) = dassert(ts3.name,{'power(A1;2)';'power(A2;2)'});
|
||||
%$ t(6) = dassert(ts3.tex,{'A1^2';'A2^2'});
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ % Define a dseries object
|
||||
%$ ts1=dseries([1 1;2 2;3 3], '1999y', {'MyVar1','MyVar2'});
|
||||
%$
|
||||
%$ % Use the power
|
||||
%$ try
|
||||
%$ ts2 = ts1^transpose(1:3);
|
||||
%$ t = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,3);
|
||||
%$ t(4) = dassert(ts2.data,bsxfun(@power,ts1.data,transpose(1:3)),1e-15);
|
||||
%$ t(5) = dassert(ts2.name,{'MyVar1';'MyVar2'});
|
||||
%$ t(6) = dassert(ts2.tex,{'MyVar1';'MyVar2'});
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
|
@ -1,174 +0,0 @@
|
|||
function A = mrdivide(B,C) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{A} =} mrdivide (@var{B},@var{C})
|
||||
%! @anchor{@dseries/mrdivide}
|
||||
%! @sp 1
|
||||
%! Overloads the mrdivide 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}.
|
||||
%! @item C
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item A
|
||||
%! Dynare time series object.
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2012-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 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)
|
||||
% Element by element divisions of two dseries object
|
||||
if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B),1) || isequal(vobs(C),1))
|
||||
error(['dseries::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
|
||||
else
|
||||
if vobs(B)>vobs(C)
|
||||
idB = 1:vobs(B);
|
||||
idC = ones(1:vobs(B));
|
||||
elseif vobs(B)<vobs(C)
|
||||
idB = ones(1,vobs(C));
|
||||
idC = 1:vobs(C);
|
||||
else
|
||||
idB = 1:vobs(B);
|
||||
idC = 1:vobs(C);
|
||||
end
|
||||
end
|
||||
if ~isequal(frequency(B),frequency(C))
|
||||
error(['dseries::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
|
||||
end
|
||||
if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
|
||||
[B, C] = align(B, C);
|
||||
end
|
||||
A = dseries();
|
||||
A.dates = B.dates;
|
||||
A_vobs = max(vobs(B),vobs(C));
|
||||
A.name = cell(A_vobs,1);
|
||||
A.tex = cell(A_vobs,1);
|
||||
for i=1:A_vobs
|
||||
A.name(i) = {['divide(' B.name{idB(i)} ';' C.name{idC(i)} ')']};
|
||||
A.tex(i) = {['(' B.tex{idB(i)} '/' C.tex{idC(i)} ')']};
|
||||
end
|
||||
A.data = bsxfun(@rdivide,B.data,C.data);
|
||||
else
|
||||
error()
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = randn(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'}; B_name = {'B1'};
|
||||
%$
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$ ts3 = ts1/ts2;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts3.vobs,2);
|
||||
%$ t(3) = dassert(ts3.nobs,10);
|
||||
%$ t(4) = dassert(ts3.data,[A(:,1)./B, A(:,2)./B],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = pi;
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = ts1/B;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.data,A/B,1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = pi;
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = B/ts1;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.data,B./A,1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
|
@ -1,197 +0,0 @@
|
|||
function A = mtimes(B,C) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{A} =} mtimes (@var{B},@var{C})
|
||||
%! @anchor{@dseries/mtimes}
|
||||
%! @sp 1
|
||||
%! Overloads the mtimes 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}.
|
||||
%! @item C
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item A
|
||||
%! Dynare time series object.
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2012-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 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)
|
||||
% Element by element multiplication of two dseries object
|
||||
if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B),1) || isequal(vobs(C),1))
|
||||
error(['dseries::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
|
||||
else
|
||||
if vobs(B)>vobs(C)
|
||||
idB = 1:vobs(B);
|
||||
idC = ones(1:vobs(B));
|
||||
elseif vobs(B)<vobs(C)
|
||||
idB = ones(1,vobs(C));
|
||||
idC = 1:vobs(C);
|
||||
else
|
||||
idB = 1:vobs(B);
|
||||
idC = 1:vobs(C);
|
||||
end
|
||||
end
|
||||
if ~isequal(frequency(B),frequency(C))
|
||||
error(['dseries::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
|
||||
end
|
||||
if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
|
||||
[B, C] = align(B, C);
|
||||
end
|
||||
A = dseries();
|
||||
A.dates = B.dates;
|
||||
A_vobs = max(vobs(B),vobs(C));
|
||||
A.name = cell(A_vobs,1);
|
||||
A.tex = cell(A_vobs,1);
|
||||
for i=1:A_vobs
|
||||
A.name(i) = {['multiply(' B.name{idB(i)} ';' C.name{idC(i)} ')']};
|
||||
A.tex(i) = {['(' B.tex{idB(i)} '*' C.tex{idC(i)} ')']};
|
||||
end
|
||||
A.data = bsxfun(@times,B.data,C.data);
|
||||
else
|
||||
error()
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = randn(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'}; B_name = {'B1'};
|
||||
%$
|
||||
%$
|
||||
%$ % 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) = dassert(ts3.vobs,2);
|
||||
%$ t(3) = dassert(ts3.nobs,10);
|
||||
%$ t(4) = dassert(ts3.data,[A(:,1).*B, A(:,2).*B],1e-15);
|
||||
%$ t(5) = dassert(ts3.name,{'multiply(A1;B1)';'multiply(A2;B1)'});
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = pi;
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = ts1*B;
|
||||
%$ t = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.data,A*B,1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = pi;
|
||||
%$
|
||||
%$ % 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) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.data,A*B,1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@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) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.data,bsxfun(@times,A,B),1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
|
@ -1,100 +0,0 @@
|
|||
function C = ne(A,B) % --*-- Unitary tests --*--
|
||||
|
||||
% Overloads ne (~=) operator.
|
||||
%
|
||||
% INPUTS
|
||||
% o A dseries object (T periods, N variables).
|
||||
% o B dseries object (T periods, N variables).
|
||||
%
|
||||
% OUTPUTS
|
||||
% o C T*N matrix of zeros and ones. Element C(t,n) is nonzero iff observation t of variable n in A and B are different.
|
||||
%
|
||||
% REMARKS
|
||||
% If the number of variables, the number of observations or the frequencies are different in A and B, the function returns one.
|
||||
|
||||
% 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 nargin~=2
|
||||
error('dseries::ne: I need exactly two input arguments!')
|
||||
end
|
||||
|
||||
if ~(isdseries(A) && isdseries(B))
|
||||
error('dseries::ne: Both input arguments must be dseries objects!')
|
||||
end
|
||||
|
||||
if ~isequal(nobs(A), nobs(B))
|
||||
warning('dseries::ne: Both input arguments should have the same number of observations!')
|
||||
C = 1;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(vobs(A), vobs(B))
|
||||
warning('dseries::ne: Both input arguments should have the same number of observations!')
|
||||
C = 1;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(frequency(A),frequency(B))
|
||||
warning('dseries::ne: Both input arguments should have the same frequencies!')
|
||||
C = 1;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(firstdate(A),firstdate(B))
|
||||
warning('dseries::ne: Both input arguments should have the same initial period!')
|
||||
C = 1;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(A.name,B.name)
|
||||
warning('dseries::ne: Both input arguments do not have the same variables!')
|
||||
end
|
||||
|
||||
if ~isequal(A.tex,B.tex)
|
||||
warning('dseries::ne: Both input arguments do not have the same tex names!')
|
||||
end
|
||||
|
||||
C = ne(A.data, B.data);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3);
|
||||
%$ B = A;
|
||||
%$ B(:,3) = rand(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'A3'}; B_name = A_name;
|
||||
%$
|
||||
%$ t = zeros(2,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$ ts2 = ts1;
|
||||
%$ a = eq(ts1,ts2);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(a,logical([ones(10,2), ones(10,1)]));
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,22 +0,0 @@
|
|||
function s = nobs(ts)
|
||||
|
||||
% Returns the number of observations in a @dseries object.
|
||||
|
||||
% Copyright (C) 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/>.
|
||||
|
||||
s = rows(ts.data);
|
|
@ -1,20 +0,0 @@
|
|||
function n = numel(obj, varargin)
|
||||
|
||||
% Copyright (C) 2012-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/>.
|
||||
|
||||
n = 1;
|
|
@ -1,84 +0,0 @@
|
|||
function h = plot(ts, varargin)
|
||||
|
||||
% Overloads Matlab/Octave's plot function for dseries objects.
|
||||
|
||||
% 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/>.
|
||||
|
||||
% Get the number of dseries objects
|
||||
if isequal(nargin,1)
|
||||
ndseries = 1;
|
||||
nvariables = vobs(ts);
|
||||
nobservations = nobs(ts);
|
||||
else
|
||||
if isdseries(varargin{1})
|
||||
ndseries = 2;
|
||||
nvariables = vobs(ts);
|
||||
nobservations = nobs(ts);
|
||||
if nargin>2 && any(cellfun(@isdseries,varargin(2:end)))
|
||||
error('dseries::plot: You cannot pass more two dseries objects!')
|
||||
end
|
||||
if ~isequal(nvariables, vobs(varargin{1}))
|
||||
error('dseries::plot: The two dseries objects must have the same number of variables!')
|
||||
end
|
||||
if ~isequal(nobservations, nobs(varargin{1}))
|
||||
error('dseries::plot: The two dseries objects must have the same number of observations!')
|
||||
end
|
||||
else
|
||||
ndseries = 1;
|
||||
nvariables = vobs(ts);
|
||||
nobservations = nobs(ts);
|
||||
end
|
||||
end
|
||||
|
||||
switch ndseries
|
||||
case 1
|
||||
if isequal(nvariables,1)
|
||||
hh = plot(ts.data,varargin{:});
|
||||
else
|
||||
if length(varargin)
|
||||
message = sprintf('dseries::plot: dseries object %s has %d>1 variables but you passed additional arguments to the plot function.\n These additional arguments won''t ne interpreted. Use the Matlab/Octave set command and the plot\n handle instead if you wish to modify the properties of the plotted time series.',inputname(1),nvariables);
|
||||
warning(message)
|
||||
end
|
||||
hh = plot(ts.data);
|
||||
end
|
||||
axis tight;
|
||||
id = get(gca,'XTick');
|
||||
if isequal(id(1),0)
|
||||
dates = strings([ts.dates(1)-1,ts.dates(id(2:end))]);
|
||||
else
|
||||
dates = strings(ts.dates(id));
|
||||
end
|
||||
set(gca,'XTickLabel',dates);
|
||||
case 2
|
||||
[ts0, ts1] = align(ts, varargin{1});
|
||||
if isequal(nvariables,1)
|
||||
hh = plot(ts0.data, ts1.data, varargin{2:end});
|
||||
else
|
||||
if length(varargin)>1
|
||||
message = sprintf('dseries::plot: dseries objects %s and %s have %d>1 variables but you passed additional arguments to the plot function.\n These additional arguments won''t ne interpreted. Use the Matlab/Octave set command and the plot\n handle instead if you wish to modify the properties of the plotted time series.',inputname(1),inputname(2),nvariables);
|
||||
warning(message)
|
||||
end
|
||||
hh = plot(ts0.data, ts1.data);
|
||||
end
|
||||
otherwise
|
||||
error('dseries::plot: This is a bug! Please report the bug to the authors of Dynare.')
|
||||
end
|
||||
|
||||
if nargout
|
||||
h = hh;
|
||||
end
|
|
@ -1,325 +0,0 @@
|
|||
function A = plus(B,C) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{A} =} plus (@var{B},@var{C})
|
||||
%! @anchor{@dseries/plus}
|
||||
%! @sp 1
|
||||
%! Overloads the plus 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}.
|
||||
%! @item C
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item A
|
||||
%! Dynare time series object.
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2011-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 isnumeric(B) && (isscalar(B) || isvector(B))
|
||||
if ~isdseries(C)
|
||||
error('dseries::plus: Second input argument must be a dseries object!')
|
||||
end
|
||||
A = C;
|
||||
A.data = bsxfun(@plus,C.data,B);
|
||||
return;
|
||||
end
|
||||
|
||||
if isnumeric(C) && (isscalar(C) || isvector(C))
|
||||
if ~isdseries(B)
|
||||
error('dseries::plus: First input argument must be a dseries object!')
|
||||
end
|
||||
A = B;
|
||||
A.data = bsxfun(@plus,B.data,C);
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B), 1) || isequal(vobs(C), 1))
|
||||
error(['dseries::plus: Cannot add ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
|
||||
else
|
||||
if vobs(B)>vobs(C)
|
||||
idB = 1:vobs(B);
|
||||
idC = ones(1,vobs(B));
|
||||
elseif vobs(B)<vobs(C)
|
||||
idB = ones(1,vobs(C));
|
||||
idC = 1:vobs(C);
|
||||
else
|
||||
idB = 1:vobs(B);
|
||||
idC = 1:vobs(C);
|
||||
end
|
||||
end
|
||||
|
||||
if ~isequal(frequency(B),frequency(C))
|
||||
error(['dseries::plus: Cannot add ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
|
||||
end
|
||||
|
||||
if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
|
||||
[B, C] = align(B, C);
|
||||
end
|
||||
|
||||
if isempty(B)
|
||||
A = C;
|
||||
return
|
||||
end
|
||||
|
||||
if isempty(C)
|
||||
A = B;
|
||||
return
|
||||
end
|
||||
|
||||
A = dseries();
|
||||
|
||||
A.data = bsxfun(@plus,B.data,C.data);
|
||||
A.dates = B.dates;
|
||||
|
||||
A_vobs = max(vobs(B), vobs(C));
|
||||
A.name = cell(A_vobs,1);
|
||||
A.tex = cell(A_vobs,1);
|
||||
for i=1:A_vobs
|
||||
A.name(i) = {['plus(' B.name{idB(i)} ';' C.name{idC(i)} ')']};
|
||||
A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']};
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = randn(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'}; B_name = {'B1'};
|
||||
%$
|
||||
%$ t = zeros(5,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$ ts3 = ts1+ts2;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts3.vobs,2);
|
||||
%$ t(3) = dassert(ts3.nobs,10);
|
||||
%$ t(4) = dassert(ts3.data,[A(:,1)+B, A(:,2)+B],1e-15);
|
||||
%$ t(5) = dassert(ts3.name,{'plus(A1;B1)';'plus(A2;B1)'});
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = randn(10,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'}; B_name = {'B1'};
|
||||
%$
|
||||
%$ t = zeros(5,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$ ts3 = ts1+ts2;
|
||||
%$ ts4 = ts3+ts1;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts4.vobs,2);
|
||||
%$ t(3) = dassert(ts4.nobs,10);
|
||||
%$ t(4) = dassert(ts4.data,[A(:,1)+B, A(:,2)+B]+A,1e-15);
|
||||
%$ t(5) = dassert(ts4.name,{'plus(plus(A1;B1);A1)';'plus(plus(A2;B1);A2)'});
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
|
||||
%@test:3
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2); B = randn(5,1);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'}; B_name = {'B1'};
|
||||
%$
|
||||
%$ t = zeros(5,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$ ts3 = ts1+ts2;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts3.vobs,2);
|
||||
%$ t(3) = dassert(ts3.nobs,10);
|
||||
%$ t(4) = dassert(ts3.data,[A(1:5,1)+B(1:5), A(1:5,2)+B(1:5) ; NaN(5,2)],1e-15);
|
||||
%$ t(5) = dassert(ts3.name,{'plus(A1;B1)';'plus(A2;B1)'});
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ t = zeros(7,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ ts = dseries(transpose(1:5),'1950q1',{'Output'}, {'Y_t'});
|
||||
%$ us = dseries(transpose(1:5),'1949q4',{'Consumption'}, {'C_t'});
|
||||
%$ vs = ts+us;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(us.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(us.init.time,[1949, 4]);
|
||||
%$ t(6) = dassert(vs.init.time,[1949, 4]);
|
||||
%$ t(7) = dassert(vs.nobs,6);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ t = zeros(7,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ ts = dseries(transpose(1:5),'1950q1',{'Output'}, {'Y_t'});
|
||||
%$ us = dseries(transpose(1:7),'1950q1',{'Consumption'}, {'C_t'});
|
||||
%$ vs = ts+us;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(us.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(us.init.time,[1950, 1]);
|
||||
%$ t(6) = dassert(vs.init.time,[1950, 1]);
|
||||
%$ t(7) = dassert(vs.nobs,7);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@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) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(us.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(us.init.time,[1950, 1]);
|
||||
%$ t(6) = dassert(vs.init.time,[1950, 1]);
|
||||
%$ t(7) = dassert(vs.nobs,5);
|
||||
%$ t(8) = dassert(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) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(us.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(us.init.time,[1950, 1]);
|
||||
%$ t(6) = dassert(vs.init.time,[1950, 1]);
|
||||
%$ t(7) = dassert(vs.nobs,5);
|
||||
%$ t(8) = dassert(vs.data,bsxfun(@plus,ts.data,[1, 2]));
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:7
|
||||
|
||||
%@test:8
|
||||
%$ ts1 = dseries(ones(3,1));
|
||||
%$ ts2 = ts1+1;
|
||||
%$ ts3 = 1+ts1;
|
||||
%$ t(1) = isequal(ts2.data, 2*ones(3,1));
|
||||
%$ t(2) = isequal(ts3.data, 2*ones(3,1));
|
||||
%$ T = all(t);
|
||||
%@eof:8
|
||||
|
||||
%@test:9
|
||||
%$ ts1 = dseries(ones(3,2));
|
||||
%$ ts2 = ts1+1;
|
||||
%$ ts3 = 1+ts1;
|
||||
%$ t(1) = isequal(ts2.data, 2*ones(3,2));
|
||||
%$ t(2) = isequal(ts3.data, 2*ones(3,2));
|
||||
%$ T = all(t);
|
||||
%@eof:9
|
||||
|
||||
%@test:10
|
||||
%$ ts1 = dseries(ones(3,2));
|
||||
%$ ts2 = ts1+ones(3,1);
|
||||
%$ ts3 = ones(3,1)+ts1;
|
||||
%$ t(1) = isequal(ts2.data, 2*ones(3,2));
|
||||
%$ t(2) = isequal(ts3.data, 2*ones(3,2));
|
||||
%$ T = all(t);
|
||||
%@eof:10
|
||||
|
||||
%@test:11
|
||||
%$ ts1 = dseries(ones(3,2));
|
||||
%$ ts2 = ts1+ones(1,2);
|
||||
%$ ts3 = ones(1,2)+ts1;
|
||||
%$ t(1) = isequal(ts2.data, 2*ones(3,2));
|
||||
%$ t(2) = isequal(ts3.data, 2*ones(3,2));
|
||||
%$ T = all(t);
|
||||
%@eof:11
|
|
@ -1,113 +0,0 @@
|
|||
function [ts,id] = pop(ts,a) % --*-- Unitary tests --*--
|
||||
|
||||
% Removes a variable from a dseries object.
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{ts} =} pop (@var{ts}, @var{a})
|
||||
%! @anchor{dseries/pop}
|
||||
%! @sp 1
|
||||
%! Pop method for the dseries class. Removes a variable from a dseries object.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item ts
|
||||
%! Object instantiated by @ref{dseries}.
|
||||
%! @item a
|
||||
%! String, name of the variable to be removed.
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item ts
|
||||
%! Object instantiated by @ref{dseries}, without variable (@var{a}).
|
||||
%! @item id
|
||||
%! Scalar integer, position of variable (@var{a}) in the original dseries object @var{ts}.
|
||||
%! @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 nargin<2
|
||||
% Removes the last variable
|
||||
id = vobs(ts);
|
||||
else
|
||||
id = find(strcmp(a,ts.name));
|
||||
end
|
||||
|
||||
if isempty(id)
|
||||
id = 0;
|
||||
return
|
||||
end
|
||||
|
||||
ts.data(:,id) = [];
|
||||
ts.name(id) = [];
|
||||
ts.tex(id) = [];
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'A3'};
|
||||
%$
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = pop(ts1,'A2');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.data,[A(:,1), A(:,3)],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'A3'};
|
||||
%$
|
||||
%$ t = zeros(2,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ [ts2,id] = pop(ts1,'A4');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(id,0);
|
||||
%$ t(2) = dassert(ts1,ts2);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,27 +0,0 @@
|
|||
function names = default_name(dim)
|
||||
|
||||
% 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/>.
|
||||
|
||||
|
||||
names = {};
|
||||
for i=1:dim
|
||||
names = vertcat(names, {['Variable_' int2str(i)]});
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
function us = qdiff(ts) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{us} =} qdiff (@var{ts})
|
||||
%! @anchor{qdiff}
|
||||
%! @sp 1
|
||||
%! Computes quaterly differences.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item ts
|
||||
%! Dynare time series object, instantiated by @ref{dseries}
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item us
|
||||
%! Dynare time series object with transformed data field.
|
||||
%! @end table
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2012-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/>.
|
||||
|
||||
us = ts;
|
||||
|
||||
switch frequency(ts)
|
||||
case 1
|
||||
error('dseries::qgrowth: I cannot compute quaterly differences from yearly data!')
|
||||
case 4
|
||||
us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:);
|
||||
us.data(1,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['qdiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta ' us.tex{i}]};
|
||||
end
|
||||
case 12
|
||||
us.data(4:end,:) = ts.data(4:end,:)-ts.data(1:end-3,:);
|
||||
us.data(1:3,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['qdiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta_3 ' us.tex{i}]};
|
||||
end
|
||||
case 52
|
||||
error('dseries::qgrowth: I do not know yet how to compute quaterly differences from weekly data!')
|
||||
otherwise
|
||||
error(['dseries::ygrowth: object ' inputname(1) ' has unknown frequency']);
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ t = zeros(2,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = transpose(0:1:50);
|
||||
%$ ts = dseries(data,'1950Q1');
|
||||
%$ ts = ts.qdiff;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = NaN(1,ts.vobs);
|
||||
%$ DATA = [DATA; ones(ts.nobs-1,ts.vobs)];
|
||||
%$ t(2) = dassert(ts.data,DATA,1e-15);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ t = zeros(2,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = transpose(0:1:80);
|
||||
%$ ts = dseries(data,'1950M1');
|
||||
%$ ts = ts.qdiff;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = NaN(3,ts.vobs);
|
||||
%$ DATA = [DATA; 3*ones(ts.nobs-3,ts.vobs)];
|
||||
%$ t(2) = dassert(ts.data,DATA,1e-15);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,107 +0,0 @@
|
|||
function us = qgrowth(ts) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{us} =} qgrowth (@var{ts})
|
||||
%! @anchor{qgrowth}
|
||||
%! @sp 1
|
||||
%! Computes quaterly growth rates.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item ts
|
||||
%! Dynare time series object, instantiated by @ref{dseries}
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item us
|
||||
%! Dynare time series object with transformed data field.
|
||||
%! @end table
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2012-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/>.
|
||||
|
||||
us = ts;
|
||||
|
||||
switch frequency(ts)
|
||||
case 1
|
||||
error('dseries::qgrowth: I cannot compute quaterly growth rates from yearly data!')
|
||||
case 4
|
||||
us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1;
|
||||
us.data(1,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['qgrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta ' us.tex{i}]};
|
||||
end
|
||||
case 12
|
||||
us.data(4:end,:) = ts.data(4:end,:)./ts.data(1:end-3,:) - 1;
|
||||
us.data(1:3,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['qgrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta_3 ' us.tex{i}]};
|
||||
end
|
||||
case 52
|
||||
error('dseries::qgrowth: I do not know yet how to compute quaterly growth rates from weekly data!')
|
||||
otherwise
|
||||
error(['dseries::ygrowth: object ' inputname(1) ' has unknown frequency']);
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ t = zeros(2,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = (1+.01).^transpose(0:1:50);
|
||||
%$ ts = dseries(data,'1950Q1');
|
||||
%$ ts = ts.qgrowth;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = NaN(1,ts.vobs);
|
||||
%$ DATA = [DATA; .01*ones(ts.nobs-1,ts.vobs)];
|
||||
%$ t(2) = dassert(ts.data,DATA,1e-15);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ t = zeros(2,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = (1+.01).^transpose(0:1:80);
|
||||
%$ ts = dseries(data,'1950M1');
|
||||
%$ ts = ts.qgrowth;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = NaN(3,ts.vobs);
|
||||
%$ DATA = [DATA; (1.01^3-1)*ones(ts.nobs-3,ts.vobs)];
|
||||
%$ t(2) = dassert(ts.data,DATA,1e-15);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,98 +0,0 @@
|
|||
function ts = remove(ts,a) % --*-- Unitary tests --*--
|
||||
|
||||
% Removes a variable from a dseries object (alias for the pop method).
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{ts} =} pop (@var{ts}, @var{a})
|
||||
%! @anchor{dseries/pop}
|
||||
%! @sp 1
|
||||
%! Remove method for the dseries class. Removes a variable from a dseries object.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item ts
|
||||
%! Object instantiated by @ref{dseries}.
|
||||
%! @item a
|
||||
%! String, name of the variable to be removed.
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item ts
|
||||
%! Object instantiated by @ref{dseries}, without variable (@var{a}).
|
||||
%! @end table
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 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/>.
|
||||
|
||||
ts = pop(ts, a);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'A3'};
|
||||
%$
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = remove(ts1,'A2');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.data,[A(:,1), A(:,3)],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'A3'};
|
||||
%$
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = ts1.remove('A2');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.data,[A(:,1), A(:,3)],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,76 +0,0 @@
|
|||
function ts = rename(ts,old,new) % --*-- Unitary tests --*--
|
||||
|
||||
% 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 ~ischar(old) || ~ischar(new)
|
||||
error(['dseries::rename: Input arguments ''' inputname(2) ''' and ''' inputname(3) ''' have to be strings!'])
|
||||
end
|
||||
|
||||
idname = find(strcmp(old,ts.name));
|
||||
|
||||
if isempty(idname)
|
||||
error(['dseries::rename: Variable ' old ' is unknown in dseries object ' inputname(1) '!'])
|
||||
end
|
||||
|
||||
ts.name(idname) = {new};
|
||||
|
||||
%@test:1
|
||||
%$ t = zeros(8,1);
|
||||
%$ ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
|
||||
%$ try
|
||||
%$ ts = rename(ts,'Output','Production');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,2);
|
||||
%$ t(6) = dassert(ts.nobs,5);
|
||||
%$ t(7) = dassert(ts.name,{'Production'; 'Consumption'});
|
||||
%$ t(8) = dassert(ts.tex,{'Y_t'; 'C_t'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ t = zeros(8,1);
|
||||
%$ ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
|
||||
%$ try
|
||||
%$ ts = ts.rename('Output','Production');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,2);
|
||||
%$ t(6) = dassert(ts.nobs,5);
|
||||
%$ t(7) = dassert(ts.name,{'Production'; 'Consumption'});
|
||||
%$ t(8) = dassert(ts.tex,{'Y_t'; 'C_t'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,171 +0,0 @@
|
|||
function save(A,basename,format) % --*-- Unitary tests --*--
|
||||
|
||||
% Saves a dseries object on disk.
|
||||
|
||||
% 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 nargin<3 || isempty(format)
|
||||
format = 'csv';
|
||||
end
|
||||
|
||||
if nargin<2 || isempty(basename)
|
||||
basename = inputname(1);
|
||||
end
|
||||
|
||||
switch format
|
||||
case 'm'
|
||||
if exist([basename, '.m'],'file')
|
||||
copyfile([basename, '.m'],[basename, '.old.m']);
|
||||
end
|
||||
fid = fopen([basename, '.m'],'w');
|
||||
fprintf(fid,'%% File created on %s.\n',datestr(now));
|
||||
fprintf(fid,'\n');
|
||||
fprintf(fid,'FREQ__ = %s;\n',num2str(frequency(A)));
|
||||
fprintf(fid,'INIT__ = ''%s'';\n',date2string(firstdate(A)));
|
||||
fprintf(fid,'\n');
|
||||
fprintf(fid,'NAMES__ = {');
|
||||
for i=1:vobs(A)
|
||||
fprintf(fid,[ '''' A.name{i} '''']);
|
||||
if i<vobs(A)
|
||||
fprintf(fid,'; ');
|
||||
end
|
||||
end
|
||||
fprintf(fid,'};\n');
|
||||
str = 'TEX__ = {';
|
||||
for i=1:vobs(A)-1
|
||||
str = [str, '''%s''; '];
|
||||
end
|
||||
str = [str, '''%s''};'];
|
||||
str = sprintf(str, A.tex{:});
|
||||
pattern = '(\w*)(\\\_)';
|
||||
str = regexprep(str, pattern, '$1\\\\_');
|
||||
fprintf(fid,str);
|
||||
fprintf(fid,'\n\n');
|
||||
for v=1:vobs(A)
|
||||
fprintf(fid,'%s = [\n', A.name{v});
|
||||
fprintf(fid,'%15.8g\n',A.data(1:end-1,v));
|
||||
fprintf(fid,'%15.8g];\n\n',A.data(end,v));
|
||||
end
|
||||
fclose(fid);
|
||||
case 'mat'
|
||||
FREQ__ = frequency(A);
|
||||
INIT__ = date2string(firstdate(A));
|
||||
NAMES__ = A.name;
|
||||
TEX__ = A.tex;
|
||||
str = [];
|
||||
for v=1:vobs(A)
|
||||
str = [str, A.name{v} ' = A.data(:,' num2str(v) ');' ];
|
||||
end
|
||||
eval(str);
|
||||
if exist([basename, '.mat'],'file')
|
||||
copyfile([basename, '.mat'],[basename, '.old.mat']);
|
||||
end
|
||||
save([basename '.mat'],'INIT__','FREQ__','NAMES__','TEX__',A.name{:});
|
||||
case 'csv'
|
||||
if exist([basename, '.csv'],'file')
|
||||
copyfile([basename, '.csv'],[basename, '.old.csv']);
|
||||
end
|
||||
fid = fopen([basename, '.csv'],'w');
|
||||
fprintf(fid,',%s', A.name{:});
|
||||
fprintf(fid,'\n');
|
||||
for t=1:nobs(A)
|
||||
str = sprintf(', %15.8g',A.data(t,:));
|
||||
fprintf(fid, '%s%s\n',date2string(A.dates(t)),str);
|
||||
end
|
||||
fclose(fid);
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ save(ts1,[],'csv');
|
||||
%$ t = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ save(ts1,[],'m');
|
||||
%$ t = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ save(ts1,[],'mat');
|
||||
%$ t = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ if isoctave
|
||||
%$ ts1.save('A');
|
||||
%$ else
|
||||
%$ ts1.save;
|
||||
%$ end
|
||||
%$ t = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
|
@ -1,113 +0,0 @@
|
|||
function A = set_names(B,varargin) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{A} =} times (@var{B},@code{varargin})
|
||||
%! @anchor{@nSeries/set_names}
|
||||
%! @sp 1
|
||||
%! Specify names of the variables in a @ref{dseries} object.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item B
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @item C
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item A
|
||||
%! Dynare time series object.
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2012 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/>.
|
||||
|
||||
% AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT fr
|
||||
|
||||
n = nargin-1;
|
||||
|
||||
if ~isdseries(B)
|
||||
error(['dseries::rename: ' inputname(1) ' must be a dseries object!'])
|
||||
end
|
||||
|
||||
if ~isequal(vobs(B),n)
|
||||
error(['dseries::rename: The number of variables in ' inputname(1) ' does not match the number of declared names!'])
|
||||
end
|
||||
|
||||
A = B;
|
||||
|
||||
for i=1:vobs(A)
|
||||
if ~isempty(varargin{i})
|
||||
A.name(i) = { varargin{i} };
|
||||
end
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'Variable_2';'A3'};
|
||||
%$
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],[],[]);
|
||||
%$ ts2 = set_names(ts1,'A1',[],'A3');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts2.vobs,3);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.name,A_name);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'Variable_2';'A3'};
|
||||
%$
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],[],[]);
|
||||
%$ ts1 = ts1.set_names('A1',[],'A3');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts1.vobs,3);
|
||||
%$ t(3) = dassert(ts1.nobs,10);
|
||||
%$ t(4) = dassert(ts1.name,A_name);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,34 +0,0 @@
|
|||
function varargout = size(o, varargin)
|
||||
|
||||
% 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/>.
|
||||
|
||||
switch nargout
|
||||
case 0
|
||||
size(o.data, varargin{:})
|
||||
case 1
|
||||
varargout{1} = size(o.data, varargin{:});
|
||||
case 2
|
||||
if isequal(nargin, 1)
|
||||
varargout{1} = size(o.data, 1);
|
||||
varargout{2} = size(o.data, 2);
|
||||
else
|
||||
error('dseries::size: Wrong calling sequence!')
|
||||
end
|
||||
otherwise
|
||||
error('dseries::size: Wrong calling sequence! Cannot return more than two arguments.')
|
||||
end
|
|
@ -1,886 +0,0 @@
|
|||
function A = subsasgn(A,S,B) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{A} =} subsasgn (@var{A}, @var{S}, @var{B})
|
||||
%! @anchor{@dseries/subsasgn}
|
||||
%! @sp 1
|
||||
%! Overloads the subsasgn method for the Dynare time series class (@ref{dseries}).
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2012-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/>.
|
||||
|
||||
merge_dseries_objects = 1;
|
||||
|
||||
switch length(S)
|
||||
case 1
|
||||
switch S(1).type
|
||||
case '{}' % Multiple variable selection.
|
||||
if ~isequal(numel(S(1).subs),numel(unique(S(1).subs)))
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
for i=1:numel(S(1).subs)
|
||||
element = S(1).subs{i};
|
||||
idArobase = strfind(element,'@');
|
||||
if ~isempty(idArobase)
|
||||
switch length(idArobase)
|
||||
case 2
|
||||
idComma = strfind(element(idArobase(1)+1:idArobase(2)-1),',');
|
||||
if ~isempty(idComma)
|
||||
elements = cell(1,numel(idComma)+1); j = 1;
|
||||
expression = element(idArobase(1)+1:idArobase(2)-1);
|
||||
while ~isempty(expression)
|
||||
[token, expression] = strtok(expression,',');
|
||||
elements(j) = {[element(1:idArobase(1)-1), token, element(idArobase(2)+1:end)]};
|
||||
j = j + 1;
|
||||
end
|
||||
S(1).subs = replace_object_in_a_one_dimensional_cell_array(S(1).subs, elements(:), i);
|
||||
else
|
||||
error('dseries::subsasgn: Wrong syntax, matlab''s regular expressions cannot be used here!')
|
||||
end
|
||||
case 4
|
||||
idComma_1 = strfind(element(idArobase(1)+1:idArobase(2)-1),',');
|
||||
idComma_2 = strfind(element(idArobase(3)+1:idArobase(4)-1),',');
|
||||
if ~isempty(idComma_1)
|
||||
elements = cell(1,(numel(idComma_1)+1)*(numel(idComma_2)+1)); j = 1;
|
||||
expression_1 = element(idArobase(1)+1:idArobase(2)-1);
|
||||
while ~isempty(expression_1)
|
||||
[token_1, expression_1] = strtok(expression_1,',');
|
||||
expression_2 = element(idArobase(3)+1:idArobase(4)-1);
|
||||
while ~isempty(expression_2)
|
||||
[token_2, expression_2] = strtok(expression_2,',');
|
||||
elements(j) = {[element(1:idArobase(1)-1), token_1, element(idArobase(2)+1:idArobase(3)-1), token_2, element(idArobase(4)+1:end)]};
|
||||
j = j+1;
|
||||
end
|
||||
end
|
||||
S(1).subs = replace_object_in_a_one_dimensional_cell_array(S(1).subs, elements(:), i);
|
||||
else
|
||||
error('dseries::subsasgn: Wrong syntax, matlab''s regular expressions cannot be used here!')
|
||||
end
|
||||
otherwise
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
end
|
||||
end
|
||||
if isempty(B)
|
||||
for i=1:length(S(1).subs)
|
||||
A = remove(A,S(1).subs{i});
|
||||
end
|
||||
return
|
||||
end
|
||||
if ~isequal(length(S(1).subs),vobs(B))
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
if ~isequal(S(1).subs(:),B.name)
|
||||
for i = 1:vobs(B)
|
||||
if ~isequal(S(1).subs{i},B.name{i})
|
||||
% Rename a variable.
|
||||
id = find(strcmp(S(1).subs{i},A.name));
|
||||
if isempty(id)
|
||||
% Add a new variable a change its name.
|
||||
B.name(i) = {S(1).subs{i}};
|
||||
B.tex(i) = {name2tex(S(1).subs{i})};
|
||||
else
|
||||
% Rename variable and change its content.
|
||||
B.name(i) = A.name(id);
|
||||
B.tex(i) = A.tex(id);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
case '.'
|
||||
if isequal(S(1).subs,'init') && isdates(B) && isequal(length(B),1)
|
||||
% Change the initial date (update dates member)
|
||||
A.dates = B:B+(nobs(A)-1);
|
||||
return
|
||||
elseif isequal(S(1).subs,'dates') && isdates(B)
|
||||
% Overwrite the dates member
|
||||
A.dates = B;
|
||||
return
|
||||
elseif ismember(S(1).subs,{'data','name','tex'})
|
||||
error(['dseries::subsasgn: You cannot overwrite ' S(1).subs ' member!'])
|
||||
elseif ~isequal(S(1).subs,B.name)
|
||||
% Single variable selection.
|
||||
if ~isequal(S(1).subs,B.name{1})
|
||||
% Rename a variable.
|
||||
id = find(strcmp(S(1).subs,A.name));
|
||||
if isempty(id)
|
||||
% Add a new variable a change its name.
|
||||
B.name(1) = {S(1).subs};
|
||||
B.tex(1) = {name2tex(S(1).subs)};
|
||||
else
|
||||
% Rename variable and change its content.
|
||||
B.name(1) = A.name(id);
|
||||
B.tex(1) = A.tex(id);
|
||||
end
|
||||
end
|
||||
end
|
||||
case '()' % Date(s) selection
|
||||
if 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
|
||||
[junk, tdx] = intersect(A.dates.time,Dates.time,'rows');
|
||||
if isdseries(B)
|
||||
[junk, tdy] = intersect(B.dates.time,Dates.time,'rows');
|
||||
if isempty(tdy)
|
||||
error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!')
|
||||
end
|
||||
if ~isequal(vobs(A), vobs(B))
|
||||
error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
|
||||
end
|
||||
A.data(tdx,:) = B.data(tdy,:);
|
||||
merge_dseries_objects = 0;
|
||||
elseif isnumeric(B)
|
||||
merge_dseries_objects = 0;
|
||||
if isequal(length(tdx),rows(B))
|
||||
if isequal(columns(A.data),columns(B))
|
||||
A.data(tdx,:) = B;
|
||||
else
|
||||
error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
|
||||
end
|
||||
else
|
||||
error('dseries::subsassgn: Dimension error! The number of periods on the left and right hand side must match.')
|
||||
end
|
||||
else
|
||||
error('dseries::subsasgn: The object on the right hand side must be a dseries object or a numeric array!')
|
||||
end
|
||||
elseif ischar(S(1).subs{1}) && isequal(S(1).subs{1},':') && isempty(A)
|
||||
if isnumeric(B)
|
||||
if isequal(rows(B),1)
|
||||
A.data = repmat(B,A.dates.ndat,1);
|
||||
elseif isequal(rows(B),A.dates.ndat)
|
||||
A.data = B;
|
||||
else
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
if isempty(A.name)
|
||||
A.name = default_name(vobs(A));
|
||||
A.tex = name2tex(A.name);
|
||||
end
|
||||
elseif isdseries(B)
|
||||
if isequal(nobs(B), 1)
|
||||
A.data = repmat(B.data,A.dates.ndat,1);
|
||||
elseif isequal(nobs(B), A.dates.ndat)
|
||||
A.data = B;
|
||||
else
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
if isempty(A.name)
|
||||
A.name = B.name;
|
||||
A.tex = B.tex;
|
||||
end
|
||||
end
|
||||
return
|
||||
else
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
otherwise
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
case 2
|
||||
merge_dseries_objects = 0;
|
||||
if ((isequal(S(1).type,'{}') || isequal(S(1).type,'.')) && isequal(S(2).type,'()'))
|
||||
if isequal(S(1).type,'{}')
|
||||
sA = extract(A,S(1).subs{:});
|
||||
else
|
||||
sA = extract(A,S(1).subs);
|
||||
end
|
||||
if (isdseries(B) && isequal(vobs(sA), vobs(B))) || (isnumeric(B) && isequal(vobs(sA),columns(B))) || (isnumeric(B) && isequal(columns(B),1))
|
||||
if isdates(S(2).subs{1})
|
||||
[junk, tdx] = intersect(sA.dates.time,S(2).subs{1}.time,'rows');
|
||||
if isdseries(B)
|
||||
[junk, tdy] = intersect(B.dates.time,S(2).subs{1}.time,'rows');
|
||||
if isempty(tdy)
|
||||
error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!')
|
||||
end
|
||||
sA.data(tdx,:) = B.data(tdy,:);
|
||||
elseif isnumeric(B)
|
||||
merge_dseries_objects = 0;
|
||||
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('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
|
||||
end
|
||||
else
|
||||
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('dseries::subsassgn: Dimension error! The number of periods on the left and right hand side must match.')
|
||||
end
|
||||
end
|
||||
else
|
||||
error('dseries::subsasgn: The object on the right hand side must be a dseries object or a numeric array!')
|
||||
end
|
||||
else
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
A = merge(A,sA);
|
||||
else
|
||||
error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
|
||||
end
|
||||
end
|
||||
otherwise
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
|
||||
if isempty(A)
|
||||
% Assign variables to an empty dseries object.
|
||||
A = B;
|
||||
return
|
||||
end
|
||||
|
||||
if merge_dseries_objects
|
||||
A = merge(A,B);
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3); B = rand(10,1);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,[],{'B1'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ ts1{'A2'} = ts2;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.vobs,3);
|
||||
%$ t(3) = dassert(ts1.nobs,10);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(ts1.data,[A(:,1), B, A(:,3)],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
|
||||
%$
|
||||
%$ % Apply the exponential function to the second variable.
|
||||
%$ ts1{'A2'} = ts1{'A2'}.exp;
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$
|
||||
%$ t(1) = dassert(ts1.vobs,3);
|
||||
%$ t(2) = dassert(ts1.nobs,10);
|
||||
%$ t(3) = dassert(ts1.name{2},'A2');
|
||||
%$ t(4) = dassert(ts1.name{1},'A1');
|
||||
%$ t(5) = dassert(ts1.name{3},'A3');
|
||||
%$ t(6) = dassert(ts1.data,[A(:,1), exp(A(:,2)), A(:,3)],1e-15);
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
|
||||
%$
|
||||
%$ % Apply the logarithm function to the first and third variables.
|
||||
%$ ts1{'A1'} = ts1{'A1'}.log;
|
||||
%$ ts1{'A3'} = ts1{'A3'}.log;
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$
|
||||
%$ t(1) = dassert(ts1.vobs,3);
|
||||
%$ t(2) = dassert(ts1.nobs,10);
|
||||
%$ t(3) = dassert(ts1.name{2},'A2');
|
||||
%$ t(4) = dassert(ts1.name{1},'A1');
|
||||
%$ t(5) = dassert(ts1.name{3},'A3');
|
||||
%$ t(6) = dassert(ts1.data,[log(A(:,1)), A(:,2), log(A(:,3))],1e-15);
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
|
||||
%$
|
||||
%$ % Apply the logarithm function to the first and third variables of ts1.
|
||||
%$ ts1{'A1','A3'} = ts1{'A1','A3'}.log;
|
||||
%$
|
||||
%$ t(1) = dassert(ts1.vobs,3);
|
||||
%$ t(2) = dassert(ts1.nobs,10);
|
||||
%$ t(3) = dassert(ts1.name{1},'A1') && dassert(ts1.name{2},'A2') && dassert(ts1.name{3},'A3');
|
||||
%$ t(4) = dassert(ts1.data,[log(A(:,1)), A(:,2), log(A(:,3))],1e-15);
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3); B = rand(10,3);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,[],{'A1';'B2';'B3'},[]);
|
||||
%$
|
||||
%$ % Apply the logarithm function to the first and third variables.
|
||||
%$ ts1.A1 = ts2.A1;
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$
|
||||
%$ t(1) = dassert(ts1.vobs,3);
|
||||
%$ t(2) = dassert(ts1.nobs,10);
|
||||
%$ t(3) = dassert(ts1.name{1},'A1');
|
||||
%$ t(4) = dassert(ts1.data(:,1),B(:,1), 1e-15);
|
||||
%$ t(5) = dassert(ts1.data(:,2:3),A(:,2:3), 1e-15);
|
||||
%$ T = all(t);
|
||||
%@eof:5
|
||||
|
||||
%@test:6
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3); B = rand(10,2);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,[],{'B1';'B2'},[]);
|
||||
%$
|
||||
%$ % Call tested routine.
|
||||
%$ try
|
||||
%$ ts1.B2 = ts2.B2.log;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.vobs,4);
|
||||
%$ t(3) = dassert(ts1.nobs,10);
|
||||
%$ t(4) = dassert(ts1.name{1},'A1');
|
||||
%$ t(5) = dassert(ts1.name{2},'A2');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(ts1.name{4},'B2');
|
||||
%$ t(8) = dassert(ts1.data,[A(:,1), A(:,2), A(:,3), log(B(:,2))],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:6
|
||||
|
||||
%@test:7
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3); B = rand(10,2);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,[],{'B1';'B2'},[]);
|
||||
%$
|
||||
%$ % Append B2 to the first object.
|
||||
%$ ts1{'B2'} = ts2{'B2'};
|
||||
%$ t(1) = 1;
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.vobs,4);
|
||||
%$ t(3) = dassert(ts1.nobs,10);
|
||||
%$ t(4) = dassert(ts1.name{1},'A1');
|
||||
%$ t(5) = dassert(ts1.name{2},'A2');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(6) = dassert(ts1.name{4},'B2');
|
||||
%$ t(7) = dassert(ts1.data,[A(:,1), A(:,2), A(:,3), B(:,2)],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:7
|
||||
|
||||
%@test:8
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3); B = rand(10,1);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,[],{'B1'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ ts1{'A4'} = ts2;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.vobs,4);
|
||||
%$ t(3) = dassert(ts1.nobs,10);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(ts1.name{4},'A4');
|
||||
%$ t(8) = dassert(ts1.data,[A, B],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:8
|
||||
|
||||
%@test:9
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3); B = rand(10,2);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,[],{'A1';'B1'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ ts1{'A1','A4'} = ts2;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.vobs,4);
|
||||
%$ t(3) = dassert(ts1.nobs,10);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(ts1.name{4},'A4');
|
||||
%$ t(8) = dassert(ts1.data,[B(:,1), A(:,2:3), B(:,2)],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:9
|
||||
|
||||
|
||||
%@test:10
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3); B = rand(10,3);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,[],{'A1';'B1';'B2'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ ts1{'A@1,2@','A4'} = ts2;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.vobs,4);
|
||||
%$ t(3) = dassert(ts1.nobs,10);
|
||||
%$ t(4) = dassert(ts1.name{1},'A1');
|
||||
%$ t(5) = dassert(ts1.name{2},'A2');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(ts1.name{4},'A4');
|
||||
%$ t(8) = dassert(ts1.data,[B(:,1:2), A(:,3), B(:,3)],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:10
|
||||
|
||||
%@test:11
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3); B = rand(10,5);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,[],{'A_1';'A_2';'A_3'},[]);
|
||||
%$ ts2 = dseries(B,[],{'A_1';'A_2';'B_1';'B_2';'B_3'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ ts1{'@A,B@_@1,2@'} = ts2{'@A,B@_@1,2@'};
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ %t(2) = dassert(ts1.vobs,4);
|
||||
%$ %t(3) = dassert(ts1.nobs,10);
|
||||
%$ %t(4) = dassert(ts1.name,{'A1','A2';'A3';'B1';'B2'});
|
||||
%$ %t(5) = dassert(ts1.data,[B(:,1:2), A(:,3), B(:,3:4)],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:11
|
||||
|
||||
%@test:12
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(40,3); B = rand(40,1);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ d1 = dates('1950Q3');
|
||||
%$ d2 = dates('1951Q3');
|
||||
%$ rg = d1:d2;
|
||||
%$ ts1{'A1'}(rg) = ts2{'B1'}(rg);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.vobs,3);
|
||||
%$ t(3) = dassert(ts1.nobs,40);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(ts1.data,[[A(1:2,1); B(3:7); A(8:end,1)], A(:,2:3)],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:12
|
||||
|
||||
%@test:13
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(40,3); B = rand(40,1);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ d1 = dates('1950Q3');
|
||||
%$ d2 = dates('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) = dassert(ts1.vobs,3);
|
||||
%$ t(3) = dassert(ts1.nobs,40);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(ts1.data,[[A(1:2,1); B(3:7); A(8:end,1)], A(:,2:3)],1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:13
|
||||
|
||||
%@test:14
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(40,3); B = rand(40,1);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ d1 = dates('1950Q3');
|
||||
%$ d2 = dates('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) = dassert(ts1.vobs,3);
|
||||
%$ t(3) = dassert(ts1.nobs,40);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(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 dseries object.
|
||||
%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ d1 = dates('1950Q3');
|
||||
%$ d2 = dates('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) = dassert(ts1.vobs,3);
|
||||
%$ t(3) = dassert(ts1.nobs,40);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(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 dseries object.
|
||||
%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ d1 = dates('1950Q3');
|
||||
%$ d2 = dates('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) = dassert(ts1.vobs,3);
|
||||
%$ t(3) = dassert(ts1.nobs,40);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(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 dseries object.
|
||||
%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ d1 = dates('1950Q3');
|
||||
%$ d2 = dates('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) = dassert(ts1.vobs,3);
|
||||
%$ t(3) = dassert(ts1.nobs,40);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(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 dseries object.
|
||||
%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
|
||||
%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ d1 = dates('1950Q3');
|
||||
%$ d2 = dates('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) = dassert(ts1.vobs,3);
|
||||
%$ t(3) = dassert(ts1.nobs,40);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(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
|
||||
|
||||
%@test:19
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(40,3);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
|
||||
%$
|
||||
%$ % Instantiate a dates object.
|
||||
%$ dd = dates('1952Q1');
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ ts1.init = dd;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.vobs,3);
|
||||
%$ t(3) = dassert(ts1.nobs,40);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(ts1.data,A,1e-15);
|
||||
%$ t(8) = dassert(ts1.init,dd);
|
||||
%$ t(9) = dassert(ts1.dates(1),dd);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:19
|
||||
|
||||
%@test:20
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(40,3);
|
||||
%$
|
||||
%$ % Instantiate two dseries object.
|
||||
%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
|
||||
%$
|
||||
%$ % Instantiate a dates object.
|
||||
%$ dd = dates('1952Q1');
|
||||
%$
|
||||
%$ % modify first object.
|
||||
%$ try
|
||||
%$ ts1.dates = dd:(dd+(ts1.nobs-1));
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts1.vobs,3);
|
||||
%$ t(3) = dassert(ts1.nobs,40);
|
||||
%$ t(4) = dassert(ts1.name{2},'A2');
|
||||
%$ t(5) = dassert(ts1.name{1},'A1');
|
||||
%$ t(6) = dassert(ts1.name{3},'A3');
|
||||
%$ t(7) = dassert(ts1.data,A,1e-15);
|
||||
%$ t(8) = dassert(ts1.init,dd);
|
||||
%$ t(9) = dassert(ts1.dates(1),dd);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:20
|
||||
|
||||
%@test:21
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(4,3);
|
||||
%$
|
||||
%$ % Instantiate an empty dseries object.
|
||||
%$ ts = dseries(dates('1950Q1'):dates('1950Q4'));
|
||||
%$
|
||||
%$ % Populate ts
|
||||
%$ try
|
||||
%$ ts(:) = A;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts.vobs,3);
|
||||
%$ t(3) = dassert(ts.nobs,4);
|
||||
%$ t(4) = dassert(ts.data,A,1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:21
|
||||
|
||||
%@test:22
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(1,3);
|
||||
%$
|
||||
%$ % Instantiate an empty dseries object.
|
||||
%$ ts = dseries(dates('1950Q1'):dates('1950Q4'));
|
||||
%$
|
||||
%$ % Populate ts
|
||||
%$ try
|
||||
%$ ts(:) = A;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ if t(1)
|
||||
%$ t(2) = dassert(ts.vobs,3);
|
||||
%$ t(3) = dassert(ts.nobs,4);
|
||||
%$ t(4) = dassert(ts.data,repmat(A,4,1),1e-15);
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:22
|
||||
|
||||
%@test:23
|
||||
%$ % Instantiate a dseries object.
|
||||
%$ ts0 = dseries(randn(10,6), '1999y');
|
||||
%$
|
||||
%$ % Try to remove Variable_2 and Variable_3
|
||||
%$ try
|
||||
%$ ts0{'Variable_@2,3@'} = [];
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ % Try to display Variable_2 and Variable_3 again (should fail because already removed)
|
||||
%$ try
|
||||
%$ ts0{'Variable_@2,3@'};
|
||||
%$ t(2) = 0;
|
||||
%$ catch
|
||||
%$ t(2) = 1;
|
||||
%$ end
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:23
|
|
@ -1,689 +0,0 @@
|
|||
function B = subsref(A, S) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{us} =} subsref (@var{ts},S)
|
||||
%! @anchor{@dseries/subsref}
|
||||
%! @sp 1
|
||||
%! Overloads the subsref method for the Dynare time series class (@ref{dseries}).
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item ts
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @item S
|
||||
%! Matlab's structure array S with two fields, type and subs. The type field is string containing '()', '@{@}', or '.', where '()' specifies
|
||||
%! integer subscripts, '@{@}' specifies cell array subscripts, and '.' specifies subscripted structure fields. The subs field is a cell array
|
||||
%! or a string containing the actual subscripts (see matlab's documentation).
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item us
|
||||
%! Dynare time series object. Depending on the calling sequence @var{us} is a transformation of @var{ts} obtained by applying a public method on @var{ts},
|
||||
%! or a dseries object built by extracting a variable from @var{ts}, or a dseries object containing a subsample of the all the variable in @var{ts}.
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Example 1.} Let @var{ts} be a dseries object containing three variables named 'A1', 'A2' and 'A3'. Then the following syntax:
|
||||
%! @example
|
||||
%! us = ts.A1;
|
||||
%! @end example
|
||||
%!will create a new dseries object @var{us} containing the variable 'A1'.
|
||||
%! @sp 1
|
||||
%! @strong{Example 2.} Let @var{ts} be a dseries object. Then the following syntax:
|
||||
%! @example
|
||||
%! us = ts.log;
|
||||
%! @end example
|
||||
%!will create a new dseries object @var{us} containing all the variables of @var{ts} transformed by the neperian logarithm.
|
||||
%! @sp 1
|
||||
%! @strong{Example 3.} Let @var{ts} be a dseries object. The following syntax:
|
||||
%! @example
|
||||
%! us = ts(3:50);
|
||||
%! @end example
|
||||
%!will create a new dseries object @var{us} by selecting a subsample out of @var{ts}.
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2011-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/>.
|
||||
|
||||
switch S(1).type
|
||||
case '.'
|
||||
switch S(1).subs
|
||||
case {'data','name','tex','dates'} % Public members.
|
||||
if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
|
||||
error(['dseries::subsref: ' S(1).subs ' is not a method but a member!'])
|
||||
end
|
||||
B = builtin('subsref', A, S(1));
|
||||
case {'log','exp','ygrowth','qgrowth','ydiff','qdiff','abs'} % Give "dot access" to public methods without args.
|
||||
B = feval(S(1).subs,A);
|
||||
if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
|
||||
S = shiftS(S,1);
|
||||
end
|
||||
case 'nobs'
|
||||
% Returns the number of observations.
|
||||
B = rows(A.data);
|
||||
case 'vobs'
|
||||
% Returns the number of variables.
|
||||
B = columns(A.data);
|
||||
case 'init'
|
||||
% Returns a dates object (first date).
|
||||
B = A.dates(1);
|
||||
case 'last'
|
||||
% Returns a dates object (last date).
|
||||
B = A.dates(end);
|
||||
case 'freq'
|
||||
% Returns an integer characterizing the data frequency (1, 4, 12 or 52)
|
||||
B = A.dates.freq;
|
||||
case {'lag','lead','hptrend','hpcycle','chain','detrend','exist'} % Methods with less than two arguments.
|
||||
if length(S)>1 && isequal(S(2).type,'()')
|
||||
if isempty(S(2).subs)
|
||||
B = feval(S(1).subs,A);
|
||||
S = shiftS(S,1);
|
||||
else
|
||||
if ~ischar(S(2).subs{1}) && length(S(2).subs{1})>1
|
||||
error(['dseries::subsref: ' S(1).subs{1} ' method admits no more than one argument!'])
|
||||
end
|
||||
B = feval(S(1).subs,A,S(2).subs{1});
|
||||
S = shiftS(S,1);
|
||||
end
|
||||
else
|
||||
B = feval(S(1).subs,A);
|
||||
end
|
||||
case {'cumsum','insert','pop','cumprod','remove'} % Methods with less than three argument.
|
||||
if length(S)>1 && isequal(S(2).type,'()')
|
||||
if isempty(S(2).subs)
|
||||
B = feval(S(1).subs,A);
|
||||
S = shiftS(S,1);
|
||||
else
|
||||
if length(S(2).subs)>2
|
||||
error(['dseries::subsref: ' S(1).subs{1} ' method admits no more than two arguments!'])
|
||||
end
|
||||
B = feval(S(1).subs,A,S(2).subs{:});
|
||||
S = shiftS(S,1);
|
||||
end
|
||||
else
|
||||
B = feval(S(1).subs,A);
|
||||
end
|
||||
case 'baxter_king_filter'
|
||||
if length(S)>1 && isequal(S(2).type,'()')
|
||||
if isempty(S(2).subs)
|
||||
B = feval(S(1).subs,A);
|
||||
S = shiftS(S,1);
|
||||
else
|
||||
B = feval(S(1).subs,A,S(2).subs{1})
|
||||
S = shiftS(S,1);
|
||||
end
|
||||
else
|
||||
B = feval(S(1).subs,A);
|
||||
end
|
||||
case 'save' % Save dseries object on disk (default is a csv file).
|
||||
B = NaN;
|
||||
if isequal(length(S),2)
|
||||
if strcmp(S(2).type,'()')
|
||||
if isempty(S(2).subs)
|
||||
save(A,inputname(1));
|
||||
else
|
||||
if isempty(S(2).subs{1})
|
||||
save(A,inputname(1),S(2).subs{2});
|
||||
else
|
||||
save(A,S(2).subs{:});
|
||||
end
|
||||
end
|
||||
S = shiftS(S,1);
|
||||
else
|
||||
error('dseries::subsref: Wrong syntax.')
|
||||
end
|
||||
elseif isequal(length(S),1)
|
||||
save(A,inputname(1));
|
||||
else
|
||||
error('dseries::subsref: Call to save method must come in last position!')
|
||||
end
|
||||
case 'size'
|
||||
if isequal(length(S),2) && strcmp(S(2).type,'()')
|
||||
if isempty(S(2).subs)
|
||||
[x,y] = size(A);
|
||||
B = [x, y];
|
||||
else
|
||||
B = size(A,S(2).subs{1});
|
||||
end
|
||||
S = shiftS(S,1);
|
||||
elseif isequal(length(S),1)
|
||||
[x,y] = size(A);
|
||||
B = [x, y];
|
||||
else
|
||||
error('dseries::subsref: Call to size method must come in last position!')
|
||||
end
|
||||
case {'set_names','rename','tex_rename'}
|
||||
B = feval(S(1).subs,A,S(2).subs{:});
|
||||
S = shiftS(S,1);
|
||||
case {'disp'}
|
||||
feval(S(1).subs,A);
|
||||
return
|
||||
otherwise % Extract a sub-object by selecting one variable.
|
||||
ndx = find(strcmp(S(1).subs,A.name));
|
||||
if ~isempty(ndx)
|
||||
B = dseries();
|
||||
B.data = A.data(:,ndx);
|
||||
B.name = A.name(ndx);
|
||||
B.tex = A.tex(ndx);
|
||||
B.tex = deblank(A.tex(ndx,:));
|
||||
B.dates = A.dates;
|
||||
else
|
||||
error('dseries::subsref: Unknown public method, public member or variable!')
|
||||
end
|
||||
end
|
||||
case '()'
|
||||
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 isempty(A)
|
||||
B = dseries(S(1).subs{1});
|
||||
else
|
||||
error(['dseries::subsref: dseries object ''' inputname(1) ''' is not empty!'])
|
||||
end
|
||||
elseif isa(S(1).subs{1},'dynTimeIndex')
|
||||
% shift backward/forward (lag/lead) dseries object
|
||||
shift = S(1).subs{1}.index;
|
||||
if shift>0
|
||||
B = feval('lead',A,shift);
|
||||
elseif shift<0
|
||||
B = feval('lag',A,-shift);
|
||||
else
|
||||
% Do nothing.
|
||||
B = A;
|
||||
end
|
||||
elseif isscalar(S(1).subs{1}) && isnumeric(S(1).subs{1}) && isint(S(1).subs{1})
|
||||
% Input is also interpreted as a backward/forward operator
|
||||
if S(1).subs{1}>0
|
||||
B = feval('lead', A, S(1).subs{1});
|
||||
elseif S(1).subs{1}<0
|
||||
B = feval('lag', A, -S(1).subs{1});
|
||||
else
|
||||
% Do nothing.
|
||||
B = A;
|
||||
end
|
||||
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
|
||||
[junk,tdx] = intersect(A.dates.time,Dates.time,'rows');
|
||||
B = dseries();
|
||||
B.data = A.data(tdx,:);
|
||||
B.name = A.name;
|
||||
B.tex = A.tex;
|
||||
B.dates = A.dates(tdx);
|
||||
elseif isvector(S(1).subs{1}) && all(isint(S(1).subs{1}))
|
||||
error('dseries::subsref: It is not possible to select observations with a vector of integers. You have to index with a dates object instead!');
|
||||
else
|
||||
error('dseries::subsref: I have no idea of what you are trying to do!')
|
||||
end
|
||||
case '{}'
|
||||
if iscellofchar(S(1).subs)
|
||||
B = extract(A,S(1).subs{:});
|
||||
elseif isequal(length(S(1).subs),1) && all(isint(S(1).subs{1}))
|
||||
idx = S(1).subs{1};
|
||||
if max(idx)>size(A.data,2) || min(idx)<1
|
||||
error('dseries::subsref: Indices are out of bounds!')
|
||||
end
|
||||
B = dseries();
|
||||
B.data = A.data(:,idx);
|
||||
B.name = A.name(idx);
|
||||
B.tex = A.tex(idx);
|
||||
B.dates = A.dates;
|
||||
else
|
||||
error('dseries::subsref: What the Hell are you tryin'' to do?!')
|
||||
end
|
||||
otherwise
|
||||
error('dseries::subsref: What the Hell are you doin'' here?!')
|
||||
end
|
||||
|
||||
S = shiftS(S,1);
|
||||
if ~isempty(S)
|
||||
B = subsref(B, S);
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ a = ts1(ts1.dates(2:9));
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ e.data = [transpose(2:9),2*transpose(2:9)];
|
||||
%$ e.nobs = 8;
|
||||
%$ e.vobs = 2;
|
||||
%$ e.name = {'A1';'A2'};
|
||||
%$ e.freq = 1;
|
||||
%$ e.init = dates(1,2);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = dassert(a.data,e.data);
|
||||
%$ t(2) = dassert(a.nobs,e.nobs);
|
||||
%$ t(3) = dassert(a.vobs,e.vobs);
|
||||
%$ t(4) = dassert(a.freq,e.freq);
|
||||
%$ t(5) = dassert(a.init,e.init);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ a = ts1.A1;
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ e.data = transpose(1:10);
|
||||
%$ e.nobs = 10;
|
||||
%$ e.vobs = 1;
|
||||
%$ e.name = {'A1'};
|
||||
%$ e.freq = 1;
|
||||
%$ e.init = dates(1,1);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = dassert(a.data,e.data);
|
||||
%$ t(2) = dassert(a.init,e.init);
|
||||
%$ t(3) = dassert(a.nobs,e.nobs);
|
||||
%$ t(4) = dassert(a.vobs,e.vobs);
|
||||
%$ t(5) = dassert(a.freq,e.freq);
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ a = ts1.log;
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ e.data = log(A);
|
||||
%$ e.nobs = 10;
|
||||
%$ e.vobs = 2;
|
||||
%$ e.name = {'A1';'A2'};
|
||||
%$ e.freq = 1;
|
||||
%$ e.init = dates(1,1);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = dassert(a.data,e.data);
|
||||
%$ t(2) = dassert(a.nobs,e.nobs);
|
||||
%$ t(3) = dassert(a.vobs,e.vobs);
|
||||
%$ t(4) = dassert(a.freq,e.freq);
|
||||
%$ t(5) = dassert(a.init,e.init);
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ % Create an empty dseries object.
|
||||
%$ dataset = dseries();
|
||||
%$
|
||||
%$ t = zeros(5,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ A = dataset('dynseries_test_data.csv');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(A.nobs,4);
|
||||
%$ t(3) = dassert(A.vobs,4);
|
||||
%$ t(4) = dassert(A.freq,4);
|
||||
%$ t(5) = dassert(A.init,dates('1990Q1'));
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10),3*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'B1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ a = ts1{'A1','B1'};
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ e.data = A(:,[1,3]);
|
||||
%$ e.nobs = 10;
|
||||
%$ e.vobs = 2;
|
||||
%$ e.name = {'A1';'B1'};
|
||||
%$ e.freq = 1;
|
||||
%$ e.init = dates(1,1);
|
||||
%$
|
||||
%$ t(1) = dassert(e.data,a.data);
|
||||
%$ t(2) = dassert(e.nobs,a.nobs);
|
||||
%$ t(3) = dassert(e.vobs,a.vobs);
|
||||
%$ t(4) = dassert(e.name,a.name);
|
||||
%$ t(5) = dassert(e.init,a.init);
|
||||
%$ T = all(t);
|
||||
%@eof:5
|
||||
|
||||
%@test:6
|
||||
%$ % Define a data set.
|
||||
%$ A = rand(10,24);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'; 'HICP_1';'HICP_2';'HICP_3'; 'HICP_4'; 'HICP_5'; 'HICP_6'; 'HICP_7'; 'HICP_8'; 'HICP_9'; 'HICP_10'; 'HICP_11'; 'HICP_12';};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ a = ts1{'GDP_[0-9]'};
|
||||
%$ b = ts1{'[A-Z]_1$'};
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ e1.data = A(:,1:12);
|
||||
%$ e1.nobs = 10;
|
||||
%$ e1.vobs = 12;
|
||||
%$ e1.name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'};
|
||||
%$ e1.freq = 1;
|
||||
%$ e1.init = dates(1,1);
|
||||
%$ e2.data = A(:,[1 13]);
|
||||
%$ e2.nobs = 10;
|
||||
%$ e2.vobs = 2;
|
||||
%$ e2.name = {'GDP_1';'HICP_1'};
|
||||
%$ e2.freq = 1;
|
||||
%$ e2.init = dates(1,1);
|
||||
%$
|
||||
%$ % Check results.
|
||||
%$ t(1) = dassert(e1.data,a.data);
|
||||
%$ t(2) = dassert(e1.nobs,a.nobs);
|
||||
%$ t(3) = dassert(e1.vobs,a.vobs);
|
||||
%$ t(4) = dassert(e1.name,a.name);
|
||||
%$ t(5) = dassert(e1.init,a.init);
|
||||
%$ t(6) = dassert(e2.data,b.data);
|
||||
%$ t(7) = dassert(e2.nobs,b.nobs);
|
||||
%$ t(8) = dassert(e2.vobs,b.vobs);
|
||||
%$ t(9) = dassert(e2.name,b.name);
|
||||
%$ t(10) = dassert(e2.init,b.init);
|
||||
%$ T = all(t);
|
||||
%@eof:6
|
||||
|
||||
%@test:7
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts1.save('ts1');
|
||||
%$ t = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:7
|
||||
|
||||
%@test:8
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts1.save('test_generated_data_file','m');
|
||||
%$ t = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:8
|
||||
|
||||
%@test:9
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:60),2*transpose(1:60),3*transpose(1:60)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'B1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,'1971Q1',A_name,[]);
|
||||
%$
|
||||
%$ % Define the range of a subsample.
|
||||
%$ range = dates('1971Q2'):dates('1971Q4');
|
||||
%$ % Call the tested method.
|
||||
%$ a = ts1(range);
|
||||
%$
|
||||
%$ % Expected results.
|
||||
%$ e.data = A(2:4,:);
|
||||
%$ e.nobs = 3;
|
||||
%$ e.vobs = 3;
|
||||
%$ e.name = {'A1';'A2';'B1'};
|
||||
%$ e.freq = 4;
|
||||
%$ e.init = dates('1971Q2');
|
||||
%$
|
||||
%$ t(1) = dassert(e.data,a.data);
|
||||
%$ t(2) = dassert(e.nobs,a.nobs);
|
||||
%$ t(3) = dassert(e.vobs,a.vobs);
|
||||
%$ t(4) = dassert(e.name,a.name);
|
||||
%$ t(5) = dassert(e.init,a.init);
|
||||
%$ T = all(t);
|
||||
%@eof:9
|
||||
|
||||
%@test:10
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:60),2*transpose(1:60),3*transpose(1:60)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'B1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,'1971Q1',A_name,[]);
|
||||
%$
|
||||
%$ % Test the size method.
|
||||
%$ B = ts1.size();
|
||||
%$ C = ts1.size(1);
|
||||
%$ D = ts1.size(2);
|
||||
%$ E = ts1.size;
|
||||
%$
|
||||
%$ t(1) = dassert(B,[60, 3]);
|
||||
%$ t(2) = dassert(E,[60, 3]);
|
||||
%$ t(3) = dassert(C,60);
|
||||
%$ t(4) = dassert(D,3);
|
||||
%$ T = all(t);
|
||||
%@eof:10
|
||||
|
||||
%@test:11
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:60),2*transpose(1:60),3*transpose(1:60)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2';'B1'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ ts1 = dseries(A,'1971Q1',A_name,[]);
|
||||
%$
|
||||
%$ % Test the size method.
|
||||
%$ B = ts1{1};
|
||||
%$ C = ts1{[1,3]};
|
||||
%$ D = ts1{'A1'};
|
||||
%$
|
||||
%$ t(1) = dassert(B.name{1},'A1');
|
||||
%$ t(2) = dassert(B.data,A(:,1));
|
||||
%$ t(3) = dassert(C.name{1},'A1');
|
||||
%$ t(4) = dassert(C.data(:,1),A(:,1));
|
||||
%$ t(5) = dassert(C.name{2},'B1');
|
||||
%$ t(6) = dassert(C.data(:,2),A(:,3));
|
||||
%$ t(7) = dassert(D.name{1},'A1');
|
||||
%$ t(8) = dassert(D.data,A(:,1));
|
||||
%$ T = all(t);
|
||||
%@eof:11
|
||||
|
||||
%@test:12
|
||||
%$ % Define a data set.
|
||||
%$ A = [transpose(1:10),2*transpose(1:10)];
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ if isoctave
|
||||
%$ ts1.save('ts1');
|
||||
%$ else
|
||||
%$ ts1.save();
|
||||
%$ end
|
||||
%$ t = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:12
|
||||
|
||||
%@test:13
|
||||
%$ try
|
||||
%$ data = transpose(0:1:50);
|
||||
%$ ts = dseries(data,'1950Q1');
|
||||
%$ a = ts.lag;
|
||||
%$ b = ts.lead;
|
||||
%$ tt = dynTimeIndex();
|
||||
%$ c = ts(tt-1);
|
||||
%$ d = ts(tt+1);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)>1
|
||||
%$ t(2) = (a==c);
|
||||
%$ t(3) = (b==d);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:13
|
||||
|
||||
%@test:14
|
||||
%$ try
|
||||
%$ data = transpose(0:1:50);
|
||||
%$ ts = dseries(data,'1950Q1');
|
||||
%$ a = ts.lag;
|
||||
%$ b = ts.lead;
|
||||
%$ c = ts(-1);
|
||||
%$ d = ts(1);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)>1
|
||||
%$ t(2) = (a==c);
|
||||
%$ t(3) = (b==d);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:14
|
||||
|
||||
%@test:15
|
||||
%$ try
|
||||
%$ ds = dseries(transpose(1:5));
|
||||
%$ ts = ds(ds.dates(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(ds.dates(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
|
|
@ -1,88 +0,0 @@
|
|||
function ts = tex_rename(ts, varargin) % --*-- Unitary tests --*--
|
||||
|
||||
% 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/>.
|
||||
|
||||
assert(nargin <= 3, 'dseries::tex_rename: accepts at most three args');
|
||||
|
||||
if nargin == 2
|
||||
newtexname = varargin{1};
|
||||
assert(vobs(ts) == 1, ['dseries::tex_rename: with one argument, the dseries contain only one variable.']);
|
||||
else
|
||||
newtexname = varargin{2};
|
||||
name = varargin{1};
|
||||
assert(ischar(name), 'dseries::tex_rename: second input argument (name) must be a string');
|
||||
end
|
||||
|
||||
assert(ischar(newtexname), 'dseries::tex_rename: third input argument (newtexname) name must be a string');
|
||||
|
||||
if nargin == 2
|
||||
idname = 1;
|
||||
else
|
||||
idname = find(strcmp(name, ts.name));
|
||||
if isempty(idname)
|
||||
error(['dseries::tex_rename: Variable ' name ' is unknown in dseries object ' inputname(1) '!'])
|
||||
end
|
||||
end
|
||||
|
||||
ts.tex(idname) = {newtexname};
|
||||
|
||||
%@test:1
|
||||
%$ t = zeros(8,1);
|
||||
%$ ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
|
||||
%$ try
|
||||
%$ ts = tex_rename(ts,'Output','\\Delta Y_t');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,2);
|
||||
%$ t(6) = dassert(ts.nobs,5);
|
||||
%$ t(7) = dassert(ts.name,{'Output'; 'Consumption'});
|
||||
%$ t(8) = dassert(ts.tex,{'\\Delta Y_t'; 'C_t'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ t = zeros(8,1);
|
||||
%$ ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
|
||||
%$ try
|
||||
%$ ts = ts.tex_rename('Output','\\Delta Y_t');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts.freq,4);
|
||||
%$ t(3) = dassert(ts.init.freq,4);
|
||||
%$ t(4) = dassert(ts.init.time,[1950, 1]);
|
||||
%$ t(5) = dassert(ts.vobs,2);
|
||||
%$ t(6) = dassert(ts.nobs,5);
|
||||
%$ t(7) = dassert(ts.name,{'Output'; 'Consumption'});
|
||||
%$ t(8) = dassert(ts.tex,{'\\Delta Y_t'; 'C_t'});
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,81 +0,0 @@
|
|||
function A = uminus(B) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{A} =} plus (@var{B},@var{C})
|
||||
%! @anchor{@dseries/uminus}
|
||||
%! @sp 1
|
||||
%! Overloads the uminus 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}.
|
||||
%! @item C
|
||||
%! Dynare time series object instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item A
|
||||
%! Dynare time series object.
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2012-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/>.
|
||||
|
||||
A = dseries();
|
||||
|
||||
A.data = -(B.data);
|
||||
A.dates = B.dates;
|
||||
|
||||
A.name = cell(vobs(A),1);
|
||||
A.tex = cell(vobs(A),1);
|
||||
for i = 1:vobs(A)
|
||||
A.name(i) = {[ '-' B.name{i}]};
|
||||
A.tex(i) = {[ '-' B.tex{i}]};
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,2);
|
||||
%$
|
||||
%$ % Define names
|
||||
%$ A_name = {'A1';'A2'};
|
||||
%$ A_tex = {'A_1';'A_2'};
|
||||
%$ t = zeros(6,1);
|
||||
%$
|
||||
%$ % Instantiate a time series object.
|
||||
%$ try
|
||||
%$ ts1 = dseries(A,[],A_name,A_tex);
|
||||
%$ ts2 = -ts1;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dassert(ts2.vobs,2);
|
||||
%$ t(3) = dassert(ts2.nobs,10);
|
||||
%$ t(4) = dassert(ts2.data,-A,1e-15);
|
||||
%$ t(5) = dassert(ts2.name,{'-A1';'-A2'});
|
||||
%$ t(6) = dassert(ts2.tex,{'-A_1';'-A_2'});
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,142 +0,0 @@
|
|||
function a = vertcat(varargin) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function file} {@var{a} =} vertcat (@var{b},@var{c}, ...)
|
||||
%! @anchor{horzcat}
|
||||
%! @sp 1
|
||||
%! Method of the dseries 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{dseries}.
|
||||
%! @item c
|
||||
%! Dynare time series object, instantiated by @ref{dseries}.
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item a
|
||||
%! Dynare time series 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 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
|
||||
|
||||
function d = vertcat_(b, c)
|
||||
d = NaN;
|
||||
if ~isequal(frequency(b), frequency(c))
|
||||
error('dseries::vertcat: Frequencies must be common!')
|
||||
end
|
||||
if ~isequal(vobs(b), vobs(c))
|
||||
error('dseries::vertcat: Number of variables must be common!')
|
||||
end
|
||||
if ~isequal(b.name, c.name)
|
||||
error('dseries::vertcat: Variables must be common!')
|
||||
end
|
||||
d = b;
|
||||
d.data = [b.data; c.data];
|
||||
d.dates = [b.dates; c.dates];
|
||||
|
||||
%@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.init = dates(1,1);
|
||||
%$ e.freq = 1;
|
||||
%$ e.name = {'A1';'A2'};
|
||||
%$ e.data = [A;B];
|
||||
%$
|
||||
%$ % Instantiate two time series objects.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts3 = [ts1;ts2];
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$
|
||||
%$ t(1) = dassert(ts3.init,e.init);
|
||||
%$ t(2) = dassert(ts3.freq,e.freq);
|
||||
%$ t(3) = dassert(ts3.data,e.data);
|
||||
%$ t(4) = dassert(ts3.name,e.name);
|
||||
%$ t(5) = dassert(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.init = dates(1,1);
|
||||
%$ e.freq = 1;
|
||||
%$ e.name = {'A1';'A2'};
|
||||
%$ e.data = [A;B;C];
|
||||
%$
|
||||
%$ % Instantiate two time series objects.
|
||||
%$ ts1 = dseries(A,[],A_name,[]);
|
||||
%$ ts2 = dseries(B,[],B_name,[]);
|
||||
%$ ts3 = dseries(C,[],C_name,[]);
|
||||
%$
|
||||
%$ % Call the tested method.
|
||||
%$ ts4 = [ts1; ts2; ts3];
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$
|
||||
%$ t(1) = dassert(ts4.init,e.init);
|
||||
%$ t(2) = dassert(ts4.freq,e.freq);
|
||||
%$ t(3) = dassert(ts4.data,e.data);
|
||||
%$ t(4) = dassert(ts4.name,e.name);
|
||||
%$ t(5) = dassert(ts4.nobs,30);
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,22 +0,0 @@
|
|||
function s = vobs(ts)
|
||||
|
||||
% Returns the number of variables in a @dseries object.
|
||||
|
||||
% Copyright (C) 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/>.
|
||||
|
||||
s = columns(ts.data);
|
|
@ -1,171 +0,0 @@
|
|||
function us = ydiff(ts) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{us} =} ydiff (@var{ts})
|
||||
%! @anchor{ydiff}
|
||||
%! @sp 1
|
||||
%! Computes annual differences.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item ts
|
||||
%! Dynare time series object, instantiated by @ref{dseries}
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item us
|
||||
%! Dynare time series object with transformed data field.
|
||||
%! @end table
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2012-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/>.
|
||||
|
||||
us = ts;
|
||||
|
||||
switch frequency(ts)
|
||||
case 1
|
||||
us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:);
|
||||
us.data(1,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ydiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta ' us.tex{i}]};
|
||||
end
|
||||
case 4
|
||||
us.data(5:end,:) = ts.data(5:end,:)-ts.data(1:end-4,:);
|
||||
us.data(1:4,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ydiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta_4 ' us.tex{i}]};
|
||||
end
|
||||
case 12
|
||||
us.data(13:end,:) = ts.data(13:end,:)-ts.data(1:end-12,:);
|
||||
us.data(1:12,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ydiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta_{12} ' us.tex{i}]};
|
||||
end
|
||||
case 52
|
||||
us.data(53:end,:) = ts.data(53:end,:)-ts.data(1:end-52,:);
|
||||
us.data(1:52,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ydiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta_{52} ' us.tex{i}]};
|
||||
end
|
||||
otherwise
|
||||
error(['dseries::ygrowth: object ' inputname(1) ' has unknown frequency']);
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = transpose(1:100);
|
||||
%$ ts = dseries(data,'1950Q1',{'A1'},{'A_1'});
|
||||
%$ ts = ts.ydiff;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = NaN(4,ts.vobs);
|
||||
%$ DATA = [DATA; 4*ones(ts.nobs-4,ts.vobs)];
|
||||
%$ t(2) = dassert(ts.data,DATA);
|
||||
%$ t(3) = dassert(ts.name{1},['ydiff(A1)']);
|
||||
%$ t(4) = dassert(ts.tex{1},['\\Delta_4 A_1']);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = transpose(1:100);
|
||||
%$ ts = dseries(data,'1950M1',{'A1'},{'A_1'});
|
||||
%$ ts = ts.ydiff;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = NaN(12,ts.vobs);
|
||||
%$ DATA = [DATA; 12*ones(ts.nobs-12,ts.vobs)];
|
||||
%$ t(2) = dassert(ts.data,DATA);
|
||||
%$ t(3) = dassert(ts.name{1},['ydiff(A1)']);
|
||||
%$ t(4) = dassert(ts.tex{1},['\\Delta_{12} A_1']);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ t = zeros(2,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = transpose(1:100);
|
||||
%$ ts = dseries(data,'1950W1',{'A1'},{'A_1'});
|
||||
%$ ts = ts.ydiff;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = NaN(52,ts.vobs);
|
||||
%$ DATA = [DATA; 52*ones(ts.nobs-52,ts.vobs)];
|
||||
%$ t(2) = dassert(ts.data,DATA);
|
||||
%$ t(3) = dassert(ts.name{1},['ydiff(A1)']);
|
||||
%$ t(4) = dassert(ts.tex{1},['\\Delta_{52} A_1']);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ t = zeros(4,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = transpose(1:100);
|
||||
%$ ts = dseries(data,'1950Y',{'A1'},{'A_1'});
|
||||
%$ ts = ts.ydiff;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = NaN(1,ts.vobs);
|
||||
%$ DATA = [DATA; ones(ts.nobs-1,ts.vobs)];
|
||||
%$ t(2) = dassert(ts.data,DATA);
|
||||
%$ t(3) = dassert(ts.name{1},['ydiff(A1)']);
|
||||
%$ t(4) = dassert(ts.tex{1},['\\Delta A_1']);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
|
@ -1,141 +0,0 @@
|
|||
function us = ygrowth(ts) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{us} =} ygrowth (@var{ts})
|
||||
%! @anchor{ygrowth}
|
||||
%! @sp 1
|
||||
%! Computes annual growth rates.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item ts
|
||||
%! Dynare time series object, instantiated by @ref{dseries}
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item us
|
||||
%! Dynare time series object with transformed data field.
|
||||
%! @end table
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2012-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/>.
|
||||
|
||||
us = ts;
|
||||
|
||||
switch frequency(ts)
|
||||
case 1
|
||||
us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1;
|
||||
us.data(1,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ygrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta ' us.tex{i}]};
|
||||
end
|
||||
case 4
|
||||
us.data(5:end,:) = ts.data(5:end,:)./ts.data(1:end-4,:) - 1;
|
||||
us.data(1:4,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ygrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta_4 ' us.tex{i}]};
|
||||
end
|
||||
case 12
|
||||
us.data(13:end,:) = ts.data(13:end,:)./ts.data(1:end-12,:) - 1;
|
||||
us.data(1:12,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ygrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta_{12} ' us.tex{i}]};
|
||||
end
|
||||
case 52
|
||||
us.data(53:end,:) = ts.data(53:end,:)./ts.data(1:end-52,:) - 1;
|
||||
us.data(1:52,:) = NaN;
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ygrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta_{52} ' us.tex{i}]};
|
||||
end
|
||||
otherwise
|
||||
error(['dseries::ygrowth: object ' inputname(1) ' has unknown frequency']);
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ t = zeros(2,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = repmat(transpose(1:4),100,1);
|
||||
%$ ts = dseries(data,'1950Q1');
|
||||
%$ ts = ts.ygrowth;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = NaN(4,ts.vobs);
|
||||
%$ DATA = [DATA; zeros(ts.nobs-4,ts.vobs)];
|
||||
%$ t(2) = dassert(ts.data,DATA);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ t = zeros(2,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = repmat(transpose(1:12),100,1);
|
||||
%$ ts = dseries(data,'1950M1');
|
||||
%$ ts = ts.ygrowth;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = NaN(12,ts.vobs);
|
||||
%$ DATA = [DATA; zeros(ts.nobs-12,ts.vobs)];
|
||||
%$ t(2) = dassert(ts.data,DATA);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ t = zeros(2,1);
|
||||
%$
|
||||
%$ try
|
||||
%$ data = repmat(transpose(1:52),100,1);
|
||||
%$ ts = dseries(data,'1950W1');
|
||||
%$ ts = ts.ygrowth;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ DATA = NaN(52,ts.vobs);
|
||||
%$ DATA = [DATA; zeros(ts.nobs-52,ts.vobs)];
|
||||
%$ t(2) = dassert(ts.data,DATA);
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
|
@ -1,494 +0,0 @@
|
|||
function from(varargin) % --*-- Unitary tests --*--
|
||||
|
||||
% Copyright (C) 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/>.
|
||||
|
||||
lvarargin = lower(varargin);
|
||||
|
||||
to_id = strmatch('to',lvarargin);
|
||||
do_id = strmatch('do',lvarargin);
|
||||
|
||||
if isempty(to_id) || isempty(do_id)
|
||||
error(get_error_message_0())
|
||||
end
|
||||
|
||||
if do_id<to_id
|
||||
msg = sprinf('dseries::from: Wrong syntax! The TO keyword must preceed the DO keyword.\n');
|
||||
error(get_error_message_0(msg))
|
||||
end
|
||||
|
||||
if ~isdate(varargin{1})
|
||||
% The first argument is not a string formatted date. Test if this argument refers to a dates object
|
||||
% in the caller workspace.
|
||||
try
|
||||
d1 = evalin('caller', varargin{1});
|
||||
if ~isdates(d1)
|
||||
error(['dseries::from: Variable ' varargin{1} ' is not a dates object!'])
|
||||
end
|
||||
catch
|
||||
error(['dseries::from: Variable ' varargin{1} ' is unknown!'])
|
||||
end
|
||||
if ~exist('d1')
|
||||
msg = sprintf('dseries::from: Wrong syntax! The FROM statement must be followed by a string formatted date.\n');
|
||||
error(get_error_message_0(msg))
|
||||
end
|
||||
else
|
||||
d1 = dates(varargin{1}); % First date
|
||||
end
|
||||
|
||||
if ~isequal(to_id,2)
|
||||
msg = sprintf('dseries::from: Wrong syntax! The first dates object must be immediately followed by the TO keyword.\n');
|
||||
error(get_error_message_0(msg))
|
||||
end
|
||||
|
||||
if ~isdate(varargin{3})
|
||||
% The third argument is not a string formatted date. Test if this argument refers to a dates object
|
||||
% in the caller workspace.
|
||||
try
|
||||
d2 = evalin('caller', varargin{3});
|
||||
if ~isdates(d2)
|
||||
error(['dseries::from: Variable ' varargin{3} ' is not a dates object!'])
|
||||
end
|
||||
catch
|
||||
error(['dseries::from: Variable ' varargin{3} ' is unknown!'])
|
||||
end
|
||||
if ~exist('d2')
|
||||
msg = sprintf('dseries::from: Wrong syntax! The TO keyword must be followed by a second dates object.\n');
|
||||
error(get_error_message_0(msg))
|
||||
end
|
||||
else
|
||||
d2 = dates(varargin{3}); % Last date
|
||||
end
|
||||
|
||||
if d1>d2
|
||||
error('dseries::from: The first date must preceed the second one!')
|
||||
end
|
||||
|
||||
if ~isequal(do_id,4)
|
||||
msg = sprintf('dseries::from: Wrong syntax! The second dates object must be immediately followed by the DO keyword.\n');
|
||||
error(get_error_message_0(msg))
|
||||
end
|
||||
|
||||
% Build the recursive expression.
|
||||
EXPRESSION = char([varargin{5:end}]);
|
||||
|
||||
% Check that the expression is an assignment
|
||||
equal_id = strfind(EXPRESSION,'=');
|
||||
if isempty(equal_id)
|
||||
error('dseries::from: Wrong syntax! The expression following the DO keyword must be an assignment (missing equal symbol).')
|
||||
end
|
||||
|
||||
% Issue ann error message if the user attempts to do more than one assignment.
|
||||
if ~isequal(length(equal_id),1)
|
||||
error('dseries::from: Not yet implemented! Only one assignment is allowed in the FROM-TO-DO statement.')
|
||||
end
|
||||
|
||||
% Get all the variables involved in the recursive expression.
|
||||
variables = unique(regexpi(EXPRESSION, '\w*\(t\)|\w*\(t\-\d\)|\w*\(t\+\d\)|\w*\.\w*\(t\)|\w*\.\w*\(t\-\d\)|\w*\.\w*\(t\+\d\)','match'));
|
||||
|
||||
% Copy EXPRESSION in expression. In the next loop we will remove all indexed variables from expression.
|
||||
expression = EXPRESSION;
|
||||
|
||||
% Build an incidence table (max lag/lead for each variable)
|
||||
%
|
||||
% Column 1: Name of the variable.
|
||||
% Column 2: Maximum lag order.
|
||||
% Column 3: Equal to 1 if the variable appears at the current period, 0 otherwise.
|
||||
% Column 4: Maximum lead order.
|
||||
% Column 5: Vector of effective lag orders.
|
||||
% Column 6: Vector of effective lead orders.
|
||||
%
|
||||
% Initialization.
|
||||
leadlagtable = cell(0,6);
|
||||
% Loop over the variables (dseries objects).
|
||||
for i=1:length(variables)
|
||||
expression = strrep(expression,variables{i},'');
|
||||
current = ~isempty(regexpi(variables{i},'\(t\)'));
|
||||
lag = ~isempty(regexpi(variables{i},'\(t\-\d\)'));
|
||||
lead = ~isempty(regexpi(variables{i},'\(t\+\d\)'));
|
||||
start = regexpi(variables{i},'\(t\)|\(t\-\d\)|\(t\+\d\)');
|
||||
index = variables{i}(start:end);
|
||||
variables(i) = {variables{i}(1:start-1)};
|
||||
if isempty(leadlagtable)
|
||||
leadlagtable(1,1) = {variables{i}};
|
||||
if current
|
||||
leadlagtable(1,3) = {1};
|
||||
else
|
||||
leadlagtable(1,3) = {0};
|
||||
end
|
||||
if lag
|
||||
tmp = regexpi(index,'\d','match');
|
||||
leadlagtable(1,2) = {str2double(tmp{1})};
|
||||
leadlagtable(1,5) = {str2double(tmp{1})};
|
||||
else
|
||||
leadlagtable(1,2) = {0};
|
||||
leadlagtable(1,5) = {[]};
|
||||
end
|
||||
if lead
|
||||
tmp = regexpi(index,'\d','match');
|
||||
leadlagtable(1,4) = {str2double(tmp{1})};
|
||||
leadlagtable(1,6) = {str2double(tmp{1})};
|
||||
else
|
||||
leadlagtable(1,4) = {0};
|
||||
leadlagtable(1,6) = {[]};
|
||||
end
|
||||
else
|
||||
linea = strmatch(variables{i},leadlagtable(:,1));
|
||||
if isempty(linea)
|
||||
% This is a new variable!
|
||||
linea = size(leadlagtable,1)+1;
|
||||
leadlagtable(linea,1) = {variables{i}};
|
||||
leadlagtable(linea,2) = {0};
|
||||
leadlagtable(linea,3) = {0};
|
||||
leadlagtable(linea,4) = {0};
|
||||
leadlagtable(linea,5) = {[]};
|
||||
leadlagtable(linea,6) = {[]};
|
||||
end
|
||||
if current
|
||||
leadlagtable(linea,3) = {1};
|
||||
end
|
||||
if lag
|
||||
tmp = regexpi(index,'\d','match');
|
||||
leadlagtable(linea,2) = {max(str2double(tmp{1}),leadlagtable{linea,2})};
|
||||
leadlagtable(linea,5) = {sortrows([leadlagtable{linea,5}; str2double(tmp{1})])};
|
||||
end
|
||||
if lead
|
||||
tmp = regexpi(index,'\d','match');
|
||||
leadlagtable(linea,4) = {max(str2double(tmp{1}),leadlagtable{linea,4})};
|
||||
leadlagtable(linea,6) = {sortrows([leadlagtable{linea,6}; str2double(tmp{1})])};
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
% Set the number of variables
|
||||
number_of_variables = size(leadlagtable,1);
|
||||
|
||||
% Initialize a cell array containing the names of the variables.
|
||||
variable_names = cell(1);
|
||||
|
||||
% Test that all the involved variables are available dseries objects. Also check that
|
||||
% these time series are defined over the time range given by d1 and d2 (taking care of
|
||||
% the lags and leads) and check that each object is a singleton
|
||||
for i=1:number_of_variables
|
||||
current_variable = leadlagtable{i,1};
|
||||
idvar = strfind(current_variable,'.');
|
||||
if isempty(idvar)
|
||||
idvar = 0;
|
||||
end
|
||||
if idvar
|
||||
current_variable_0 = current_variable(1:idvar-1);
|
||||
else
|
||||
current_variable_0 = current_variable;
|
||||
end
|
||||
try
|
||||
var = evalin('caller',current_variable_0);
|
||||
catch
|
||||
error(['dseries::from: Variable ' current_variable_0 ' is unknown!'])
|
||||
end
|
||||
if idvar
|
||||
try
|
||||
eval(sprintf('var = var.%s;',current_variable(idvar+1:end)))
|
||||
catch
|
||||
error(sprintf('dseries::from: Variable %s is not a member of dseries oject %s!', current_variable(idvar+1:end), current_variable_0))
|
||||
end
|
||||
end
|
||||
if ~isdseries(var)
|
||||
error(['dseries::from: Variable ' current_variable ' is not a dseries object!'])
|
||||
else
|
||||
if ~var.vobs
|
||||
msg = sprintf('dseries::from: Object %s must not be empty!\n',current_variable);
|
||||
error(msg)
|
||||
end
|
||||
if var.vobs>1
|
||||
msg = sprintf('dseries::from: Object %s must contain only one variable!\n',current_variable);
|
||||
error(msg)
|
||||
end
|
||||
if i>1
|
||||
if ismember(var.name,variable_names)
|
||||
% Locally change variable name.
|
||||
var = var.rename(var.name{1},get_random_string(20));
|
||||
end
|
||||
variable_names(i) = {var.name{1}};
|
||||
else
|
||||
variable_names(i) = {var.name{1}};
|
||||
end
|
||||
if d1<var.dates(1)+leadlagtable{i,2}
|
||||
msg = sprintf('dseries::from: Initial date of the loop (%s) is inconsistent with %s''s range!\n',char(d1),current_variable);
|
||||
msg = [msg, sprintf(' Initial date should be greater than or equal to %s.',char(var.dates(1)+leadlagtable{i,2}))];
|
||||
error(msg)
|
||||
end
|
||||
if d2>var.dates(end)-leadlagtable{i,4}
|
||||
% The first variable should be the assigned variable (will be tested later)
|
||||
if ~isassignedvariable(leadlagtable{i,1},EXPRESSION)
|
||||
msg = sprintf('dseries::from: Last date of the loop (%s) is inconsistent with %s''s range!\n',char(d2),current_variable);
|
||||
msg = [msg, sprintf(' Last date should be less than or equal to %s.',char(var.dates(end)-leadlagtable{i,4}))];
|
||||
error(msg)
|
||||
else
|
||||
var = [var; dseries(NaN((d2-var.dates(end)),1),var.dates(end)+1:d2,var.name)];
|
||||
end
|
||||
end
|
||||
eval(sprintf('%s = var;',current_variable));
|
||||
end
|
||||
end
|
||||
|
||||
% Get the name of the assigned variable (with time index)
|
||||
assignedvariablename = regexpi(EXPRESSION(1:equal_id-1), '\w*\(t\)|\w*\(t\-\d\)|\w*\(t\+\d\)|\w*\.\w*\(t\)|\w*\.\w*\(t\-\d\)|\w*\.\w*\(t\+\d\)','match');
|
||||
if isempty(assignedvariablename)
|
||||
error('dseries::from: Wrong syntax! The expression following the DO keyword must be an assignment (missing variable before the equal symbol).')
|
||||
end
|
||||
if length(assignedvariablename)>1
|
||||
error('dseries::from: No more than one variable can be assigned!')
|
||||
end
|
||||
% Check if the model is static
|
||||
start = regexpi(assignedvariablename{1},'\(t\)|\(t\-\d\)|\(t\+\d\)');
|
||||
index = assignedvariablename{1}(start:end);
|
||||
assignedvariablename = assignedvariablename{1}(1:start-1);
|
||||
indva = strmatch(assignedvariablename, leadlagtable(:,1));
|
||||
dynamicmodel = ~isempty(regexpi(EXPRESSION(equal_id:end), ...
|
||||
sprintf('%s\\(t\\)|%s\\(t\\-\\d\\)|%s\\(t\\+\\d\\)',assignedvariablename,assignedvariablename,assignedvariablename),'match'));
|
||||
% Check that the dynamic model for the endogenous variable is not forward looking.
|
||||
if dynamicmodel
|
||||
indum = index2num(index);
|
||||
if indum<leadlagtable{indva,4}
|
||||
error('dseries::from: It is not possible to simulate a forward looking model!')
|
||||
end
|
||||
end
|
||||
% Check that the assigned variable does not depend on itself (the assigned variable can depend on its past level but not on the current level).
|
||||
if dynamicmodel
|
||||
tmp = regexpi(EXPRESSION(equal_id+1:end), ...
|
||||
sprintf('%s\\(t\\)|%s\\(t\\-\\d\\)|%s\\(t\\+\\d\\)',assignedvariablename,assignedvariablename,assignedvariablename),'match');
|
||||
tmp = cellfun(@extractindex, tmp);
|
||||
tmp = cellfun(@index2num, tmp);
|
||||
if ~all(tmp(:)<indum)
|
||||
error(sprintf('dseries::from: On the righthand side, the endogenous variable, %s, must be indexed by %s at most.',assignedvariablename,num2index(indum-1)))
|
||||
end
|
||||
end
|
||||
|
||||
% Put all the variables in a unique dseries object.
|
||||
list_of_variables = leadlagtable{1,1};
|
||||
for i=2:number_of_variables
|
||||
list_of_variables = [list_of_variables, ',' leadlagtable{i,1}];
|
||||
end
|
||||
eval(sprintf('tmp = [%s];', list_of_variables));
|
||||
|
||||
% Get base time index
|
||||
t1 = find(d1==tmp.dates);
|
||||
t2 = find(d2==tmp.dates);
|
||||
|
||||
% Get data
|
||||
data = tmp.data;
|
||||
|
||||
% Isolate the (potential) parameters in the expression to be evaluated
|
||||
TMP314 = regexp(expression, '([0-9]*\.[0-9]*|\w*)', 'match');
|
||||
% Here I remove the numbers (TMP314 -> TMP314159).
|
||||
TMP3141 = regexp(TMP314,'(([0-9]*\.[0-9]*)|([0-9]*))','match');
|
||||
TMP31415 = find(cellfun(@isempty,TMP3141));
|
||||
TMP314159 = TMP314(TMP31415);
|
||||
|
||||
if dynamicmodel
|
||||
% Transform EXPRESSION by replacing calls to the dseries objects by references to data.
|
||||
for i=1:number_of_variables
|
||||
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t\\)',leadlagtable{i,1}),sprintf('data(t,%s)',num2str(i)));
|
||||
for j=1:length(leadlagtable{i,5})
|
||||
lag = leadlagtable{i,5}(j);
|
||||
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t-%s\\)',leadlagtable{i,1},num2str(lag)), ...
|
||||
sprintf('data(t-%s,%s)',num2str(lag),num2str(i)));
|
||||
end
|
||||
for j=1:length(leadlagtable{i,6})
|
||||
lead = leadlagtable{i,6}(j);
|
||||
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t+%s\\)',leadlagtable{i,1},num2str(lead)), ...
|
||||
sprintf('data(t+%s,%s)',num2str(lead),num2str(i)));
|
||||
end
|
||||
end
|
||||
% Get values for the parameters (if any)
|
||||
if ~isempty(TMP314159)
|
||||
for i=1:length(TMP314159)
|
||||
wordcandidate = TMP314159{i};
|
||||
try % If succesful, word is a reference to a variable in the caller function/script.
|
||||
thiswordisaparameter = evalin('caller', wordcandidate);
|
||||
eval(sprintf('%s = thiswordisaparameter;',wordcandidate));
|
||||
catch
|
||||
% I assume that word is a reference to a function.
|
||||
end
|
||||
end
|
||||
end
|
||||
% Do the job. Evaluate the recursion.
|
||||
eval(sprintf('for t=%s:%s, %s; end',num2str(t1),num2str(t2),EXPRESSION));
|
||||
else
|
||||
% Transform EXPRESSION by replacing calls to the dseries objects by references to data.
|
||||
for i=1:number_of_variables
|
||||
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t\\)',leadlagtable{i,1}), ...
|
||||
sprintf('data(%s:%s,%s)',num2str(t1),num2str(t2),num2str(i)));
|
||||
for j=1:length(leadlagtable{i,5})
|
||||
lag = leadlagtable{i,5}(j);
|
||||
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t-%s\\)',leadlagtable{i,1},num2str(lag)), ...
|
||||
sprintf('data(%s:%s,%s)',num2str(t1-lag),num2str(t2-lag),num2str(i)));
|
||||
end
|
||||
for j=1:length(leadlagtable{i,6})
|
||||
lead = leadlagtable{i,6}(j);
|
||||
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t+%s\\)',leadlagtable{i,1},num2str(lead)), ...
|
||||
sprintf('data(%s:%s,%s)',num2str(t1-lead),num2str(t2-lead),num2str(i)));
|
||||
end
|
||||
end
|
||||
% Transform some operators (^ -> .^, / -> ./ and * -> .*)
|
||||
EXPRESSION = strrep(EXPRESSION,'^','.^');
|
||||
EXPRESSION = strrep(EXPRESSION,'*','.*');
|
||||
EXPRESSION = strrep(EXPRESSION,'/','./');
|
||||
% Get values for the parameters (if any)
|
||||
if ~isempty(TMP314159)
|
||||
for i=1:length(TMP314159)
|
||||
wordcandidate = TMP314159{i};
|
||||
try % If succesful, word is a reference to a variable in the caller function/script.
|
||||
thiswordisaparameter = evalin('caller', wordcandidate);
|
||||
eval(sprintf('%s = thiswordisaparameter;',wordcandidate));
|
||||
catch
|
||||
% I assume that word is a reference to a function.
|
||||
end
|
||||
end
|
||||
end
|
||||
% Do the job. Evaluate the static expression.
|
||||
eval(sprintf('%s;',EXPRESSION));
|
||||
end
|
||||
|
||||
% Put assigned variable back in the caller workspace...
|
||||
if isempty(strfind(assignedvariablename,'.'))
|
||||
eval(sprintf('assignin(''caller'', ''%s'', dseries(data(:,indva),%s.init,%s.name,%s.tex));', ...
|
||||
assignedvariablename,assignedvariablename,assignedvariablename,assignedvariablename))
|
||||
else
|
||||
DATA = num2cell(data(:,indva));
|
||||
strdata = sprintf('%f ', DATA{:});
|
||||
evalin('caller',sprintf('%s = dseries(transpose([%s]),%s.init,%s.name,%s.tex);', ...
|
||||
assignedvariablename,strdata,assignedvariablename,assignedvariablename,assignedvariablename))
|
||||
end
|
||||
|
||||
function msg = get_error_message_0(msg)
|
||||
if ~nargin
|
||||
msg = sprintf('Wrong syntax! The correct syntax is:\n\n');
|
||||
else
|
||||
msg = [msg, sprintf('The correct syntax is:\n\n')];
|
||||
end
|
||||
msg = [msg, sprintf(' from d1 to d2 do SOMETHING\n\n')];
|
||||
msg = [msg, sprintf('where d1<d2 are dates objects, and SOMETHING is a recursive expression involving dseries objects.')];
|
||||
|
||||
|
||||
function index = extractindex(str)
|
||||
index = regexpi(str,'\(t\)|\(t\-\d\)|\(t\+\d\)','match');
|
||||
|
||||
|
||||
function i = index2num(id)
|
||||
if isequal('(t)',id)
|
||||
i = 0;
|
||||
return
|
||||
end
|
||||
if isequal('-',id(3))
|
||||
i = - str2num(id(4:end-1));
|
||||
else
|
||||
i = str2num(id(4:end-1));
|
||||
end
|
||||
|
||||
|
||||
function id = num2index(i)
|
||||
if isequal(i,0)
|
||||
id = '(t)';
|
||||
return
|
||||
end
|
||||
if i<0
|
||||
id = ['(t-' int2str(abs(i)) ')'];
|
||||
else
|
||||
id = ['(t+' int2str(i) ')'];
|
||||
end
|
||||
|
||||
function i = isassignedvariable(var,expr)
|
||||
idv = strfind(expr,var);
|
||||
idq = strfind(expr,'=');
|
||||
if ~isempty(idv)
|
||||
if idv(1)<idq
|
||||
i = 1;
|
||||
return
|
||||
end
|
||||
end
|
||||
i = 0;
|
||||
|
||||
%@test:1
|
||||
%$ try
|
||||
%$ y = dseries(zeros(400,1),dates('1950Q1')) ;
|
||||
%$ v = dseries(randn(400,1),dates('1950Q1')) ;
|
||||
%$ u = dseries(randn(400,1),dates('1950Q1')) ;
|
||||
%$ from 1950Q2 to 2049Q4 do y(t) = (1+.01*u(t))*y(t-1) + v(t)
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ try
|
||||
%$ y = dseries(zeros(400,1),dates('1950Q1')) ;
|
||||
%$ v = dseries(randn(400,1),dates('1950Q1')) ;
|
||||
%$ u = dseries(randn(400,1),dates('1950Q1')) ;
|
||||
%$ from 1950Q2 to 2049Q3 do y(t) = (1+.01*u(t))*y(t+1) + v(t)
|
||||
%$ t(1) = 0;
|
||||
%$ catch
|
||||
%$ t(1) = 1;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ try
|
||||
%$ y = dseries(zeros(400,1),dates('1950Q1')) ;
|
||||
%$ v = dseries(randn(400,1),dates('1950Q1')) ;
|
||||
%$ u = dseries(randn(400,1),dates('1950Q1')) ;
|
||||
%$ from 1950Q2 to 2049Q4 do y(t) = v(t) -.5*v(t-1);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ try
|
||||
%$ y = dseries(zeros(400,1),dates('1950Q1')) ;
|
||||
%$ v = dseries(randn(400,1),dates('1950Q1')) ;
|
||||
%$ u = dseries(randn(400,1),dates('1950Q1')) ;
|
||||
%$ from 1950Q2 to 2049Q4 do y(t) = 2*((v(t) -.5*v(t-1))>0)-1;
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ try
|
||||
%$ y = dseries(zeros(4000,1),dates('1950Q1')) ;
|
||||
%$ v = dseries(randn(4000,1),dates('1950Q1')) ;
|
||||
%$ u = dseries(randn(4000,1),dates('1950Q1')) ;
|
||||
%$ from 1950Q2 to 2949Q4 do y(t) = y(t-1)*(2*((v(t) -.5*v(t-1))>u(t))-1)+u(t); %plot(y)
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:5
|
|
@ -1,20 +0,0 @@
|
|||
function B = isdseries(A)
|
||||
|
||||
% 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/>.
|
||||
|
||||
B = isa(A,'dseries');
|
Loading…
Reference in New Issue