Exemplo n.º 1
0
def calc_hmo_express(code, date):
    df = lut.load_orderbook(code=code, date=date, verbose=10)
    if df.shape[0] > 0:
        df = df[(df['timeint'] > 93000) & (df['timeint'] < 145700)].copy()
        dt, co, hmo = date, code, calc_hmo(df)
    else:
        dt, co, hmo = date, code, np.nan
    del df
    gc.collect()
    return date, code, hmo
Exemplo n.º 2
0
def trendstrength_express(code, date):
    df = lut.load_orderbook(code=code, date=date, verbose=0)
    is_abnormal = np.all(df['ap1'] == df['bp1']) | np.all(
        df['ap1'] == 0) | np.all(df['bp1'] == 0)
    if (df.shape[0] > 0) and (~is_abnormal):
        df = df[(df['timeint'] > 93000) & (df['timeint'] < 145700)].copy()
        dt, co, fatv = date, code, trendstrength(df)
    else:
        dt, co, fatv = date, code, np.nan
    del df
    gc.collect()
    return dt, co, fatv
Exemplo n.º 3
0
def calc_dbook_express(code, date):
    # TODO to be tested
    df = lut.load_orderbook(code=code, date=date, verbose=0)
    is_abnormal = np.all(df['ap1'] == df['bp1']) | np.all(
        df['ap1'] == 0) | np.all(df['bp1'] == 0)
    if (df.shape[0] > 0) and (~is_abnormal):
        df = df[(df['timeint'] > 93000) & (df['timeint'] < 145700)].copy()
        dt, co, fatv = date, code, dbook(df, n=1, alpha=0.05)[-1]
    else:
        dt, co, fatv = date, code, np.nan
    del df
    gc.collect()
    return dt, co, fatv
Exemplo n.º 4
0
    test_slice = np.s_[-252:]
    all_trading_dates = all_trading_dates[test_slice]
    all_trading_dates_int = all_trading_dates_int[test_slice]

    selected_codes1 = hs300b[0].tolist()
    selected_codes2 = hs300b[2].tolist()
    selected_codes3 = hs300b[3].tolist()

    # --------------------------------------------------------------------------------
    # compute factors and target
    # --------------------------------------------------------------------------------

    for date in tqdm(all_trading_dates_int):
        for code in selected_codes3:
            print(lfp.volume_distance_express(code, date))
            df = lut.load_orderbook(code, date)
            df = df[(df['timeint'] > 93000) & (df['timeint'] < 145700)].copy()
            lfp.price_volume_corr_express(code, date)
            raise Exception()

    print('computing tba...')
    tba_list = Parallel(n_jobs=16, verbose=3)(
        delayed(lfp.calc_tba_express)(code=co, date=d)
        for d in all_trading_dates_int for co in selected_codes3)
    tba = pd.DataFrame(tba_list, columns=['date', 'code', 'tba'])
    # tba['code'] = tba['code'].map(code_type_map2)
    tba = tba.set_index(['date', 'code'])

    print('computing dbook...')
    dbook_list = Parallel(n_jobs=16, verbose=3)(
        delayed(lfp.calc_dbook_express)(code=co, date=d)