Example #1
0
def test_dtutil():
    import datetime
    date = 20170105
    dt = jutil.convert_int_to_datetime(date)

    assert jutil.shift(date, 2) == 20170119
    assert jutil.convert_datetime_to_int(jutil.shift(dt, 2)) == 20170119

    t = 145539
    dt = jutil.combine_date_time(date, t)
    assert jutil.split_date_time(dt) == (date, t)

    assert jutil.get_next_period_day(date, 'day', 1, 1) == 20170109
    assert jutil.get_next_period_day(date, 'week', 2, 0) == 20170116
    assert jutil.get_next_period_day(date, 'month', 1, 0) == 20170201

    date = 20170808
    assert jutil.get_next_period_day(20170831, 'day',
                                     extra_offset=1) == 20170904
    assert jutil.get_next_period_day(20170831, 'day', n=2,
                                     extra_offset=0) == 20170904
    assert jutil.get_next_period_day(20170831, 'day', n=7,
                                     extra_offset=0) == 20170911
    assert jutil.get_next_period_day(20170831, 'week',
                                     extra_offset=1) == 20170905
    assert jutil.get_next_period_day(20170831, 'month',
                                     extra_offset=0) == 20170901

    monthly = 20170101
    while monthly < 20180301:
        monthly = jutil.get_next_period_day(monthly, 'month', extra_offset=0)
        assert datetime.datetime.strptime(str(monthly), "%Y%m%d").weekday() < 5
Example #2
0
    def _run_bar(self):
        """Quotes of different symbols will be aligned into one dictionary."""
        trade_dates = self.ctx.calendar.get_trade_date_range(self.start_date, self.end_date)

        for trade_date in trade_dates:
            self.on_new_day(trade_date)
            
            quotes_dic = self._create_time_symbol_bars(trade_date)
            for dt in sorted(quotes_dic.keys()):
                _, time = jutil.split_date_time(dt)
                self.ctx.time = time
                
                quote_by_symbol = quotes_dic.get(dt)
                self._process_quote_bar(quote_by_symbol)
            
            self.on_after_market_close()
Example #3
0
    def _run_bar(self):
        """Quotes of different symbols will be aligned into one dictionary."""
        trade_dates = self.ctx.data_api.get_trade_date_range(
            self.start_date, self.end_date)

        last_trade_date = trade_dates[0]
        for i, trade_date in enumerate(trade_dates):
            self.settle_for_stocks(last_trade_date, trade_date)
            self.on_new_day(trade_date)

            quotes_dic = self._create_time_symbol_bars(trade_date)
            for dt in sorted(quotes_dic.keys()):
                _, time = jutil.split_date_time(dt)
                self.ctx.time = time

                quote_by_symbol = quotes_dic.get(dt)
                self._process_quote_bar(quote_by_symbol)

            self.on_after_market_close()
            last_trade_date = trade_date