1 ## Copyright (C) 2008 Bill Denney <bill@denney.ws>
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
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
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/>.
17 ## @deftypefn {Function File} {[begindate, enddate]} = thirdwednesday (month, year)
19 ## Find the third Wednesday of the month specified by the @var{month}
20 ## and @var{year}. The @var{begindate} is the third Wednesday of the
21 ## month, and the @var{enddate} is three months after that. Outputs are
22 ## in the form of datenums.
24 ## The third Wednesday is used for Eurodollar futures.
26 ## @seealso{nweekdate, datenum}
29 function [wednesdays, enddate] = thirdwednesday (month, year)
33 elseif ~ ((numel(year) == 1) ||
34 (numel(month) == 1) ||
35 ~isequal (size (month), size (year)))
36 error("month and year must have the same size or one of them must be a scalar")
45 wednesdays = nweekdate (3, 4, year, month);
46 dates = datevec (wednesdays);
47 ## adjust the year when the date will wrap
48 dates(:,1) += dates (:,2) > 9;
49 ## adjust the month by three
50 dates(:,2) = mod (dates(:,2) + 2, 12) + 1;
51 enddate = reshape (datenum (dates), sz);
59 %! bt = datenum(2008, m, [16;20;19;16;21;18;16;20;17;15;19;17]);
60 %! et = datenum([2008*ones(9,1);2009*ones(3,1)], [4:12 1:3]', [16;20;19;16;21;18;16;20;17;15;19;17]);
62 %! [b e] = thirdwednesday (m, y);
66 %! [b e] = thirdwednesday (m', y);