Home > matlab > @dynDate > plus.m

plus

PURPOSE ^

@info:

SYNOPSIS ^

function c = plus(a,b)

DESCRIPTION ^

@info:
! @deftypefn {Function File} {@var{c} =} plus (@var{a},@var{b})
! @anchor{@dynDate/plus}
! @sp 1
! Overloads the plus (addition) operator for the Dynare dates class (@ref{dynDate}). Given an initial date @var{a},
! computes a new date @var{c} by adding the number of periods @var{b}.
! @sp 2
! @strong{Inputs}
! @sp 1
! @table @ @var
! @item a
! Dynare date object instantiated by @ref{dynDate}.
! @item b
! Positive scalar integer, the number of periods
! @end table
! @sp 2
! @strong{Outputs}
! @sp 1
! @table @ @var
! @item c
! Dynare date object instantiated by @ref{dynDate}.
! @end table
! @sp 2
! @strong{This function is called by:}
! @sp 2
! @strong{This function calls:}
! @ref{@@dynDate/eq}
!
! @end deftypefn
@eod:

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function c = plus(a,b)
0002 
0003 %@info:
0004 %! @deftypefn {Function File} {@var{c} =} plus (@var{a},@var{b})
0005 %! @anchor{@dynDate/plus}
0006 %! @sp 1
0007 %! Overloads the plus (addition) operator for the Dynare dates class (@ref{dynDate}). Given an initial date @var{a},
0008 %! computes a new date @var{c} by adding the number of periods @var{b}.
0009 %! @sp 2
0010 %! @strong{Inputs}
0011 %! @sp 1
0012 %! @table @ @var
0013 %! @item a
0014 %! Dynare date object instantiated by @ref{dynDate}.
0015 %! @item b
0016 %! Positive scalar integer, the number of periods
0017 %! @end table
0018 %! @sp 2
0019 %! @strong{Outputs}
0020 %! @sp 1
0021 %! @table @ @var
0022 %! @item c
0023 %! Dynare date object instantiated by @ref{dynDate}.
0024 %! @end table
0025 %! @sp 2
0026 %! @strong{This function is called by:}
0027 %! @sp 2
0028 %! @strong{This function calls:}
0029 %! @ref{@@dynDate/eq}
0030 %!
0031 %! @end deftypefn
0032 %@eod:
0033 
0034 % Copyright (C) 2011 Dynare Team
0035 %
0036 % This file is part of Dynare.
0037 %
0038 % Dynare is free software: you can redistribute it and/or modify
0039 % it under the terms of the GNU General Public License as published by
0040 % the Free Software Foundation, either version 3 of the License, or
0041 % (at your option) any later version.
0042 %
0043 % Dynare is distributed in the hope that it will be useful,
0044 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0045 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0046 % GNU General Public License for more details.
0047 %
0048 % You should have received a copy of the GNU General Public License
0049 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0050 
0051 % AUTHORS(S) stephane DOT adjemian AT univ DASH lemans DOT fr
0052 
0053 if ~isa(a,'dynDate')
0054     error(['dynDate::plus: Input argument ' inputname(1) ' must be a dynDate object!'])
0055 end
0056 
0057 if b<0 || ~isint(b)
0058     error(['dynDate::plus: Input argument ' inputname(2) ' must be a positive integer'])
0059 end
0060 
0061 
0062 if b==0
0063     c = a;
0064     return
0065 end
0066 
0067 switch a.freq
0068   case 1
0069     c = a;
0070     c.time(1) = a.time(1) + b - 1;
0071   case {4,12,52}
0072     c = a;
0073     n1 = b;
0074     n2 = floor(n1/a.freq);
0075     n3 = mod(n1,a.freq);
0076     c.time(2) = c.time(2)+n3-1;
0077     c.time(1) = c.time(1)+n2;
0078   otherwise
0079     error('dynDate::plus: Unknown frequency!')
0080 end
0081 
0082 %@test:1
0083 %$ addpath ../matlab
0084 %$
0085 %$ % Define some dates
0086 %$ date_1 = 1950;
0087 %$ date_2 = '1950Q4';
0088 %$ date_3 = '2000M3';
0089 %$
0090 %$ % Call the tested routine.
0091 %$ d_1 = dynDate(date_1);
0092 %$ d_2 = dynDate(date_2);
0093 %$ d_3 = dynDate(date_3);
0094 %$
0095 %$ d1 = d_1+3;
0096 %$ d2 = d_2+5;
0097 %$ d3 = d_3+15;
0098 %$ d4 = d_3+10;
0099 %$
0100 %$ % Expected results.
0101 %$ e1 = dynDate(1952);
0102 %$ e2 = dynDate('1951Q4');
0103 %$ e3 = dynDate('2001M5');
0104 %$ e4 = dynDate('2000M12');
0105 %$
0106 %$ % Check the results.
0107 %$ t(1) = dyn_assert(e1.time,d1.time);
0108 %$ t(2) = dyn_assert(e2.time,d2.time);
0109 %$ t(3) = dyn_assert(e3.time,d3.time);
0110 %$ t(4) = dyn_assert(e4.time,d4.time);
0111 %$ T = all(t);
0112 %@eof:1

Generated on Fri 18-May-2012 02:41:00 by m2html © 2005