A custom indicator that I am using will only accept data that is quoted hourly. I have attempted to resample the continuous futures data using pandas data frame conventions and an unexpected error is thrown. I am first looking to find what is wrong with the resampling method used in my code below. Second, I am looking for suggestions on how to modify the range of my for loop to account for 24-hour continuous data.
def initialize(context):
context.intraday_bar = 60
for i in range(1, 390):
if i % context.intraday_bar == 0:
schedule_function(hourly_rebalance, date_rules.every_day(), time_rules.market_open(minutes=i))
schedule_function(record_vars, date_rules.every_day(), time_rules.market_open())
def hourly_rebalance(context, data):
bar_count = context.intraday_bar * 42
df = data.history(context.my_futures, ['close'], bar_count, '1m')
resample_period = str(context.intraday_bar)+'T'
result = df.resample(resample_period, base=1).first()
result['close'] = df['close'].resample(resample_period, base=1).last()
The error below is thrown on the second to last line of the code above:
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'