]> Creatis software - CreaPhase.git/blob - octave_packages/financial-0.4.0/fbusdate.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / financial-0.4.0 / fbusdate.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 =} fbusdate (year, month)
18 ## @deftypefnx {Function File} {b =} fbusdate (year, month, holiday)
19 ## @deftypefnx {Function File} {b =} fbusdate (year, month, holiday, weekend)
20 ##
21 ## Return the datenum of the first 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, lbusdate, isbusday, busdate}
32 ## @end deftypefn
33
34 function rd = fbusdate (y, m, hol, wkend)
35
36   rd = datenum (y, m, 1);
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 before the beginning of the month so that the
47   ## first 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(fbusdate(2008,2), datenum(2008,2,1))
55 ## A holiday
56 %!assert(fbusdate(2008,1), datenum(2008,1,2))
57 ## A weekend
58 %!assert(fbusdate(2008,3), datenum(2008,3,3))