當前位置: 首頁>>代碼示例>>Python>>正文


Python Event.dt方法代碼示例

本文整理匯總了Python中zipline.protocol.Event.dt方法的典型用法代碼示例。如果您正苦於以下問題:Python Event.dt方法的具體用法?Python Event.dt怎麽用?Python Event.dt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在zipline.protocol.Event的用法示例。


在下文中一共展示了Event.dt方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handle_data

# 需要導入模塊: from zipline.protocol import Event [as 別名]
# 或者: from zipline.protocol.Event import dt [as 別名]
    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)
開發者ID:ChrisBg,項目名稱:zipline,代碼行數:33,代碼來源:batch_transform.py

示例2: handle_data

# 需要導入模塊: from zipline.protocol import Event [as 別名]
# 或者: from zipline.protocol.Event import dt [as 別名]
    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)
開發者ID:rymurr,項目名稱:zipline,代碼行數:33,代碼來源:utils.py

示例3: create_trade

# 需要導入模塊: from zipline.protocol import Event [as 別名]
# 或者: from zipline.protocol.Event import dt [as 別名]
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
開發者ID:barrygolden,項目名稱:zipline,代碼行數:18,代碼來源:test_source.py

示例4: handle_data

# 需要導入模塊: from zipline.protocol import Event [as 別名]
# 或者: from zipline.protocol.Event import dt [as 別名]
    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)
開發者ID:PostPCEra,項目名稱:zipline,代碼行數:40,代碼來源:utils.py

示例5: handle_data

# 需要導入模塊: from zipline.protocol import Event [as 別名]
# 或者: from zipline.protocol.Event import dt [as 別名]
    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)
開發者ID:aichi,項目名稱:zipline,代碼行數:25,代碼來源:utils.py


注:本文中的zipline.protocol.Event.dt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。