I wrote some code to build my own EMA/MACD, but have decided to give Pandas a try instead.
I am using this website below as a basic understanding of EMA and trying to get pandas to give me the same answers to be sure I am using pandas correctly:
And here is the chart with the data that Im working with.
Here is the code I'm trying to get to work, but it gives me different output than the 10-day EMA column
import pandas as pd
data=[22.27,22.19,22.08,22.17,22.18,22.13,22.23,22.43,22.24,22.29,22.15,22.39,22.38,22.61,23.36,24.05,23.75,23.83]
df=pd.Series(data)
pd.ewma(df, span=10)
I've also tried this with no luck.
pd.ewma(df, span=10, min_periods=10)
Any help is appreciated.
解决方案
Coincidentally, this question was asked and answered here: Does Pandas calculate ewm wrong?
Check out @chrisb's answer there. To compute the EWM as described in the article you're studying:
manually compute the first valid simple MA to serve as a starting point for EWA
run pandas' EWM with adjust=False