k线重新采样

def resample_kbar(df, rule, base=0, add=None):
    rule = rule.upper()
    if rule[-1:] == 'M':
        rule = rule[:-1] + 'T'

    agg_rule = {
        'symbol':'first',
        # 'open_time':'first',
        'close': 'last',
        'open': 'first',
        'low': 'min',
        'high': 'max',
        # 'amount': 'sum',
        'volume': 'sum'
    }

    if add:
        agg_rule.update(add)

    cols = [k for k in agg_rule.keys()]
    cols.append('Datetime_as')

    temp = df[cols].resample(rule=rule, closed='left', label='left', base=base).agg(agg_rule)

    temp.dropna(subset=['open'], inplace=True)
    temp.reset_index(inplace=True)
    return temp

环境 :

python 3.6.8

pandas 0.18.1

作用:

ns = resample_kbar(n,'60S',5) 把5秒的K线数据,合并成1分钟,并偏移5秒k线重新采样_第1张图片

你可能感兴趣的:(java,c++,python)