I am trying to copy the functionality of classical EMA from trading. In trading view DOCS they say for EMA:
It calculates by sing a formula: EMA = alpha * x + (1 - alpha) * EMA[1], where alpha = 2 / (y + 1)
But what do I provide to EWM of Pandas as alpha (or span?) param to have the same computation?
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.ewm.html
If not possible to compute it via Pandas, how to do it via Numpy?
=================================
Edit:
So it should be simple as:
serie.ewm(span=window, adjust=False, ignore_na=True).mean()
But for some strange reason it computes different values than the Tradingview indicator.. I even checked the input values. Really strange, i can't understand it.
The numbers are same like for window smaller than 3 but then it starts get different.
Like TV.EMA(3) = PD.EMA(3) but TV.EMA(6) != PD.EMA(6). crazy..
Edit: I added some sample data.
**`Note: i am displaying EMA for last 3 values only`**
input:
1.9646
1.9441
1.9296
1.8883
1.8916
1.9277
tradingview EMA(3): (given unlimited inputs)
1.91471466
1.90315733
1.91542866
pandas EMA(3): (given 49 inputs)
1.914715
1.903157
1.915429
pandas EMA(3): (given 3 inputs)
1.888300
1.889950
1.908825
==========
tradingview EMA(6): (given unlimited inputs)
1.93477990
1.92244279
1.92394485
pandas EMA(6): (given 96 inputs)
1.934780
1.922443
1.923945
pandas EMA(6): (given 6 inputs)
1.932669
1.920935
1.922868
==========
tradingview EMA(20): (given unlimited inputs)
1.95649590
1.95031533
1.94816149
pandas EMA(20): (given 20 inputs)
1.953533
1.944004
1.941496
pandas EMA(20): (given 40 inputs)
1.953454
1.943938
1.941440
pandas EMA(20): (given 320 inputs)
1.953483
1.943962
1.941461
So 3 new questions:
- How to know, how much input is required for EMA(N) - I was thinking it could be N * 2 to have also data for first input (maybe more N*2-1) - but doesn't work for EMA(20) obviously.
- Why there is only 6 precision computation out of Pandas. What if i need better precision eg to 8 numbers.
- EMA(20) obviously doesn't work well, while lower ema works (if rounded to 6)
How i compute it with pandas:
period = 6, 20 etc
t = c.ewm(span=period, adjust=False, ignore_na=True).mean()