简单的Python Pandas EMA(ewma)? [英] Simple Python Pandas EMA (ewma)?

查看:2490
本文介绍了简单的Python Pandas EMA(ewma)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些代码来构建自己的EMA/MACD,但决定尝试给熊猫做个尝试.

I wrote some code to build my own EMA/MACD, but have decided to give Pandas a try instead.

我将以下网站用作对EMA的基本了解,并尝试让熊猫给我相同的答案,以确保我正确使用了熊猫:

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:

http://stockcharts.com/school/doku.php ?id = chart_school:technical_indicators:moving_averages

这是图表,其中包含Im正在使用的数据.

And here is the chart with the data that Im working with.

这是我要开始使用的代码,但是它给我的输出与10天EMA列不同.

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)

我也没有运气尝试过.

pd.ewma(df, span=10, min_periods=10)

感谢您的帮助.

推荐答案

巧合的是,在这里提出并回答了这个问题:

Coincidentally, this question was asked and answered here: Does Pandas calculate ewm wrong?

在这里查看@chrisb的答案.按照您正在研究的文章中所述计算EWM:

Check out @chrisb's answer there. To compute the EWM as described in the article you're studying:

  1. 手动计算第一个有效的简单MA作为EWA的起点
  2. 使用adjust=False
  3. 运行熊猫的EWM
  1. manually compute the first valid simple MA to serve as a starting point for EWA
  2. run pandas' EWM with adjust=False

这篇关于简单的Python Pandas EMA(ewma)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆