Ejemplo n.º 1
0
    def initialize_env(cls):
        cls.signals_normal.clear()
        cls.signals_pending.clear()
        cls.signals_trigger.clear()
        cls.signals_cancel.clear()
        cls.signals_normal_cur.clear()
        cls.signals_pending_cur.clear()
        cls.signals_trigger_cur.clear()
        cls.signals_cancel_cur.clear()
        cls.orders_mkt_normal_cur.clear()
        cls.orders_mkt_absolute_cur.clear()
        cls.orders_mkt_submitted_cur.clear()
        cls.orders_pending.clear()
        cls.orders_child_of_mkt_dict.clear()
        cls.orders_cancel_cur.clear()
        cls.orders_cancel_submitted_cur.clear()
        cls.tickers.clear()
        cls.cur_suspended_tickers.clear()
        cls.suspended_tickers_record.clear()
        cls.cache.clear()

        if not cls.is_live_trading:
            ratio = get_day_ratio(cls.sys_frequency)
            cls.sys_date = arrow.get(cls.fromdate).shift(
                days=-ratio).format('YYYY-MM-DD HH:mm:ss')
        cls.reset_all_counters()
Ejemplo n.º 2
0
    def update_calendar(self):
        if self.env.is_live_trading:
            self.env.sys_date = arrow.utcnow().format('YYYY-MM-DD HH:mm:ss')
        else:
            self._check_todate()
            ratio = get_day_ratio(self.env.sys_frequency)
            new_sys_date = arrow.get(self.env.sys_date).shift(days=ratio)
            self.env.sys_date = new_sys_date.format('YYYY-MM-DD HH:mm:ss')

            while not self.is_trading_time(new_sys_date):
                self._check_todate()
                new_sys_date = arrow.get(self.env.sys_date).shift(days=ratio)
                self.env.sys_date = new_sys_date.format('YYYY-MM-DD HH:mm:ss')
Ejemplo n.º 3
0
    def get_brand_new_ohlc_list(self):
        ratio = get_day_ratio(self.frequency)
        reader = self.env.readers[self.ticker]
        ohlc_list = reader.load()

        while self.current_ohlc in ohlc_list and len(ohlc_list) == 2:
            self.check_if_weekday()

            if (arrow.utcnow() - arrow.get(self.date)) >= timedelta(ratio * 2):
                ohlc_list = reader.load()
            time.sleep(1)

        return ohlc_list
Ejemplo n.º 4
0
    def move_next_ohlc_to_cur_ohlc(self):
        """
        用于伪造最新的next bar,骗过系统产生最新日期的信号
        会导致回测结果不准确。
        """
        date_format = "YYYY-MM-DD HH:mm:ss"
        next_date = arrow.get(self.next_ohlc['date']).format(date_format)
        todate = arrow.get(self.env.todate).format(date_format)

        if todate == next_date:
            self.current_ohlc = copy(self.next_ohlc)
            self.next_ohlc['date'] = arrow.get(todate).shift(
                days=get_day_ratio(self.env.sys_frequency)).format(date_format)
        else:
            self.env.cur_suspended_tickers.append(self.ticker)
Ejemplo n.º 5
0
    def _analysis_func(self, fromdate, todate, cache, index):
        t1 = time.time()
        go = op.Gaius()

        fromdate = arrow.get(fromdate).shift(
            months=index).format("YYYY-MM-DD")
        todate = arrow.get(todate).shift(
            months=index).format("YYYY-MM-DD")
        go.env.fromdate = fromdate
        ratio = get_day_ratio(go.env.sys_frequency)
        go.env.sys_date = arrow.get(fromdate).shift(
            days=-ratio).format('YYYY-MM-DD HH:mm:ss')
        go.env.todate = todate

        go.sunny(self.show_summary)
        summary = 1
        cache.append(summary)
        t2 = time.time()
        self._compute_running_time(t1, t2, len(cache))