本文整理汇总了Python中zipline.protocol.Event类的典型用法代码示例。如果您正苦于以下问题:Python Event类的具体用法?Python Event怎么用?Python Event使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Event类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_data
def handle_data(self, data, *args, **kwargs):
"""
Point of entry. Process an event frame.
"""
# extract dates
dts = [event.dt for event in itervalues(data._data)]
# we have to provide the event with a dt. This is only for
# checking if the event is outside the window or not so a
# couple of seconds shouldn't matter. We don't add it to
# the data parameter, because it would mix dt with the
# sid keys.
event = Event()
event.dt = max(dts)
event.data = {k: v.__dict__ for k, v in iteritems(data._data)
# Need to check if data has a 'length' to filter
# out sids without trade data available.
# TODO: expose more of 'no trade available'
# functionality to zipline
if len(v)}
# only modify the trailing window if this is
# a new event. This is intended to make handle_data
# idempotent.
if self.last_dt < event.dt:
self.updated = True
self._append_to_window(event)
else:
self.updated = False
# return newly computed or cached value
return self.get_transform_value(*args, **kwargs)
示例2: handle_data
def handle_data(self, data, *args, **kwargs):
"""
New method to handle a data frame as sent to the algorithm's
handle_data method.
"""
# extract dates
# dts = [data[sid].datetime for sid in self.sids]
dts = [event.datetime for event in data.itervalues()]
# we have to provide the event with a dt. This is only for
# checking if the event is outside the window or not so a
# couple of seconds shouldn't matter. We don't add it to
# the data parameter, because it would mix dt with the
# sid keys.
event = Event()
event.dt = max(dts)
event.data = {
k: v.__dict__
for k, v in data.iteritems()
# Need to check if data has a 'length' to filter
# out sids without trade data available.
# TODO: expose more of 'no trade available'
# functionality to zipline
if len(v)
}
# append data frame to window. update() will call handle_add() and
# handle_remove() appropriately
self.update(event)
# return newly computed or cached value
return self.get_transform_value(*args, **kwargs)
示例3: handle_data
def handle_data(self, data, *args, **kwargs):
"""
New method to handle a data frame as sent to the algorithm's
handle_data method.
"""
# extract dates
#dts = [data[sid].datetime for sid in self.sids]
dts = [event.datetime for event in data.itervalues()]
# we have to provide the event with a dt. This is only for
# checking if the event is outside the window or not so a
# couple of seconds shouldn't matter. We don't add it to
# the data parameter, because it would mix dt with the
# sid keys.
event = Event()
event.dt = max(dts)
event.data = {k: v.__dict__ for k, v in data.iteritems()
# Need to check if data has a 'length' to filter
# out sids without trade data available.
# TODO: expose more of 'no trade available'
# functionality to zipline
if len(v)}
# only modify the trailing window if this is
# a new event. This is intended to make handle_data
# idempotent.
if event not in self.ticks:
# append data frame to window. update() will call handle_add() and
# handle_remove() appropriately, and self.updated
# will be modified based on the refresh_period
self.update(event)
else:
# we are recalculating based on an old event, so
# there is no change in the contents of the trailing
# window
self.updated = False
# return newly computed or cached value
return self.get_transform_value(*args, **kwargs)
示例4: handle_data
def handle_data(self, data, *args, **kwargs):
"""
New method to handle a data frame as sent to the algorithm's
handle_data method.
"""
# extract dates
#dts = [data[sid].datetime for sid in self.sids]
dts = [event.datetime for event in data.itervalues()]
# we have to provide the event with a dt. This is only for
# checking if the event is outside the window or not so a
# couple of seconds shouldn't matter. We don't add it to
# the data parameter, because it would mix dt with the
# sid keys.
event = Event()
event.dt = max(dts)
event.data = data
# append data frame to window. update() will call handle_add() and
# handle_remove() appropriately
self.update(event)
# return newly computed or cached value
return self.get_transform_value(*args, **kwargs)
示例5: create_trade
def create_trade(sid, price, amount, datetime, source_id="test_factory"):
trade = Event()
trade.source_id = source_id
trade.type = DATASOURCE_TYPE.TRADE
trade.sid = sid
trade.dt = datetime
trade.price = price
trade.close_price = price
trade.open_price = price
trade.low = price * .95
trade.high = price * 1.05
trade.volume = amount
return trade