App/Chart/Series/Derived/FOSC.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 85 CC 3 SCAR 13.3
CC
3
Cov
0%
proc
12.0
longname
2.0
shortname
2.0
CRAP 3.8
1 # Copyright 2007, 2009, 2010 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::FOSC;
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 # http://store.traders.com/-v10-c05-forcast-pdf.html
30 # Abstract of TASC May 1992 article, rest for sale.
31 #
32 # http://trader.online.pl/MSZ/e-w-Chandes_Forecast_Oscillator_I.html
33 # Formula, text of TASC article.
34 #
35 # http://www.fmlabs.com/reference/ForecastOscillator.htm
36 #
37 # https://www.stockworm.com/do/community/manual;jsessionid=8F865CC4F15C7E055E0A62A865AF7415?chapter=forecast-oscillator
38 # Sample Oracle (ORCL), year not marked but is 2003.
39 #
40 # http://www.prophet.net/analyze/popglossary.jsp?studyid=FOSC
41 # Sample chart of Peoplesoft (symbol PSFT maybe, since taken over).
42 #
43 # http://www.paritech.com/paritech-site/education/technical/indicators/trend/forecast.asp
44 # Sample chart of Dollar Sweets, Australia (delisted after a takeover a
45 # long time ago ... what symbol was it?).
46 #
47 # http://trader.online.pl/MSZ/e-st-Forecast_Oscillator.html
48 # Trading system by Steve Karnish.
49 #
50  
51  
52 sub longname { __('Forecast Oscillator %F') }
53 sub shortname { __('FOSC') }
54 sub manual { __p('manual-node','Forecast Oscillator') }
55  
56 use constant
57 { type => 'indicator',
58 units => 'roc_percent',
59 priority => -10,
60 hlines => [ 0 ],
61 minimum => 0,
62 parameter_info => [ { name => __('Days'),
63 key => 'forecastosc_days',
64 type => 'integer',
65 minimum => 1,
66 default => 5 } ],
67 };
68  
69 sub new {
70 my ($class, $parent, $N) = @_;
71  
72 $N //= parameter_info()->[0]->{'default'};
73 ($N > 0) || croak "FOSC bad N: $N";
74  
75 return $class->SUPER::new
76 (parent => $parent,
77 N => $N,
78 parameters => [ $N ],
79 arrays => { values => [] },
80 array_aliases => { });
81 }
82 *warmup_count = \&App::Chart::Series::Derived::SMA::warmup_count; # $N-1
83  
84 sub proc {
85 my ($class, $N) = @_;
86 my $linreg_proc = App::Chart::Series::Calculation->linreg($N);
87 my $prev;
88 return sub {
89 my ($value) = @_;
90 my $fosc;
91 if (defined $prev) {
92 my ($a, $b) = $linreg_proc->($prev);
93 if ($value != 0) {
94 # $a is for prev point, $a+$b is forecast for today
95 $fosc = 100.0 * ($value - ($a + $b)) / $value;
96 }
97 }
98 $prev = $value;
99 return $fosc;
100 };
101 }
102  
103 1;
104 __END__