]> Creatis software - CreaPhase.git/blob - octave_packages/financial-0.4.0/lbusdate.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / financial-0.4.0 / lbusdate.m
1 ## Copyright (C) 2008 Bill Denney <bill@denney.ws>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {b =} lbusdate (year, month)
18 ## @deftypefnx {Function File} {b =} lbusdate (year, month, holiday)
19 ## @deftypefnx {Function File} {b =} lbusdate (year, month, holiday, weekend)
20 ##
21 ## Return the datenum of the last business day of the @var{year} and
22 ## @var{month}.  @var{holiday} is a vector of datenums that defines the
23 ## holidays observed (the holidays function is used if not given).
24 ## @var{weekend} defines the days of the week that should be considered
25 ## weekends; [1 0 0 0 0 0 1] (default) indicates that Sunday and
26 ## Saturday are holidays.
27 ##
28 ## If any of the optional inputs (@var{holiday}, @var{weekend}) are
29 ## empty, then the default is used.
30 ##
31 ## @seealso{holidays, fbusdate, isbusday, busdate}
32 ## @end deftypefn
33
34 function rd = lbusdate (y, m, hol, wkend)
35
36   rd = eomdate (y, m);
37   if nargin < 3
38         hol = [];
39   end
40   if nargin < 4
41         wkend = [];
42   elseif nargin < 3 || nargin > 4
43         print_usage ();
44   endif
45
46   ## Test from the day after the end of the month so that the
47   ## last day of the month is captured.
48   rd = busdate (rd+1, -1, hol, wkend);
49
50 endfunction
51
52 ## Tests
53 ## A normal day
54 %!assert(lbusdate(2008,4), datenum(2008,4,30))
55 ## A weekend
56 %!assert(lbusdate(2008,5), datenum(2008,5,30))