- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 pandas 计算 EWMA,但结果不是我所期望的。我认为第 4 个元素应该是 13.179,但 pandas 给出了 13.121。我通过 documentation 中指定的公式将衰减因子 (a) 转换为质心.我是不是误会了什么?
In[222]: y
Out[222]:
0 NaN
1 NaN
2 13.192161
3 13.109292
4 12.623850
5 12.150520
Name: data, dtype: float64
In[223]: pd.ewma(y, com = 1.0 / a - 1)
Out[223]:
0 NaN
1 NaN
2 13.192161
3 13.120667
4 12.701206
5 12.237839
dtype: float64
In[224]: a
Out[224]: 0.8408964152537145
In[225]: a * 13.192161 + (1 - a) * 13.109292
Out[225]: 13.17897624503566
最佳答案
因为文档说
a = com/(1 + com)
由此可见
com = a/(1.0-a)
(对于 0 <= a < 1)。
此外,对开始期间计算的值进行了调整 "to account for imbalance in relative weightings" .确认公式
让我们关闭该调整:
z = pd.ewma(x, com=a/(1.0-a), adjust=False)
print(z)
然后打印
0 NaN
1 NaN
2 2.098920
3 3.850710
4 5.246548
5 6.344995
这个结果可以通过计算来模拟
import pandas as pd
import numpy as np
import numpy.testing.utils as NTU
nan = np.nan
x = pd.Series([nan, nan, nan, 13.109292, 12.623850, 12.150520])
a = 0.8408964152537145
z = pd.ewma(x, com=a/(1.0-a), adjust=False)
def nanzero(x):
return 0 if np.isnan(x) else x
x.ffill(inplace=True)
y = [x[0]]
for xt in x[1:]:
yt1 = y[-1]
if np.isnan(yt1) and np.isnan(xt):
yt = nan
else:
yt1 = nanzero(yt1)
xt = nanzero(xt)
yt = a*yt1 + (1-a)*xt
# yt = (1-a)*yt1 + a*xt
y.append(yt)
y = pd.Series(y)
NTU.assert_allclose(y,z)
关于python - Pandas EWMA 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17954314/
我正在尝试使用 pandas 计算 EWMA,但结果不是我所期望的。我认为第 4 个元素应该是 13.179,但 pandas 给出了 13.121。我通过 documentation 中指定的公式将
我正在计算基于时间的 EWMA,定义如下: 地点: 在以下示例数据框 df 上: index time x 0 1 5 1
我正在尝试创建一个滚动 EWMA,其 df 的最后 13 个值的衰减= 1-ln(2)/3 如下: factor Out[36]: EWMA 0 0.043 1 0.056 2 0.07
我有这个数据框: avg date high low qty 0 16.92 2013-05-27 00:00:00 19.00 1.22
我在 Google 和此处进行了广泛搜索,但似乎找不到我正在寻找的答案,或者至少找不到我理解的一些东西。是否可以在 Pandas 中使用 EWMA 进行预测?例如,如果我有从 2 月 1 日到 3 月
我试图从名为 base_retorno_diario 的数据框的一系列股票每日返回中获得 EWMA 波动率。 Data IBOV ABEV3 AEDU3
我编写了一些代码来构建我自己的 EMA/MACD,但我决定改为尝试使用 Pandas。 我使用下面这个网站作为对 EMA 的基本了解,并试图让 pandas 给我相同的答案以确保我正确使用 panda
我有一个看起来像这样的时间序列(切片): Date 3 7 10 2015-02-13 0.00021 -0.00078927 0.0040
给定以下高频但稀疏的时间序列: #Sparse Timeseries dti1 = pd.date_range(start=datetime(2015,8,1,9,0,0),periods=10,fr
我是一名优秀的程序员,十分优秀!