我有一个python数据框,其中包含一些财务数据,我正试图为这些数据创建一些技术指标。我试图找出如何使用一个移动窗口函数来加速这个过程,而不是逐个元素地进行。对于每个索引,我想返回过去30天的最大索引。我已经实现了一个元素一个元素的解决方案,但正如你可以想象的那样,它的速度非常慢。在
for s_sym in ls_symbols:
for i in range(refresh, len(ldt_timestamps)):
#Aroon-Up = ((period - Days Since High)/period) x 100 Aroon-Down = ((period - Days Since Low)/peiod) x 100'''
whrmax = df_close[s_sym].ix[ldt_timestamps[i-uplen:i]].idxmax()
maxaway = (df_close[s_sym].ix[whrmax : ldt_timestamps[i-1]]).count()
aroonup = ((uplen - maxaway) / uplen ) * 100
whrmin = df_close[s_sym].ix[ldt_timestamps[i-dnlen:i]].idxmin()
minaway = df_close[s_sym].ix[whrmin : ldt_timestamps[i-1]].count()
aroondn = ((dnlen - minaway) / dnlen ) * 100
如何创建自定义滚动窗口函数?在
参见文档:
http://pandas.pydata.org/pandas-docs/dev/computation.html#moving-rolling-statistics-moments
还有一些很好的例子:
http://pandas.pydata.org/pandas-docs/dev/cookbook.html#grouping
仅供参考,使用
rolling_max(df,30)
来获取特定范围内的最大值可能会更好,这正是我收集到的您所追求的相关问题 更多 >
编程相关推荐