Hi everyone, need some help on the batch_transform.
Dive into the code
import random
def initialize(context):
pass
@batch_transform(window_length=1, refresh_period=1)
def batch(datapanel):
return random.random()
# Will be called on every trade event for the securities you specify.
def handle_data(context, data):
x = batch(data)
if x is not None:
log.info(x)
order(sid(24), 50)
From what I understand, when I set the
refresh period=1
the batch_transformed function should only be called once every day. [update: okay, that's incorrect. The function should be called every bar. However, the datapanel is only updated once everyday] Hence I expect the the output of logs be same within the same day when run in the minute mode. But here is what I got
2014-02-20handle_data:14INFO0.0866587877595
2014-02-21handle_data:14INFO0.260505064836
2014-02-21handle_data:14INFO0.297122017472
2014-02-21handle_data:14INFO0.0491141736111
2014-02-21handle_data:14INFO0.999269810604
2014-02-21handle_data:14INFO0.0700925961977
2014-02-21handle_data:14INFO0.422723775352
2014-02-21handle_data:14INFO0.256027120872
2014-02-21handle_data:14INFO0.406170130361
2014-02-21handle_data:14INFO0.73002239253
2014-02-21handle_data:14INFO0.515887335473
2014-02-21handle_data:14INFO0.74262632377
2014-02-21handle_data:14INFO0.707867163496
2014-02-21handle_data:14INFO0.214877704526
2014-02-21handle_data:14INFO0.751468426835
2014-02-21handle_data:14INFO0.142119377371
2014-02-21handle_data:14INFO0.981545623245
2014-02-21handle_data:14INFO0.833314020675
it seems to be rolling as the output is different for each minute. Even stranger, when i set
refresh_period = 2
The logs for the first day turn out as expected, that is the value returned for the log are the same for the first day. However, from the second day and on, the batch_transform behavior like rolling again.
Without digging into zipline source code, I cannot make sense of this behavior. Any idea?