Home > matlab > @dynDate > minus.m

minus

PURPOSE ^

@info:

SYNOPSIS ^

function c = minus(a,b)

DESCRIPTION ^

@info:
! @deftypefn {Function File} {@var{c} =} minus (@var{a},@var{b})
! @anchor{@dynDate/minus}
! @sp 1
! Overloads the minus (soustraction) operator for the Dynare dates class (@ref{dynDate}). Depending on the frequency, computes the number
! of years, quarters, months, weeks between two dates @var{a} and @var{b} (it is assumed that @var{a}>@var{B}).
! @sp 2
! @strong{Inputs}
! @sp 1
! @table @ @var
! @item a
! Dynare date object instantiated by @ref{dynDate}.
! @item b
! Dynare date object instantiated by @ref{dynDate}.
! @end table
! @sp 1
! @strong{Outputs}
! @sp 1
! @table @ @var
! @item c
! Integer scalar, the number of years, quarters, months or weeks between @var{a} and @var{B}.
! @end table
! @sp 2
! @strong{This function is called by:}
! @sp 2
! @strong{This function calls:}
! @ref{@@dynDate/eq},@ref{@@dynDate/lt}
!
! @end deftypefn
@eod:

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function c = minus(a,b)
0002 
0003 %@info:
0004 %! @deftypefn {Function File} {@var{c} =} minus (@var{a},@var{b})
0005 %! @anchor{@dynDate/minus}
0006 %! @sp 1
0007 %! Overloads the minus (soustraction) operator for the Dynare dates class (@ref{dynDate}). Depending on the frequency, computes the number
0008 %! of years, quarters, months, weeks between two dates @var{a} and @var{b} (it is assumed that @var{a}>@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 %! Dynare date object instantiated by @ref{dynDate}.
0017 %! @end table
0018 %! @sp 1
0019 %! @strong{Outputs}
0020 %! @sp 1
0021 %! @table @ @var
0022 %! @item c
0023 %! Integer scalar, the number of years, quarters, months or weeks between @var{a} and @var{B}.
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},@ref{@@dynDate/lt}
0030 %!
0031 %! @end deftypefn
0032 %@eod:
0033 
0034 % Copyright (C) 2011 Dynare Team
0035 % stephane DOT adjemian AT univ DASH lemans DOT fr
0036 %
0037 % This file is part of Dynare.
0038 %
0039 % Dynare is free software: you can redistribute it and/or modify
0040 % it under the terms of the GNU General Public License as published by
0041 % the Free Software Foundation, either version 3 of the License, or
0042 % (at your option) any later version.
0043 %
0044 % Dynare is distributed in the hope that it will be useful,
0045 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0046 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0047 % GNU General Public License for more details.
0048 %
0049 % You should have received a copy of the GNU General Public License
0050 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0051 
0052 if ~( isa(a,'dynDate') && isa(b,'dynDate') )
0053     error(['dynDate::minus: Input arguments ' inputname(1) ' and ' inputname(2) ' must be dynDate objects!'])
0054 end
0055 
0056 if a.freq~=b.freq
0057     error(['dynDate::minus: ' inputname(1) ' and ' inputname(2) ' must have common frequency!'])
0058 end
0059 
0060 if a<b
0061     error(['dynDate::minus: ' inputname(1) ' must be posterior to ' inputname(2) '!'])
0062 end
0063 
0064 if a==b
0065     c = 0;
0066     return
0067 end
0068 
0069 switch a.freq
0070   case 1
0071     c = a.time(1)-b.time(1);
0072   case {4,12,52}
0073     c = a.time(2)-b.time(2) + (a.time(1)-b.time(1))*a.freq;
0074   otherwise
0075     error('dynDate::minus: Unknown frequency!')
0076 end
0077 
0078 %@test:1
0079 %$ addpath ../matlab
0080 %$
0081 %$ % Define some dates
0082 %$ date_0_1 = 1950;
0083 %$ date_0_2 = 1950;
0084 %$ date_0_3 = 1940;
0085 %$ date_1_1 = '1950Q4';
0086 %$ date_1_2 = '1950Q1';
0087 %$ date_1_3 = '1940Q3';
0088 %$ date_2_1 = '2000M3';
0089 %$ date_2_2 = '1998M8';
0090 %$
0091 %$ % Call the tested routine.
0092 %$ d_0_1 = dynDate(date_0_1);
0093 %$ d_0_2 = dynDate(date_0_2);
0094 %$ d_0_3 = dynDate(date_0_3);
0095 %$ d_1_1 = dynDate(date_1_1);
0096 %$ d_1_2 = dynDate(date_1_2);
0097 %$ d_1_3 = dynDate(date_1_3);
0098 %$ d_2_1 = dynDate(date_2_1);
0099 %$ d_2_2 = dynDate(date_2_2);
0100 %$ e1 = d_0_1-d_0_2;
0101 %$ e2 = d_0_1-d_0_3;
0102 %$ e3 = d_1_1-d_1_2;
0103 %$ e4 = d_1_1-d_1_3;
0104 %$ e5 = d_2_1-d_2_2;
0105 %$
0106 %$ % Check the results.
0107 %$ t(1) = dyn_assert(e1,0);
0108 %$ t(2) = dyn_assert(e2,10);
0109 %$ t(3) = dyn_assert(e3,3);
0110 %$ t(4) = dyn_assert(e4,41);
0111 %$ t(4) = dyn_assert(e5,19);
0112 %$ T = all(t);
0113 %@eof:1

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