[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GT] Re: Re: Re: Re: Re: EMA incorrect when using --nb-item
Guys,
please, you are just speculating rather than studying the code.
Here is how EMA works:
You decide how many days you want to calculate the EMA over. You can
determine this by using --nb-item, --start, --end, --full. It does not
matter. In any case you end up with a number of days, N, that you want
to evaluate the EMA over.
Now say you want to get a 200 day EMA, and you decided that N is 10. To
get the EMA for the first day you would have to have already 200 days
before that, and in the case of EMA theoretically infinitely many, as
the EMA does not really stop. The way GT handles this is that on the
first day it uses the 200 day SMA (or whatever you give it as the third
argument, see the documentation). The next day, it uses the EMA formula
alpha = 2 / ( N + 1 )
EMA[n] = EMA[n-1] + alpha * ( INPUT - EMA[n-1] )
and so on for every day up to N.
If you set --nb-item=1, this is obviously not very precise, as it gives
you the same as the SMA.
As far as I know, every other tool handles the EMA the same way. The
difference comes in when you compare to say, stockcharts.com. There you
have no control over the number of days you evaluate the EMA over, maybe
they use 100 days or 1000 days or whatever. But the value of EMA depends
critically on how many days you evaluate over, due to its definition.
I am confident that EMA in GT is defined correctly, and will give you
the same results as other tools, assuming you test for the same data.
Just to illustrate, if you compute the EMA(200) of SPY, you will get,
for different sized intervals:
1 = 110.7929
200 = 108.0074
400 = 109.0458
600 = 108.9586
800 = 108.9507
1000 = 108.9509
As you can see, it settles down eventually. But the key to understand
here is that EMA will give you a different value depending on the number
of data items you examine. That is why I don't like to use EMA, unless I
look at at least 5 years of data. At a minimum, you should use at least
as much data as the period of the EMA.
Please study the definition of EMA and the code, GT::Indicators::EMA,
and this will all make sense.
Again, if you don't like to use SMA for the initial value of EMA, you
can give it any other indicator as an argument.
And, one more thing, --nb-item is no different from --start or --end.
All you do is select how many data items you are interested in.
Best regards, Th.
On 07/22/2010 09:58 PM, Nick Fantes Huege wrote:
> I did some more testing with --nb-item, but I only got more confused.
> I think we should not use it at all. It seems, as RAS said, it is only
> useful in graphic.pl, but it can be specifically added there.
> I would even go further as to suggest its complete removal from
> Tools::find_calculator, to avoid any confusion and wrong results, but
> I guess that may be a bit too harsh.
>
> Regards,
> Nick
>
>