]> Creatis software - CreaPhase.git/blob - octave_packages/financial-0.4.0/hhigh.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / financial-0.4.0 / hhigh.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} {@var{hhv} =} hhigh (@var{data})
18 ## @deftypefnx {Function File} {@var{hhv} =} hhigh (@var{data}, @var{nperiods})
19 ## @deftypefnx {Function File} {@var{hhv} =} hhigh (@var{data}, @var{nperiods}, @var{dim})
20 ##
21 ## Compute the highest high value of @var{data} for the past
22 ## @var{nperiods} (default: 14) across the dimension, @var{dim}
23 ## (default: 1).
24 ##
25 ## @seealso{llow}
26 ## @end deftypefn
27
28 function hhv = hhigh (data, nperiods = 14, dim = find (size (data) > 1, 1))
29
30   if nargin < 1 || nargin > 3
31     print_usage ();
32   elseif ! isvector (data)
33     ## FIXME
34     error ("cannot yet handle more than one dimensional data")
35   endif
36
37   if dim > ndims (data)
38     error ("dim cannot be greater than the number of dimensions in data");
39   endif
40
41   sz  = size (data);
42   hhv = data;
43   for i = 1:sz(dim)
44     hhv(i) = max (data(max (i-nperiods+1, 1):i));
45   endfor
46
47 endfunction
48
49 ## Tests
50 %!shared c, h
51 %! c = [22.44 22.61 22.67 22.88 23.36 23.23 23.08 22.86 23.17 23.69 23.77 23.84 24.32 24.8 24.16 24.1 23.37 23.61 23.21 25];
52 %! h = [22.44 22.61 22.67 22.88 23.36 23.36 23.36 23.36 23.36 23.69 23.77 23.84 24.32 24.8 24.8 24.8 24.8 24.8 24.8 25];
53 %!assert(hhigh(c), h)
54 %!assert(hhigh(c'), h')