使用 Pandas 的指数加权移动平均线

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42455251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 03:04:04  来源:igfitidea点击:

Exponential Weighted Moving Average using Pandas

pythonpandasexponential

提问by spin_cycle

I need to confirm few thing related to pandas exponential weighted moving average function.

我需要确认一些与Pandas指数加权移动平均函数相关的事情。

If I have a data set df for which I need to find a 12 day exponential moving average, would the method below be correct.

如果我有一个数据集 df 需要为其找到 12 天指数移动平均线,那么下面的方法是否正确。

exp_12=df.ewm(span=20,min_period=12,adjust=False).mean()

Given the data set contains 20 readings the span (Total number of values) should equal to 20.

鉴于数据集包含 20 个读数,跨度(值的总数)应等于 20。

Since I need to find a 12 day moving average hence min_period=12. I interpret span as total number of values in a data set or the total time covered.

由于我需要找到 12 天移动平均线,因此 min_period=12。我将跨度解释为数据集中值的总数或涵盖的总时间。

Can someone confirm if my above interpretation is correct? I can't get the significance of adjust.

有人可以确认我的上述解释是否正确吗?我无法理解调整的意义。

I've attached the link to pandas.df.ewm documentation below.

我已将链接附加到下面的 pandas.df.ewm 文档。

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ewm.html

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ewm.html

回答by spin_cycle

Quoting from Pandas docs: Span corresponds to what is commonly called an “N-day EW moving average”.

引自Pandas 文档:跨度对应于通常所说的“N 天 EW 移动平均线”。

In your case, set span=12. You do not need to specify that you have 20 datapoints, pandas takes care of that. min_period may not be required here.

在您的情况下,设置 span=12。您不需要指定您有 20 个数据点,pandas 会处理这些。此处可能不需要 min_period。