Hello Quantopian,
I've been using a batch_transform in a minutely algo and I've wasted HOURS debugging it. This may hint at the problem. It's....err....proper wack, as the kiddies say. Caused by the missing 14 minutes detailed in the post above and poor data handling in batch_transform.
P.
Code:
def initialize(context):
context.test_sid=sid(24)
context.error = False
def handle_data(context, data):
prices=get_data(data, context)
if prices is None:
return
if len(prices) < 780 and not context.error:
print "In hamdle_data length of prices is " + str(len(prices))
print prices.ix[0]
print prices.ix[389]
print prices.ix[765] # Amy higher is out of bounds
context.error = True
elif len(prices) == 780:
print "In hamdle_data length of prices is " + str(len(prices))
print prices.ix[0]
print prices.ix[389]
print prices.ix[779]
@batch_transform(window_length=2, refresh_period=0)
def get_data(datapanel, context):
prices = datapanel['price']
if not context.error:
print "In batch_transform length of prices is " + str(len(prices))
return prices
Output:
2013-01-03PRINTIn batch_transform length of prices is 766
2013-01-03PRINTIn hamdle_data length of prices is 766
2013-01-03PRINT24 552.97 Name: 2013-01-02 14:31:00+00:00, dtype: float64
2013-01-03PRINT24 548.71 Name: 2013-01-02 21:00:00+00:00, dtype: float64
2013-01-03PRINT24 542.38 Name: 2013-01-03 21:00:00+00:00, dtype: float64
REM ** The three lines above are quite different to the three lines below. I think this is **
REM ** due to the 14 minute period in between whilst the DataFrame returned by the batch_transform **
REM ** grows from 766 to 780 rows. This is why the first two lines are the same but the **
REM ** third one changes from 21:00:00 to 14:44:00 i,e, 14 data minutes later. **
2013-01-04PRINTIn hamdle_data length of prices is 780
2013-01-04PRINT24 552.97 Name: 2013-01-02 14:31:00+00:00, dtype: float64
2013-01-04PRINT24 548.71 Name: 2013-01-02 21:00:00+00:00, dtype: float64
2013-01-04PRINT24 536.75 Name: 2013-01-04 14:44:00+00:00, dtype: float64
2013-01-04PRINTIn hamdle_data length of prices is 780
2013-01-04PRINT24 551.09 Name: 2013-01-02 14:32:00+00:00, dtype: float64
2013-01-04PRINT24 547.158 Name: 2013-01-03 14:31:00+00:00, dtype: float64
2013-01-04PRINT24 537.14 Name: 2013-01-04 14:45:00+00:00, dtype: float64
2013-01-04PRINTIn hamdle_data length of prices is 780
2013-01-04PRINT24 551.6 Name: 2013-01-02 14:33:00+00:00, dtype: float64
2013-01-04PRINT24 545.33 Name: 2013-01-03 14:32:00+00:00, dtype: float64
2013-01-04PRINT24 536.87 Name: 2013-01-04 14:46:00+00:00, dtype: float64
2013-01-04PRINTIn hamdle_data length of prices is 780
2013-01-04PRINT24 552.07 Name: 2013-01-02 14:34:00+00:00, dtype: float64
2013-01-04PRINT24 545.56 Name: 2013-01-03 14:33:00+00:00, dtype: float64
2013-01-04PRINT24 536.96 Name: 2013-01-04 14:47:00+00:00, dtype: float64
2013-01-04PRINTIn hamdle_data length of prices is 780
2013-01-04PRINT24 553.5 Name: 2013-01-02 14:35:00+00:00, dtype: float64
2013-01-04PRINT24 544.7401 Name: 2013-01-03 14:34:00+00:00, dtype: float64
2013-01-04PRINT24 537 Name: 2013-01-04 14:48:00+00:00, dtype: float64
2013-01-04PRINTIn hamdle_data length of prices is 780
2013-01-04PRINT24 554.09 Name: 2013-01-02 14:36:00+00:00, dtype: float64
2013-01-04PRINT24 545.11 Name: 2013-01-03 14:35:00+00:00, dtype: float64
2013-01-04PRINT24 536.22 Name: 2013-01-04 14:49:00+00:00, dtype: float64
2013-01-04PRINTIn hamdle_data length of prices is 780
2013-01-04PRINT24 553.61 Name: 2013-01-02 14:37:00+00:00, dtype: float64
2013-01-04PRINT24 543.85 Name: 2013-01-03 14:36:00+00:00, dtype: float64
2013-01-04PRINT24 536.322 Name: 2013-01-04 14:50:00+00:00, dtype: float64
2013-01-04PRINTIn hamdle_data length of prices is 780
2013-01-04PRINT24 553.26 Name: 2013-01-02 14:38:00+00:00, dtype: float64
2013-01-04PRINT24 544.29 Name: 2013-01-03 14:37:00+00:00, dtype: float64
2013-01-04PRINT24 535.79 Name: 2013-01-04 14:51:00+00:00, dtype: float64
2013-01-04PRINTIn hamdle_data length of prices is 780
2013-01-04PRINT24 552.76 Name: 2013-01-02 14:39:00+00:00, dtype: float64
2013-01-04PRINT24 544.87 Name: 2013-01-03 14:38:00+00:00, dtype: float64
2013-01-04PRINT24 536.19 Name: 2013-01-04 14:52:00+00:00, dtype: float64
2013-01-04PRINTIn hamdle_data length of prices is 780
2013-01-04PRINT24 553 Name: 2013-01-02 14:40:00+00:00, dtype: float64
2013-01-04PRINT24 544.625 Name: 2013-01-03 14:39:00+00:00, dtype: float64
2013-01-04PRINT24 535.37 Name: 2013-01-04 14:53:00+00:00, dtype: float64
2013-01-04PRINTIn hamdle_data length of prices is 780
2013-01-04PRINT24 552.59 Name: 2013-01-02 14:41:00+00:00, dtype: float64
2013-01-04undefined:undefinedWARNLogging limit exceeded; some messages discarded