我有返回数据,该数据使用DateTimeIndex索引,如下所示
>ES.head()
Date
2006-01-02 19:15:00 -0.000199
2006-01-02 19:20:00 -0.000199
2006-01-02 19:25:00 0.000000
2006-01-02 19:30:00 -0.000099
2006-01-02 19:35:00 -0.000099
Name: Price, dtype: float64
当我绘制5分钟的平均回报时,我得到以下
fig = plt.figure()
ax1 = fig.add_subplot(111)
plt.plot(ES.groupby([ES.index.hour, ES.index.minute]).mean())
ax1.set_ylabel('Return')
ax1.set_xlabel('5-minute interval')
当我现在在16:00和17:00之间放下所有观察并绘制图像时,我得到相同的图像!?
mask = ~((ES.index.hour > 16) & (ES.index.hour < 17))
ES = ES[mask]
fig = plt.figure()
ax1 = fig.add_subplot(111)
plt.plot(ES.groupby([ES.index.hour, ES.index.minute]).mean())
ax1.set_ylabel('Return')
ax1.set_xlabel('5-minute interval')
有了这个情节
我已经被困在这个问题上超过一天了,因为我希望在16:00到17:00之间取消由于市场开盘/收盘效应产生的回报。
为什么我的数据框没有正确分组?
编辑:
>ES['2007-01-03 15:30':'2007-01-03 17:30']
Date
2007-01-03 15:30:00 0.000263
2007-01-03 15:35:00 0.000000
2007-01-03 15:40:00 -0.000146
2007-01-03 15:45:00 0.000058
2007-01-03 15:50:00 0.000175
2007-01-03 15:55:00 0.000058
2007-01-03 16:00:00 0.000117
2007-01-03 16:05:00 0.000000
2007-01-03 16:10:00 0.000000
2007-01-03 16:15:00 0.000000
2007-01-03 16:20:00 -0.000175
2007-01-03 16:25:00 0.000175
2007-01-03 16:30:00 0.000000
2007-01-03 16:35:00 0.000000
2007-01-03 16:40:00 0.000000
2007-01-03 16:45:00 0.000000
2007-01-03 16:50:00 0.000000
2007-01-03 16:55:00 0.000000
2007-01-03 17:00:00 0.000058
2007-01-03 17:05:00 0.000292
2007-01-03 17:10:00 -0.000175
2007-01-03 17:15:00 0.000000
2007-01-03 17:20:00 0.000000
2007-01-03 17:25:00 0.000000
2007-01-03 17:30:00 0.000000
Name: Price, dtype: float64
>mask = ~((ES.index.hour > 16) & (ES.index.hour < 17))
>ES = ES[mask]
>ES['2007-01-03 15:30':'2007-01-03 17:30']
Date
2007-01-03 15:30:00 0.000263
2007-01-03 15:35:00 0.000000
2007-01-03 15:40:00 -0.000146
2007-01-03 15:45:00 0.000058
2007-01-03 15:50:00 0.000175
2007-01-03 15:55:00 0.000058
2007-01-03 16:00:00 0.000117
2007-01-03 16:05:00 0.000000
2007-01-03 16:10:00 0.000000
2007-01-03 16:15:00 0.000000
2007-01-03 16:20:00 -0.000175
2007-01-03 16:25:00 0.000175
2007-01-03 16:30:00 0.000000
2007-01-03 16:35:00 0.000000
2007-01-03 16:40:00 0.000000
2007-01-03 16:45:00 0.000000
2007-01-03 16:50:00 0.000000
2007-01-03 16:55:00 0.000000
2007-01-03 17:00:00 0.000058
2007-01-03 17:05:00 0.000292
2007-01-03 17:10:00 -0.000175
2007-01-03 17:15:00 0.000000
2007-01-03 17:20:00 0.000000
2007-01-03 17:25:00 0.000000
2007-01-03 17:30:00 0.000000
Name: Price, dtype: float64
似乎我的面具不起作用,但是,当我尝试以下时,在删除适当的行时,绘图仍然相同。
>ES['2007-01-03 15:30':'2007-01-03 17:30']
Date
2007-01-03 15:30:00 0.000263
2007-01-03 15:35:00 0.000000
2007-01-03 15:40:00 -0.000146
2007-01-03 15:45:00 0.000058
2007-01-03 15:50:00 0.000175
2007-01-03 15:55:00 0.000058
2007-01-03 16:00:00 0.000117
2007-01-03 16:05:00 0.000000
2007-01-03 16:10:00 0.000000
2007-01-03 16:15:00 0.000000
2007-01-03 16:20:00 -0.000175
2007-01-03 16:25:00 0.000175
2007-01-03 16:30:00 0.000000
2007-01-03 16:35:00 0.000000
2007-01-03 16:40:00 0.000000
2007-01-03 16:45:00 0.000000
2007-01-03 16:50:00 0.000000
2007-01-03 16:55:00 0.000000
2007-01-03 17:00:00 0.000058
2007-01-03 17:05:00 0.000292
2007-01-03 17:10:00 -0.000175
2007-01-03 17:15:00 0.000000
2007-01-03 17:20:00 0.000000
2007-01-03 17:25:00 0.000000
2007-01-03 17:30:00 0.000000
Name: Price, dtype: float64
>ES = ES.drop(ES.between_time('16:00','17:00').index)
>ES['2007-01-03 15:30':'2007-01-03 17:30']
Date
2007-01-03 15:30:00 0.000263
2007-01-03 15:35:00 0.000000
2007-01-03 15:40:00 -0.000146
2007-01-03 15:45:00 0.000058
2007-01-03 15:50:00 0.000175
2007-01-03 15:55:00 0.000058
2007-01-03 17:05:00 0.000292
2007-01-03 17:10:00 -0.000175
2007-01-03 17:15:00 0.000000
2007-01-03 17:20:00 0.000000
2007-01-03 17:25:00 0.000000
2007-01-03 17:30:00 0.000000
Name: Price, dtype: float64