2013-09-05 11:34:19 +02:00
function B = subsref ( A, S) % --*-- Unitary tests --*--
2011-08-15 15:18:45 +02:00
%@info:
%! @deftypefn {Function File} {@var{us} =} subsref (@var{ts},S)
2013-10-18 17:38:43 +02:00
%! @anchor{@dseries/subsref}
2011-08-15 15:18:45 +02:00
%! @sp 1
2013-10-18 17:38:43 +02:00
%! Overloads the subsref method for the Dynare time series class (@ref{dseries}).
2011-08-15 15:18:45 +02:00
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item ts
2013-10-18 17:38:43 +02:00
%! Dynare time series object instantiated by @ref{dseries}.
2011-08-15 15:18:45 +02:00
%! @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},
2013-10-18 17:38:43 +02:00
%! 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}.
2011-08-15 15:18:45 +02:00
%! @end table
%! @sp 2
2013-10-18 17:38:43 +02:00
%! @strong{Example 1.} Let @var{ts} be a dseries object containing three variables named 'A1', 'A2' and 'A3'. Then the following syntax:
2011-08-15 15:18:45 +02:00
%! @example
%! us = ts.A1;
%! @end example
2013-10-18 17:38:43 +02:00
%!will create a new dseries object @var{us} containing the variable 'A1'.
2011-08-15 15:18:45 +02:00
%! @sp 1
2013-10-18 17:38:43 +02:00
%! @strong{Example 2.} Let @var{ts} be a dseries object. Then the following syntax:
2011-08-15 15:18:45 +02:00
%! @example
%! us = ts.log;
%! @end example
2013-10-18 17:38:43 +02:00
%!will create a new dseries object @var{us} containing all the variables of @var{ts} transformed by the neperian logarithm.
2011-08-15 15:18:45 +02:00
%! @sp 1
2013-10-18 17:38:43 +02:00
%! @strong{Example 3.} Let @var{ts} be a dseries object. The following syntax:
2011-08-15 15:18:45 +02:00
%! @example
%! us = ts(3:50);
%! @end example
2013-10-18 17:38:43 +02:00
%!will create a new dseries object @var{us} by selecting a subsample out of @var{ts}.
2011-08-15 15:18:45 +02:00
%! @end deftypefn
%@eod:
2013-06-12 16:42:09 +02:00
% Copyright (C) 2011-2013 Dynare Team
2011-09-09 16:03:35 +02:00
%
% 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/>.
2013-03-14 16:39:15 +01:00
switch S ( 1 ) . type
case ' .'
switch S ( 1 ) . subs
2013-11-06 22:43:43 +01:00
case { ' data' , ' nobs' , ' vobs' , ' name' , ' tex' , ' freq' , ' dates' , ' init' } % Public members.
2013-09-03 16:07:38 +02:00
if length ( S ) > 1 && isequal ( S ( 2 ) . type , ' ()' ) && isempty ( S ( 2 ) . subs )
2013-10-18 17:38:43 +02:00
error ( [ ' dseries::subsref: ' S ( 1 ) . subs ' is not a method but a member!' ] )
2013-09-03 16:07:38 +02:00
end
2013-03-14 16:39:15 +01:00
B = builtin ( ' subsref' , A , S ( 1 ) ) ;
2013-09-03 16:07:38 +02:00
case { ' log' , ' exp' , ' ygrowth' , ' qgrowth' , ' ydiff' , ' qdiff' } % Give "dot access" to public methods without args.
2013-03-14 16:39:15 +01:00
B = feval ( S ( 1 ) . subs , A ) ;
2013-09-03 16:07:38 +02:00
if length ( S ) > 1 && isequal ( S ( 2 ) . type , ' ()' ) && isempty ( S ( 2 ) . subs )
S = shiftS ( S ) ;
end
2013-10-17 15:59:29 +02:00
case { ' lag' , ' lead' , ' hptrend' , ' hpcycle' } % Methods with less than two arguments.
2013-09-03 16:07:38 +02:00
if length ( S ) > 1 && isequal ( S ( 2 ) . type , ' ()' )
if isempty ( S ( 2 ) . subs )
B = feval ( S ( 1 ) . subs , A ) ;
S = shiftS ( S ) ;
else
if length ( S ( 2 ) . subs { 1 } ) > 1
2013-10-18 17:38:43 +02:00
error ( [ ' dseries::subsref: ' S ( 1 ) . subs { 1 } ' method admits no more than one argument!' ] )
2013-09-03 16:07:38 +02:00
end
2013-10-17 11:36:03 +02:00
B = feval ( S ( 1 ) . subs , A , S ( 2 ) . subs { 1 } ) ;
2013-09-03 16:07:38 +02:00
S = shiftS ( S ) ;
end
2013-09-05 12:16:07 +02:00
else
B = feval ( S ( 1 ) . subs , A ) ;
2013-09-03 16:07:38 +02:00
end
2013-11-14 00:13:31 +01:00
case { ' cumsum' , ' insert' , ' pop' } % Methods with less than three argument.
2013-10-17 15:59:29 +02:00
if length ( S ) > 1 && isequal ( S ( 2 ) . type , ' ()' )
if isempty ( S ( 2 ) . subs )
B = feval ( S ( 1 ) . subs , A ) ;
S = shiftS ( S ) ;
else
2013-11-14 00:13:31 +01:00
if length ( S ( 2 ) . subs ) > 2
2013-10-18 17:38:43 +02:00
error ( [ ' dseries::subsref: ' S ( 1 ) . subs { 1 } ' method admits no more than two arguments!' ] )
2013-10-17 15:59:29 +02:00
end
B = feval ( S ( 1 ) . subs , A , S ( 2 ) . subs { : } ) ;
S = shiftS ( S ) ;
end
else
B = feval ( S ( 1 ) . subs , A ) ;
end
2013-09-17 22:48:22 +02:00
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 ) ;
else
B = feval ( S ( 1 ) . subs , A , S ( 2 ) . subs { 1 } )
S = shiftS ( S ) ;
end
else
B = feval ( S ( 1 ) . subs , A ) ;
end
2013-10-18 17:38:43 +02:00
case ' save' % Save dseries object on disk (default is a csv file).
2013-03-21 16:41:27 +01:00
B = NaN ;
2013-09-03 16:39:02 +02:00
if isequal ( length ( S ) , 2 )
if strcmp ( S ( 2 ) . type , ' ()' )
if isempty ( S ( 2 ) . subs )
save ( A , inputname ( 1 ) ) ;
else
2013-11-14 12:55:11 +01:00
if isempty ( S ( 2 ) . subs { 1 } )
save ( A , inputname ( 1 ) , S ( 2 ) . subs { 2 } ) ;
else
save ( A , S ( 2 ) . subs { : } ) ;
end
2013-09-03 16:39:02 +02:00
end
S = shiftS ( S ) ;
else
2013-10-18 17:38:43 +02:00
error ( ' dseries::subsref: Wrong syntax.' )
2013-09-03 16:39:02 +02:00
end
elseif isequal ( length ( S ) , 1 )
2013-06-24 15:33:05 +02:00
save ( A , inputname ( 1 ) ) ;
2013-09-03 16:39:02 +02:00
else
2013-10-18 17:38:43 +02:00
error ( ' dseries::subsref: Call to save method must come in last position!' )
2013-03-14 16:39:15 +01:00
end
2013-09-05 12:17:55 +02:00
case ' size'
2013-09-03 16:39:02 +02:00
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
2013-03-29 12:08:46 +01:00
S = shiftS ( S ) ;
2013-09-03 16:39:02 +02:00
elseif isequal ( length ( S ) , 1 )
2013-03-29 12:08:46 +01:00
[ x , y ] = size ( A ) ;
B = [ x , y ] ;
2013-09-03 16:39:02 +02:00
else
2013-10-18 17:38:43 +02:00
error ( ' dseries::subsref: Call to size method must come in last position!' )
2013-03-29 12:08:46 +01:00
end
2013-09-06 16:26:51 +02:00
case { ' set_names' , ' rename' , ' tex_rename' }
2013-03-21 16:41:27 +01:00
B = feval ( S ( 1 ) . subs , A , S ( 2 ) . subs { : } ) ;
S = shiftS ( S ) ;
2011-08-15 15:18:45 +02:00
otherwise % Extract a sub-object by selecting one variable.
2013-10-15 15:39:15 +02:00
ndx = find ( strcmp ( S ( 1 ) . subs , A . name ) ) ;
2011-08-15 15:18:45 +02:00
if ~ isempty ( ndx )
2013-10-18 17:38:43 +02:00
B = dseries ( ) ;
2013-03-14 16:39:15 +01:00
B . data = A . data ( : , ndx ) ;
2013-03-20 10:32:09 +01:00
B . name = A . name ( ndx ) ;
B . tex = A . tex ( ndx ) ;
2013-03-14 16:39:15 +01:00
B . tex = deblank ( A . tex ( ndx , : ) ) ;
B . nobs = A . nobs ;
B . vobs = 1 ;
B . freq = A . freq ;
B . init = A . init ;
2013-11-06 22:43:43 +01:00
B . dates = A . dates ;
2011-08-15 15:18:45 +02:00
else
2013-10-18 17:38:43 +02:00
error ( ' dseries::subsref: Unknown public method, public member or variable!' )
2011-08-13 00:32:42 +02:00
end
2013-09-05 12:17:55 +02:00
end
2013-03-14 16:39:15 +01:00
case ' ()'
if ischar ( S ( 1 ) . subs { 1 } )
2013-10-18 17:38:43 +02:00
% If ts is an empty dseries object, populate this object by reading data in a file.
2013-03-14 16:39:15 +01:00
if isempty ( A )
2013-10-18 17:38:43 +02:00
B = dseries ( S ( 1 ) . subs { 1 } ) ;
2013-03-14 16:39:15 +01:00
else
2013-10-18 17:38:43 +02:00
error ( [ ' dseries::subsref: dseries object ' ' ' inputname ( 1 ) ' ' ' is not empty!' ] )
2013-03-14 16:39:15 +01:00
end
2013-09-05 17:46:04 +02:00
elseif isa ( S ( 1 ) . subs { 1 } , ' dynTimeIndex' )
2013-10-18 17:38:43 +02:00
% shift backward/forward (lag/lead) dseries object
2013-09-05 17:46:04 +02:00
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
2013-10-08 17:21:07 +02:00
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
2013-11-06 22:43:43 +01:00
elseif isdates ( S ( 1 ) . subs { 1 } )
2013-10-15 15:36:21 +02:00
% Extract a subsample using a dates object
2013-11-06 22:43:43 +01:00
[ junk , tdx ] = intersect ( A . dates . time , S ( 1 ) . subs { 1 } . time , ' rows' ) ;
2013-10-18 17:38:43 +02:00
B = dseries ( ) ;
2013-03-14 16:39:15 +01:00
B . data = A . data ( tdx , : ) ;
2013-03-20 10:32:09 +01:00
B . name = A . name ;
B . tex = A . tex ;
2013-03-14 16:39:15 +01:00
B . nobs = length ( tdx ) ;
B . vobs = A . vobs ;
B . freq = A . freq ;
2013-06-24 11:29:26 +02:00
B . init = A . init + ( tdx ( 1 ) - 1 ) ;
2013-11-06 22:43:43 +01:00
B . dates = A . dates ( tdx ) ;
2013-03-14 16:39:15 +01:00
elseif isvector ( S ( 1 ) . subs { 1 } ) && all ( isint ( S ( 1 ) . subs { 1 } ) )
% Extract a subsample using a vector of integers (observation index).
2013-10-08 17:21:07 +02:00
% Note that this does not work if S(1).subs is an integer scalar... In which case S(1).subs is interpreted as a lead/lag operator (as in the Dynare syntax).
2013-10-16 16:16:26 +02:00
% To extract one observation, a dates with one element input must be used.
2013-03-14 16:39:15 +01:00
if all ( S ( 1 ) . subs { 1 } > 0 ) && all ( S ( 1 ) . subs { 1 } < = A . nobs )
if size ( A . data , 2 ) > 1
S ( 1 ) . subs = [ S ( 1 ) . subs , ' :' ] ;
end
B . data = builtin ( ' subsref' , A . data , S ( 1 ) ) ;
B . nobs = size ( B . data , 1 ) ;
B . vobs = A . vobs ;
B . freq = A . freq ;
2013-11-06 22:43:43 +01:00
B . dates = builtin ( ' subsref' , A . dates , S ( 1 ) ) ;
B . init = B . dates ( 1 ) ;
2013-03-14 16:39:15 +01:00
B . name = A . name ;
B . tex = A . tex ;
else
2013-10-18 17:38:43 +02:00
error ( ' dseries::subsref: Indices are out of bounds!' )
2012-12-03 16:14:25 +01:00
end
2011-09-09 16:03:35 +02:00
else
2013-10-18 17:38:43 +02:00
error ( ' dseries::subsref: I have no idea of what you are trying to do!' )
2011-09-09 16:03:35 +02:00
end
2013-03-14 16:39:15 +01:00
case ' {}'
Added the possibility to extract variables from dynSeries object using indices instead of variable names.
If ts is a dynSeries object containing variables A1, A2, A3, A4, A5, then the following syntaxes are equivalent:
ts{[1, 2, 5]}
ts{'A1','A2','A5'}
and will create a new dynSeries object made of variables A1, A2 and A5.
2013-03-29 14:52:48 +01:00
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 ) > A . vobs || min ( idx ) < 1
2013-10-18 17:38:43 +02:00
error ( ' dseries::subsref: Indices are out of bounds!' )
Added the possibility to extract variables from dynSeries object using indices instead of variable names.
If ts is a dynSeries object containing variables A1, A2, A3, A4, A5, then the following syntaxes are equivalent:
ts{[1, 2, 5]}
ts{'A1','A2','A5'}
and will create a new dynSeries object made of variables A1, A2 and A5.
2013-03-29 14:52:48 +01:00
end
2013-10-18 17:38:43 +02:00
B = dseries ( ) ;
Added the possibility to extract variables from dynSeries object using indices instead of variable names.
If ts is a dynSeries object containing variables A1, A2, A3, A4, A5, then the following syntaxes are equivalent:
ts{[1, 2, 5]}
ts{'A1','A2','A5'}
and will create a new dynSeries object made of variables A1, A2 and A5.
2013-03-29 14:52:48 +01:00
B . data = A . data ( : , idx ) ;
B . name = A . name ( idx ) ;
B . tex = A . tex ( idx ) ;
B . nobs = A . nobs ;
B . vobs = length ( idx ) ;
B . freq = A . freq ;
B . init = A . init ;
2013-11-06 22:43:43 +01:00
B . dates = A . dates ;
Added the possibility to extract variables from dynSeries object using indices instead of variable names.
If ts is a dynSeries object containing variables A1, A2, A3, A4, A5, then the following syntaxes are equivalent:
ts{[1, 2, 5]}
ts{'A1','A2','A5'}
and will create a new dynSeries object made of variables A1, A2 and A5.
2013-03-29 14:52:48 +01:00
else
2013-10-18 17:38:43 +02:00
error ( ' dseries::subsref: What the Hell are you tryin' ' to do?!' )
Added the possibility to extract variables from dynSeries object using indices instead of variable names.
If ts is a dynSeries object containing variables A1, A2, A3, A4, A5, then the following syntaxes are equivalent:
ts{[1, 2, 5]}
ts{'A1','A2','A5'}
and will create a new dynSeries object made of variables A1, A2 and A5.
2013-03-29 14:52:48 +01:00
end
2013-03-14 16:39:15 +01:00
otherwise
2013-10-18 17:38:43 +02:00
error ( ' dseries::subsref: What the Hell are you doin' ' here?!' )
2012-12-07 00:52:01 +01:00
end
2013-03-14 16:39:15 +01:00
S = shiftS ( S ) ;
if ~ isempty ( S )
B = subsref ( B , S ) ;
2013-03-08 17:46:28 +01:00
end
2011-08-13 00:32:42 +02:00
%@test:1
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
2012-12-03 15:51:03 +01:00
%$ A_name = {'A1';'A2'};
2011-08-13 00:32:42 +02:00
%$
%$ % Instantiate a time series object.
2013-10-18 17:38:43 +02:00
%$ ts1 = dseries(A,[],A_name,[]);
2011-08-13 00:32:42 +02:00
%$
%$ % Call the tested method.
%$ a = ts1(2:9);
%$
%$ % Expected results.
%$ e.data = [transpose(2:9),2*transpose(2:9)];
%$ e.nobs = 8;
%$ e.vobs = 2;
2012-12-03 15:51:03 +01:00
%$ e.name = {'A1';'A2'};
2011-08-13 00:32:42 +02:00
%$ e.freq = 1;
2013-10-16 16:16:26 +02:00
%$ e.init = dates(1,2);
2011-08-13 00:32:42 +02:00
%$
%$ % Check the results.
%$ t(1) = dyn_assert(a.data,e.data);
2012-12-03 15:51:03 +01:00
%$ t(2) = dyn_assert(a.nobs,e.nobs);
%$ t(3) = dyn_assert(a.vobs,e.vobs);
%$ t(4) = dyn_assert(a.freq,e.freq);
2013-10-16 16:16:26 +02:00
%$ t(5) = dyn_assert(isequal(a.init,e.init),1);
2011-08-13 00:32:42 +02:00
%$ T = all(t);
%@eof:1
%@test:2
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
2012-12-03 15:51:03 +01:00
%$ A_name = {'A1';'A2'};
2011-08-13 00:32:42 +02:00
%$
%$ % Instantiate a time series object.
2013-10-18 17:38:43 +02:00
%$ ts1 = dseries(A,[],A_name,[]);
2011-08-13 00:32:42 +02:00
%$
%$ % Call the tested method.
%$ a = ts1.A1;
%$
%$ % Expected results.
%$ e.data = transpose(1:10);
%$ e.nobs = 10;
%$ e.vobs = 1;
2012-12-03 15:51:03 +01:00
%$ e.name = {'A1'};
2011-08-13 00:32:42 +02:00
%$ e.freq = 1;
2013-10-16 16:16:26 +02:00
%$ e.init = dates(1,1);
2011-08-13 00:32:42 +02:00
%$
%$ % Check the results.
%$ t(1) = dyn_assert(a.data,e.data);
2013-10-16 16:16:26 +02:00
%$ t(2) = dyn_assert(isequal(a.init,e.init),1);
2011-08-13 00:32:42 +02:00
%$ t(3) = dyn_assert(a.nobs,e.nobs);
%$ t(4) = dyn_assert(a.vobs,e.vobs);
%$ t(5) = dyn_assert(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
2012-12-03 15:51:03 +01:00
%$ A_name = {'A1';'A2'};
2011-08-13 00:32:42 +02:00
%$
%$ % Instantiate a time series object.
2013-10-18 17:38:43 +02:00
%$ ts1 = dseries(A,[],A_name,[]);
2011-08-13 00:32:42 +02:00
%$
%$ % Call the tested method.
%$ a = ts1.log;
%$
%$ % Expected results.
%$ e.data = log(A);
%$ e.nobs = 10;
%$ e.vobs = 2;
2012-12-03 15:51:03 +01:00
%$ e.name = {'A1';'A2'};
2011-08-13 00:32:42 +02:00
%$ e.freq = 1;
2013-10-16 16:16:26 +02:00
%$ e.init = dates(1,1);
2011-08-13 00:32:42 +02:00
%$
%$ % Check the results.
%$ t(1) = dyn_assert(a.data,e.data);
2012-12-03 15:51:03 +01:00
%$ t(2) = dyn_assert(a.nobs,e.nobs);
%$ t(3) = dyn_assert(a.vobs,e.vobs);
%$ t(4) = dyn_assert(a.freq,e.freq);
2013-10-16 16:16:26 +02:00
%$ t(5) = dyn_assert(isequal(a.init,e.init),1);
2011-08-13 00:32:42 +02:00
%$ T = all(t);
%@eof:3
2012-12-03 16:14:25 +01:00
%@test:4
2013-10-18 17:38:43 +02:00
%$ % Create an empty dseries object.
%$ dataset = dseries();
2012-12-03 16:14:25 +01:00
%$
%$ 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) = dyn_assert(A.nobs,4);
%$ t(3) = dyn_assert(A.vobs,4);
%$ t(4) = dyn_assert(A.freq,4);
2013-10-16 16:16:26 +02:00
%$ t(5) = dyn_assert(isequal(A.init,dates('1990Q1')),1);
2012-12-03 16:14:25 +01:00
%$ end
%$ T = all(t);
%@eof:4
2012-12-07 00:52:01 +01:00
%@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.
2013-10-18 17:38:43 +02:00
%$ ts1 = dseries(A,[],A_name,[]);
2012-12-07 00:52:01 +01:00
%$
%$ % 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;
2013-10-16 16:16:26 +02:00
%$ e.init = dates(1,1);
2012-12-07 00:52:01 +01:00
%$
%$ t(1) = dyn_assert(e.data,a.data);
%$ t(2) = dyn_assert(e.nobs,a.nobs);
%$ t(3) = dyn_assert(e.vobs,a.vobs);
%$ t(4) = dyn_assert(e.name,a.name);
2013-10-16 16:16:26 +02:00
%$ t(5) = dyn_assert(isequal(e.init,a.init),1);
2012-12-07 00:52:01 +01:00
%$ 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.
2013-10-18 17:38:43 +02:00
%$ ts1 = dseries(A,[],A_name,[]);
2012-12-07 00:52:01 +01:00
%$
%$ % Call the tested method.
2013-11-14 17:58:09 +01:00
%$ a = ts1{'GDP_[0-9]'};
%$ b = ts1{'[A-Z]_1$'};
2012-12-07 00:52:01 +01:00
%$
%$ % 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;
2013-10-16 16:16:26 +02:00
%$ e1.init = dates(1,1);
2013-11-14 17:58:09 +01:00
%$ e2.data = A(:,[1 13]);
2012-12-07 00:52:01 +01:00
%$ e2.nobs = 10;
%$ e2.vobs = 2;
%$ e2.name = {'GDP_1';'HICP_1'};
%$ e2.freq = 1;
2013-10-16 16:16:26 +02:00
%$ e2.init = dates(1,1);
2012-12-07 00:52:01 +01:00
%$
%$ % Check results.
%$ t(1) = dyn_assert(e1.data,a.data);
%$ t(2) = dyn_assert(e1.nobs,a.nobs);
%$ t(3) = dyn_assert(e1.vobs,a.vobs);
%$ t(4) = dyn_assert(e1.name,a.name);
2013-10-16 16:16:26 +02:00
%$ t(5) = dyn_assert(isequal(e1.init,a.init),1);
2012-12-07 00:52:01 +01:00
%$ t(6) = dyn_assert(e2.data,b.data);
%$ t(7) = dyn_assert(e2.nobs,b.nobs);
%$ t(8) = dyn_assert(e2.vobs,b.vobs);
%$ t(9) = dyn_assert(e2.name,b.name);
2013-10-16 16:16:26 +02:00
%$ t(10) = dyn_assert(isequal(e2.init,b.init),1);
2012-12-07 00:52:01 +01:00
%$ T = all(t);
%@eof:6
2012-12-07 15:37:04 +01:00
%@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
2013-10-18 17:38:43 +02:00
%$ ts1 = dseries(A,[],A_name,[]);
2012-12-07 15:37:04 +01:00
%$ ts1.save;
%$ 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
2013-10-18 17:38:43 +02:00
%$ ts1 = dseries(A,[],A_name,[]);
2012-12-07 15:37:04 +01:00
%$ ts1.save('test_generated_data_file','m');
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ T = all(t);
%@eof:8
2013-03-13 16:34:49 +01:00
%@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.
2013-10-18 17:38:43 +02:00
%$ ts1 = dseries(A,'1971Q1',A_name,[]);
2013-03-13 16:34:49 +01:00
%$
%$ % Define the range of a subsample.
2013-10-16 16:16:26 +02:00
%$ range = dates('1971Q2'):dates('1971Q4');
2013-03-13 16:34:49 +01:00
%$ % 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;
2013-10-16 16:16:26 +02:00
%$ e.init = dates('1971Q2');
2013-03-13 16:34:49 +01:00
%$
%$ t(1) = dyn_assert(e.data,a.data);
%$ t(2) = dyn_assert(e.nobs,a.nobs);
%$ t(3) = dyn_assert(e.vobs,a.vobs);
%$ t(4) = dyn_assert(e.name,a.name);
2013-10-16 16:16:26 +02:00
%$ t(5) = dyn_assert(isequal(e.init,a.init),1);
2013-03-13 16:34:49 +01:00
%$ T = all(t);
%@eof:9
2013-03-29 12:09:12 +01:00
%@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.
2013-10-18 17:38:43 +02:00
%$ ts1 = dseries(A,'1971Q1',A_name,[]);
2013-03-29 12:09:12 +01:00
%$
%$ % Test the size method.
%$ B = ts1.size();
%$ C = ts1.size(1);
%$ D = ts1.size(2);
%$ E = ts1.size;
%$
%$ t(1) = dyn_assert(B,[60, 3]);
%$ t(2) = dyn_assert(E,[60, 3]);
%$ t(3) = dyn_assert(C,60);
%$ t(4) = dyn_assert(D,3);
%$ T = all(t);
%@eof:10
2013-03-29 14:53:06 +01:00
%@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.
2013-10-18 17:38:43 +02:00
%$ ts1 = dseries(A,'1971Q1',A_name,[]);
2013-03-29 14:53:06 +01:00
%$
%$ % Test the size method.
%$ B = ts1{1};
%$ C = ts1{[1,3]};
%$ D = ts1{'A1'};
%$
%$ t(1) = dyn_assert(B.name{1},'A1');
%$ t(2) = dyn_assert(B.data,A(:,1));
%$ t(3) = dyn_assert(C.name{1},'A1');
%$ t(4) = dyn_assert(C.data(:,1),A(:,1));
%$ t(5) = dyn_assert(C.name{2},'B1');
%$ t(6) = dyn_assert(C.data(:,2),A(:,3));
%$ t(7) = dyn_assert(D.name{1},'A1');
%$ t(8) = dyn_assert(D.data,A(:,1));
%$ T = all(t);
%@eof:11
2013-09-03 16:39:13 +02:00
%@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
2013-10-18 17:38:43 +02:00
%$ ts1 = dseries(A,[],A_name,[]);
2013-09-03 16:39:13 +02:00
%$ ts1.save();
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ T = all(t);
%@eof:12
2013-09-05 17:46:04 +02:00
%@test:13
%$ try
%$ data = transpose(0:1:50);
2013-10-18 17:38:43 +02:00
%$ ts = dseries(data,'1950Q1');
2013-09-05 17:46:04 +02:00
%$ 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);
2013-10-08 17:21:17 +02:00
%@eof:13
%@test:14
%$ try
%$ data = transpose(0:1:50);
2013-10-18 17:38:43 +02:00
%$ ts = dseries(data,'1950Q1');
2013-10-08 17:21:17 +02:00
%$ 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