]> Creatis software - CreaPhase.git/blob - octave_packages/financial-0.4.0/llow.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / financial-0.4.0 / llow.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{llv} =} llow (@var{data})
18 ## @deftypefnx {Function File} {@var{llv} =} llow (@var{data}, @var{nperiods})
19 ## @deftypefnx {Function File} {@var{llv} =} llow (@var{data}, @var{nperiods}, @var{dim})
20 ##
21 ## Compute the lowest low value of @var{data} for the past
22 ## @var{nperiods} (default: 14) across the dimension, @var{dim}
23 ## (default: 1).
24 ##
25 ## @seealso{hhigh}
26 ## @end deftypefn
27
28 function llv = llow (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   elseif dim > ndims (data)
36     error ("dim cannot be greater than the number of dimensions in data");
37   endif
38
39   sz  = size (data);
40   llv = data;
41   for i = 1:sz(dim)
42     llv(i) = min (data(max (i-nperiods+1, 1):i));
43   endfor
44
45 endfunction
46
47 ## Tests
48 %!shared c, l
49 %! 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];
50 %! l = [22.44 22.44 22.44 22.44 22.44 22.44 22.44 22.44 22.44 22.44 22.44 22.44 22.44 22.44 22.61 22.67 22.86 22.86 22.86 22.86];
51 %!assert(llow(c), l)
52 %!assert(llow(c'), l')