Exemplo n.º 1
0
    def raw_data_gen(self):
        bt_data = self._get_backtest_data()

        for date in self.index:
            backtest_is_done = False
            date = date.replace(hour=self.market_open.hour,
                                minute=self.market_open.minute)
            close_hour = date.replace(hour=self.market_close.hour,
                                      minute=self.market_close.minute)

            # Trade until the end of the trading day
            while date < close_hour:
                # Set to opening of the market
                self.log.debug('--> next tick {}'.format(date))
                # NOTE Make _is_live a property ?
                self._is_live = utils.next_tick(date)

                data = self._agnostic_get_data_at(date, bt_data)
                if not data.empty:
                    for sid, series in data.iterkv():
                        if backtest_is_done and not self._is_live:
                            # TODO Use previous and next data to extrapolate
                            # random values
                            self.log.debug('extrapoling intraday data')

                        yield _build_safe_event(series.to_dict(), date, sid)
                    backtest_is_done = True

                # Done for this event, when is the next ?
                date = self._set_next_tick(date)
Exemplo n.º 2
0
    def raw_data_gen(self):
        bt_data = self._get_backtest_data()

        for date in self.index:
            backtest_is_done = False
            date = date.replace(hour=self.market_open.hour,
                                minute=self.market_open.minute)
            close_hour = date.replace(hour=self.market_close.hour,
                                      minute=self.market_close.minute)

            # Trade until the end of the trading day
            while date < close_hour:
                # Set to opening of the market
                self.log.debug('--> next tick {}'.format(date))
                # NOTE Make _is_live a property ?
                self._is_live = utils.next_tick(date)

                data = self._agnostic_get_data_at(date, bt_data)
                if not data.empty:
                    for sid, series in data.iterkv():
                        if backtest_is_done and not self._is_live:
                            # TODO Use previous and next data to extrapolate
                            # random values
                            self.log.debug('extrapoling intraday data')

                        yield _build_safe_event(series.to_dict(), date, sid)
                    backtest_is_done = True

                # Done for this event, when is the next ?
                date = self._set_next_tick(date)
Exemplo n.º 3
0
 def test_wait_backtest_next_tick(self):
     old_dt = dt.datetime(2010, 12, 1, tzinfo=pytz.utc)
     self.assertFalse(utils.next_tick(old_dt))
Exemplo n.º 4
0
 def test_wait_backtest_next_tick(self):
     old_dt = dt.datetime(2010, 12, 1, tzinfo=pytz.utc)
     self.assertFalse(utils.next_tick(old_dt))