« App/Chart/Series/Derived/Kirshenbaum.pm
↑ Summary
App/Chart/Series/Derived/MedianAverageAlpha.pm »
| 1 | # Copyright 2007, 2009, 2010, 2011 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Chart. | ||
| 4 | # | ||
| 5 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 6 | # terms of the GNU General Public License as published by the Free Software | ||
| 7 | # Foundation; either version 3, or (at your option) any later version. | ||
| 8 | # | ||
| 9 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 12 | # details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | |||
| 17 | package App::Chart::Series::Derived::LinRegSlope; | ||
| 18 | use 5.010; | ||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | use Carp; | ||
| 22 | use List::Util qw(min max); | ||
| 23 | use Locale::TextDomain ('App-Chart'); | ||
| 24 | |||
| 25 | use base 'App::Chart::Series::Indicator'; | ||
| 26 | use App::Chart::Series::Calculation; | ||
| 27 | use App::Chart::Series::Derived::SMA; | ||
| 28 | |||
| 29 | |||
| 30 | sub longname { __('Linear Regression Slope') } | ||
| 31 | sub shortname { __('Linreg Slope') } | ||
| 32 | sub manual { __p('manual-node','Linear Regression Slope') } | ||
| 33 | |||
| 34 | use constant | ||
| 35 | { type => 'indicator', | ||
| 36 | units => 'price-slope', | ||
| 37 | priority => -10, | ||
| 38 | hlines => [ 0 ], | ||
| 39 | minimum => 0, | ||
| 40 | parameter_info => [ { name => __('Days'), | ||
| 41 | key => 'linregslope_days', | ||
| 42 | type => 'integer', | ||
| 43 | minimum => 1, | ||
| 44 | default => 20 } ], | ||
| 45 | }; | ||
| 46 | |||
| 47 | sub new { | ||
| 48 | my ($class, $parent, $N) = @_; | ||
| 49 | |||
| 50 | $N //= parameter_info()->[0]->{'default'}; | ||
| 51 | ($N > 0) || croak "LinRegSlope bad N: $N"; | ||
| 52 | |||
| 53 | return $class->SUPER::new | ||
| 54 | (parent => $parent, | ||
| 55 | N => $N, | ||
| 56 | parameters => [ $N ], | ||
| 57 | arrays => { values => [] }, | ||
| 58 | array_aliases => { }); | ||
| 59 | } | ||
| 60 | *warmup_count = \&App::Chart::Series::Derived::SMA::warmup_count; # $N-1 | ||
| 61 | |||
| 62 | sub proc { | ||
| 63 | my ($class, $N) = @_; | ||
| 64 | my $linreg_proc = App::Chart::Series::Calculation->linreg($N); | ||
| 65 | return sub { | ||
| 66 | my ($y) = @_; | ||
| 67 | return ($linreg_proc->($y))[1]; | ||
| 68 | }; | ||
| 69 | } | ||
| 70 | |||
| 71 | 1; | ||
| 72 | __END__ |