Calculate MA, SMA indicators in Pandas

Tiếp theo bài viết https://toan.co/prepare-dataset-for-backtest-strategy/ mình sẽ tính các chỉ số SMA, EMA trên Pandas

df['SMA7'] = df.Close.rolling(5).mean()
df['SMA14'] = df.Close.rolling(14).mean()

df['EMA10'] = df.Close.ewm(span=10, adjust=False).mean()
df['EMA20'] = df.Close.ewm(span=20, adjust=False).mean()

# plot
df.head(500)[['SMA7', 'SMA14', 'EMA10', 'EMA20']].plot(figsize=(15, 10))

Leave a Reply

Your email address will not be published. Required fields are marked *