I'm trying to write a custom moving average function that will update every trading minute and use a trailing window of minutely ticks. Under the minutely backtest, it appears that I am able to extract a trailing window of 390 ticks with this code:
@batch_transform(refresh_period=0, window_length=1)
def get_prices(datapanel, sids):
return datapanel['price'][sids].values
The window is updated every minute (due to the setting refresh_period=0).
Note that the code won't execute under the daily backtester, due to this line:
log.debug(' prices: ' + str(prices[388]))
But, if I ignore the error, I can still run under the minutely backtest.
The problem is that the minutely backtester runs this simple algorithm very slowly. Any idea why? I tried commenting out the logging, but it didn't help.