On Jul 19, 4:40 pm, Jim <
jimyu...@gmail.com> wrote:
> It has 22 data and bollinger bands numbers are:
> BB: 3.60824863529101 < 6.15 < 8.69175136470899.
>
> I think the first two numbers (3 and 4) should not count.
Probably.
my $bb = Math::Business::BollingerBands->new(20);
$bb->insert( (5) x 27 );
my(undef,$mean,undef) = $bb->query;
# I'm getting 5 like I should
$bb->insert(7,7);
(undef,$mean,undef) = $bb->query;
# I'm getting 5.2 like I should
> I removed the first two numbers, I got this result:
> BB: 3.7604393709303 < 6.15 < 8.5395606290697.
How did you "remove" them? There isn't really an interface for that.
This module automatically shifts irrelevant data from the data store
on insert, so inserting extra values likely has little effect.
use Statistics::Basic qw(mean);
# Note that while this
mean(qw(3 4 4 5 6 5 6 5 5 5 5 6 6 6 6 7 7 7 8 8 8 8));
# returns 5.91
# and this
mean(qw(4 5 6 5 6 5 5 5 5 6 6 6 6 7 7 7 8 8 8 8));
# returns 6.51,
# this
$bb->insert(qw(3 4 4 5 6 5 6 5 5 5 5 6 6 6 6 7 7 7 8 8 8 8))
(undef,$mean,undef) = $bb->query;
# $mean is 6.15
$bb->insert(qw(4 5 6 5 6 5 5 5 5 6 6 6 6 7 7 7 8 8 8 8))
(undef,$mean,undef) = $bb->query;
# $mean is 6.15
In order to use those two extra values, you'd have to increase the
size of the bands from 20 days to 22 days.
> For what I understand, the standard deviation should be calculated in
> the past 20 days, the same days as you calculate average. So the extra
> two days' data should not matter.
They don't appear to.
> Let me know if I understand it wrong. Otherwise, it's a bug.
Likewise.