colon.m 3.17 KB
Newer Older
Stéphane Adjemian's avatar
Stéphane Adjemian committed
1
2
3
4
function sp = colon(a,b)

%@info:
%! @deftypefn {Function File} {@var{sp} =} colon (@var{a},@var{b})
5
%! @anchor{@dynDate/colon}
Stéphane Adjemian's avatar
Stéphane Adjemian committed
6
%! @sp 1
7
%! Overloads the colon operator for the Dynare Dates class (@ref{dynDate}). Creates a @ref{dynDates} object.
Stéphane Adjemian's avatar
Stéphane Adjemian committed
8
9
10
11
12
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item a
13
%! Dynare date object instantiated by @ref{dynDate}, initial date.
Stéphane Adjemian's avatar
Stéphane Adjemian committed
14
%! @item b
15
%! Dynare date object instantiated by @ref{dynDate}, last date.
Stéphane Adjemian's avatar
Stéphane Adjemian committed
16
17
18
19
20
21
%! @end table
%! @sp 1
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item c
22
%! Dynare Dates object instantiated by @ref{dynDates}.
Stéphane Adjemian's avatar
Stéphane Adjemian committed
23
24
25
26
27
%! @end table
%! @sp 2
%! @strong{This function is called by:}
%! @sp 2
%! @strong{This function calls:}
28
%! @ref{dynDates}, @ref{@@dynDates/setFreq}, @ref{@@dynDates/setTime}, @ref{@@dynDates/setSize}
Stéphane Adjemian's avatar
Stéphane Adjemian committed
29
30
31
32
%!
%! @end deftypefn
%@eod:

Sébastien Villemot's avatar
Sébastien Villemot committed
33
% Copyright (C) 2011-2013 Dynare Team
Stéphane Adjemian's avatar
Stéphane Adjemian committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%
% 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
51
    error('dynDate::colon: I need exactly two input arguments!')
Stéphane Adjemian's avatar
Stéphane Adjemian committed
52
53
end

54
if ~( isa(a,'dynDate') && isa(b,'dynDate'))
Stéphane Adjemian's avatar
Stéphane Adjemian committed
55
    error(['dynDate::colon: Input arguments ' inputname(1) 'and ' inputname(2) ' have to be a dynDate objects!'])
Stéphane Adjemian's avatar
Stéphane Adjemian committed
56
57
58
end

if a.freq~=b.freq
Stéphane Adjemian's avatar
Stéphane Adjemian committed
59
    error(['dynDate::colon: Input arguments ' inputname(1) 'and ' inputname(2) ' must have common frequency!'])
Stéphane Adjemian's avatar
Stéphane Adjemian committed
60
61
62
end

if a>b
Stéphane Adjemian's avatar
Stéphane Adjemian committed
63
    error(['dynDate::colon: ' inputname(1) ' must precede ' inputname(2) '!' ])
Stéphane Adjemian's avatar
Stéphane Adjemian committed
64
65
end

66
67
68
69
70
sp = dynDates(a);
n = b-a;
for t=1:n
    a = +a;
    sp = sp.append(a);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
71
72
73
74
75
76
77
78
79
80
81
82
end

%@test:1
%$ % Define two dates
%$ date_1 = '1950Q2';
%$ date_2 = '1951Q4';
%$
%$ % Define expected results.
%$ e.freq = 4;
%$ e.time = [1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4];
%$
%$ % Call the tested routine.
83
84
%$ d1 = dynDate(date_1);
%$ d2 = dynDate(date_2);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
85
86
87
88
89
90
91
%$ d3 = d1:d2;
%$
%$ % Check the results.
%$ t(1) = dyn_assert(d3.time,e.time);
%$ t(2) = dyn_assert(d3.freq,e.freq);
%$ T = all(t);
%@eof:1
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

%@test:2
%$ % Create an empty dynDate object
%$ date = dynDate();
%$
%$ % Define expected results.
%$ e.freq = 4;
%$ e.time = [1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4];
%$
%$ % Call the tested routine.
%$ d = date('1950Q2'):date('1951Q4');
%$
%$ % Check the results.
%$ t(1) = dyn_assert(d.time,e.time);
%$ t(2) = dyn_assert(d.freq,e.freq);
%$ T = all(t);
%@eof:2

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
%@test:3
%$ % Create an empty dynDate object for quaterly data
%$ qq = dynDate('Q');
%$
%$ % Define expected results.
%$ e.freq = 4;
%$ e.time = [1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4];
%$
%$ % Call the tested routine.
%$ d = qq(1950,2):qq(1951,4);
%$
%$ % Check the results.
%$ t(1) = dyn_assert(d.time,e.time);
%$ t(2) = dyn_assert(d.freq,e.freq);
%$ T = all(t);
%@eof:3