TA-Lib / ta-lib-python

Python wrapper for TA-Lib (http://ta-lib.org/).
http://ta-lib.github.io/ta-lib-python
Other
9.79k stars 1.78k forks source link

Re: EMA indicator calculation #632

Open akaulgud1 opened 11 months ago

akaulgud1 commented 11 months ago

Hello,

I have installed TA-LIB for Python.

I calculated EMA for 5 and 50 period against 6 months and 1 year data.

Couple of observations:

  1. value for 50EMA differs when I use 6 months data v/s 1 year data
  2. when compared with 50 EMA on investing.com, 50 ema calculated is not accurate , deviates by 10-12 points on higher side.

could you please look into this and advise.

Here is the code 5-50-setup.txt

Here are data files RELIANCE-updated-using-1year-data.xlsx RELIANCE-updated-using-6-months-data.csv

mario4tier commented 1 week ago

This is expected.

With the EMA algo, each new EMA uses the previous EMA. The function is in a sense "recursive". Depending how many previous data were fed to the function, the output will vary.

It is quite common for users to get confuse by this, and the EMA (and many algo using EMA) from many website/app do not disclose how they handle this. Many generally just assume that a popular website has to be "correct".

In the case of TA-Lib, there is a feature (named "unstable period") that allows devs to reduce (and control) such variance. The variance progressively reduce as there is more output... so the trick is for the function to start outputing only after the variance is "reasonably" low.

This is a complex subject, will let you digest this for a while, may be starting with understanding why EMA is "unstable" :smile:

====

If this is too complicated, then just feed to the function as much input that you have... and accept that when you provide less input, the output will have a lot of variance in the first few outputs (and it gets more consistent as there is more output produced).