


@info:
! @deftypefn {Function File} {@var{dd} =} dynDates (@var{a},@var{b},...)
! @anchor{dynDates}
! @sp 1
! Constructor for the Dynare dates class (unordered sequence of dates).
! @sp 2
! @strong{Inputs}
! @sp 1
! @table @ @var
! @item a
! String, date.
! @item b
! @end table
! @sp 2
! @strong{Outputs}
! @sp 1
! @table @ @var
! @item dd
! Dynare dates object.
! @end table
! @sp 1
! @strong{Properties}
! @sp 1
! The constructor defines the following properties:
! @sp 1
! @table @ @var
! @item ndate
! Scalar integer, the number of dates.
! @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 time
! Array of integers (nobs*2). The first column defines the years associated to each date. The second column,
! depending on the frequency, indicates the week, month or quarter numbers. For yearly data or unspecified frequency
! the second column is filled by ones.
! @end table
! @sp 2
! @strong{This function is called by:}
! @sp 2
! @strong{This function calls:}
!
! @end deftypefn
@eod:

0001 function dd = dynDates(varargin) 0002 0003 %@info: 0004 %! @deftypefn {Function File} {@var{dd} =} dynDates (@var{a},@var{b},...) 0005 %! @anchor{dynDates} 0006 %! @sp 1 0007 %! Constructor for the Dynare dates class (unordered sequence of dates). 0008 %! @sp 2 0009 %! @strong{Inputs} 0010 %! @sp 1 0011 %! @table @ @var 0012 %! @item a 0013 %! String, date. 0014 %! @item b 0015 %! @end table 0016 %! @sp 2 0017 %! @strong{Outputs} 0018 %! @sp 1 0019 %! @table @ @var 0020 %! @item dd 0021 %! Dynare dates object. 0022 %! @end table 0023 %! @sp 1 0024 %! @strong{Properties} 0025 %! @sp 1 0026 %! The constructor defines the following properties: 0027 %! @sp 1 0028 %! @table @ @var 0029 %! @item ndate 0030 %! Scalar integer, the number of dates. 0031 %! @item freq 0032 %! Scalar integer, the frequency of the time series. @var{freq} is equal to 1 if data are on a yearly basis or if 0033 %! frequency is unspecified. @var{freq} is equal to 4 if data are on a quaterly basis. @var{freq} is equal to 0034 %! 12 if data are on a monthly basis. @var{freq} is equal to 52 if data are on a weekly basis. 0035 %! @item time 0036 %! Array of integers (nobs*2). The first column defines the years associated to each date. The second column, 0037 %! depending on the frequency, indicates the week, month or quarter numbers. For yearly data or unspecified frequency 0038 %! the second column is filled by ones. 0039 %! @end table 0040 %! @sp 2 0041 %! @strong{This function is called by:} 0042 %! @sp 2 0043 %! @strong{This function calls:} 0044 %! 0045 %! @end deftypefn 0046 %@eod: 0047 0048 % Copyright (C) 2011 Dynare Team 0049 % 0050 % This file is part of Dynare. 0051 % 0052 % Dynare is free software: you can redistribute it and/or modify 0053 % it under the terms of the GNU General Public License as published by 0054 % the Free Software Foundation, either version 3 of the License, or 0055 % (at your option) any later version. 0056 % 0057 % Dynare is distributed in the hope that it will be useful, 0058 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0059 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0060 % GNU General Public License for more details. 0061 % 0062 % You should have received a copy of the GNU General Public License 0063 % along with Dynare. If not, see <http://www.gnu.org/licenses/>. 0064 0065 % AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT fr 0066 0067 dd = struct; 0068 0069 dd.ndat = []; 0070 dd.freq = []; 0071 dd.time = dynTime(); 0072 0073 dd = class(dd,'dynDates'); 0074 0075 switch nargin 0076 case 0 0077 % Returns an empty object 0078 return 0079 case 1 0080 if isa(varargin{1},'dynDates') 0081 % Returns a copy of the input argument 0082 dd = varargin{1}; 0083 elseif ischar(varargin{1}) 0084 tmp = dynDate(varargin{1}); 0085 dd.ndat = 1; 0086 dd.freq = tmp.freq; 0087 dd.time = tmp.time; 0088 else 0089 error('dynDates:: Wrong calling sequence of the constructor!') 0090 end 0091 otherwise 0092 tmp = dynDate(varargin{1}); 0093 dd.ndat = nargin; 0094 dd.time = NaN(dd.ndat,2); 0095 dd.freq = tmp.freq; 0096 dd.time(1,:) = tmp.time; 0097 for i=2:dd.ndat 0098 tmp = dynDate(varargin{i}); 0099 if ~isequal(dd.freq,tmp.freq) 0100 error(['dynDates:: The frequency declared in input argument number ' int2str(i) ' is different from the frequency declared in the first input argument!']) 0101 end 0102 dd.time(i,:) = tmp.time; 0103 end 0104 end 0105 0106 %@test:1 0107 %$ addpath ../matlab 0108 %$ 0109 %$ % Define some dates 0110 %$ B1 = '1945Q3'; 0111 %$ B2 = '1950Q2'; 0112 %$ B3 = '1950Q1'; 0113 %$ B4 = '1953Q4'; 0114 %$ 0115 %$ % Define expected results. 0116 %$ e.time = [1945 3; 1950 2; 1950 1; 1953 4]; 0117 %$ e.freq = 4; 0118 %$ e.ndat = 4; 0119 %$ 0120 %$ % Call the tested routine. 0121 %$ d = dynDates(B1,B2,B3,B4); 0122 %$ 0123 %$ % Check the results. 0124 %$ t(1) = dyn_assert(d.time,e.time); 0125 %$ t(2) = dyn_assert(d.freq,e.freq); 0126 %$ t(3) = dyn_assert(d.ndat,e.ndat); 0127 %$ T = all(t); 0128 %@eof:1 0129 0130 %@test:2 0131 %$ addpath ../matlab 0132 %$ 0133 %$ % Define some dates 0134 %$ B1 = '1945M3'; 0135 %$ B2 = '1950M2'; 0136 %$ B3 = '1950M10'; 0137 %$ B4 = '1953M12'; 0138 %$ 0139 %$ % Define expected results. 0140 %$ e.time = [1945 3; 1950 2; 1950 10; 1953 12]; 0141 %$ e.freq = 12; 0142 %$ e.ndat = 4; 0143 %$ 0144 %$ % Call the tested routine. 0145 %$ d = dynDates(B1,B2,B3,B4); 0146 %$ 0147 %$ % Check the results. 0148 %$ t(1) = dyn_assert(d.time,e.time); 0149 %$ t(2) = dyn_assert(d.freq,e.freq); 0150 %$ t(3) = dyn_assert(d.ndat,e.ndat); 0151 %$ T = all(t); 0152 %@eof:2 0153 0154 %@test:3 0155 %$ addpath ../matlab 0156 %$ 0157 %$ % Define some dates 0158 %$ B1 = '1945'; 0159 %$ B2 = '1950'; 0160 %$ B3 = '1950'; 0161 %$ B4 = '1953'; 0162 %$ 0163 %$ % Define expected results. 0164 %$ e.time = [1945 1; 1950 1; 1950 1; 1953 1]; 0165 %$ e.freq = 1; 0166 %$ e.ndat = 4; 0167 %$ 0168 %$ % Call the tested routine. 0169 %$ d = dynDates(B1,B2,B3,B4); 0170 %$ 0171 %$ % Check the results. 0172 %$ t(1) = dyn_assert(d.time,e.time); 0173 %$ t(2) = dyn_assert(d.freq,e.freq); 0174 %$ t(3) = dyn_assert(d.ndat,e.ndat); 0175 %$ T = all(t); 0176 %@eof:3 0177 0178 %@test:4 0179 %$ addpath ../matlab 0180 %$ 0181 %$ % Define some dates 0182 %$ B1 = '1945Q1'; 0183 %$ B2 = '1950Q3'; 0184 %$ B3 = '1950M10'; 0185 %$ B4 = '1953Q1'; 0186 %$ 0187 %$ 0188 %$ % Call the tested routine. 0189 %$ try 0190 %$ d = dynDates(B1,B2,B3,B4); 0191 %$ t(1) = 0; 0192 %$ T = 0; 0193 %$ catch 0194 %$ % Expected issue... 0195 %$ t(1) = 1; 0196 %$ T = 1; 0197 %$ end 0198 %@eof:4