示例#1
0
        def check_df(freq, df, daily_bars):
            if freq == '1m':
                need_check = pd.DataFrame({
                    'open':
                    df['open'].resample('1D').first(),
                    'high':
                    df['high'].resample('1D').max(),
                    'low':
                    df['low'].resample('1D').min(),
                    'close':
                    df['close'].resample('1D').last(),
                    'volume':
                    df['volume'].resample('1D').sum()
                }).dropna()
            else:
                need_check = df

            if daily_bars.shape[0] != need_check.shape[0]:
                logger.warning("{} merged {}, expected {}".format(
                    code, need_check.shape[0], daily_bars.shape[0]))
                need_check = fillna(
                    need_check.reindex(daily_bars.index, copy=False))
            diff = daily_bars[['open',
                               'close']] == need_check[['open', 'close']]
            res = (diff.open) & (diff.close)
            sessions = res[res == False].index
            return sessions
示例#2
0
    def minute_bars_from_transaction(cls, transaction, freq):
        if transaction.empty:
            return pd.DataFrame()
        mask = transaction.index < transaction.index[0].normalize(
        ) + pd.Timedelta('12 H')

        def resample(transaction):
            if transaction.empty:
                return pd.DataFrame()
            data = transaction['price'].resample(freq,
                                                 label='right',
                                                 closed='left').ohlc()

            data['volume'] = transaction['vol'].resample(freq,
                                                         label='right',
                                                         closed='left').sum()
            data['code'] = transaction['code'][0]
            return data

        morning = resample(transaction[mask])
        afternoon = resample(transaction[~mask])
        if morning.empty and afternoon.empty:
            return pd.DataFrame()
        if not afternoon.empty:
            morning.index.values[-1] = afternoon.index[0] - pd.Timedelta(
                '1 min')

        df = pd.concat([morning, afternoon])

        return fillna(df)
示例#3
0
    def minute_bars_from_transaction(cls, transaction, freq):
        if transaction.empty:
            return pd.DataFrame()
        data = transaction['price'].resample(freq,
                                             label='right',
                                             closed='left').ohlc()

        data['volume'] = transaction['vol'].resample(freq,
                                                     label='right',
                                                     closed='left').sum()
        data['code'] = transaction['code'][0]

        return fillna(data)