重新采样分钟数据
在开放时间/第一小时(美国东部标准时间9:30-10:30),我有基于分钟的OHLCV数据.我正在尝试对这些数据进行重新采样,以便获得一个60分钟的值,然后计算范围.
I have minute based OHLCV data for the opening range/first hour (9:30-10:30 AM EST). I'm looking to resample this data so I can get one 60-minute value and then calculate the range.
当我对数据调用dataframe.resample()函数时,会得到两行,并且第一行从9:00 AM开始.我希望仅获得从9:30 AM开始的一行.
When I call the dataframe.resample() function on the data I get two rows and the initial row starts at 9:00 AM. I'm looking to get only one row which starts at 9:30 AM.
注意:初始数据始于9:30.
Note: the initial data begins at 9:30.
添加代码:
# Extract data for regular trading hours (rth) from the 24 hour data set
rth = data.between_time(start_time = '09:30:00', end_time = '16:15:00', include_end = False)
# Extract data for extended trading hours (eth) from the 24 hour data set
eth = data.between_time(start_time = '16:30:00', end_time = '09:30:00', include_end = False)
# Extract data for initial balance (rth) from the 24 hour data set
initial_balance = data.between_time(start_time = '09:30:00', end_time = '10:30:00', include_end = False)
卡住了,试图按各个日期分开开仓范围并获得初始余额
Got stuck tried to separate the opening range by individual date and get the Initial Balance
conversion = {'Open' : 'first', 'High' : 'max', 'Low' : 'min', 'Close' : 'last', 'Volume' : 'sum'}
sample = data.between_time(start_time = '09:30:00', end_time = '10:30:00', include_end = False)
sample = sample.ix['2007-05-07']
sample.tail()
sample.resample('60Min', how = conversion)
默认情况下,重新采样从小时开始时开始.我希望它从数据开始的地方开始.
By default resample starts at the beggining of the hour. I would like it to start from where the data starts.
您可以使用resample
:
You can use the base
argument of resample
:
sample.resample('60Min', how=conversion, base=30)
来自上面的文档链接 :
base
:int
,默认0
对于平均细分为1天的频率,则是汇总间隔的起点".
例如,对于"5min"频率,基数范围可以从0到4.默认值为0
base
:int
, default 0
For frequencies that evenly subdivide 1 day, the "origin" of the aggregated intervals.
For example, for ‘5min’ frequency, base could range from 0 through 4. Defaults to 0