python计算ema,简单的Python Pandas EMA(ewma)?

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.

7256a18c43b8ef534e91df91f3be1abc.png

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值