Пример #1
0
def get_st_classified():
    """
        获取风险警示板股票
    Return
    --------
    DataFrame
        code :股票代码
        name :股票名称
    """
    df = fd.get_stock_basics()
    df.reset_index(inplace=True)
    df = df[ct.FOR_CLASSIFY_COLS]
    df = df.ix[df.name.str.contains('ST')]
    df = df.sort_values('code').reset_index(drop=True)
    return df
Пример #2
0
def get_area_classified():
    """
        获取地域分类数据
    Return
    --------
    DataFrame
        code :股票代码
        name :股票名称
        area :地域名称
    """
    df = fd.get_stock_basics()
    df = df[['name', 'area']]
    df.reset_index(inplace=True)
    df = df.sort_values('area').reset_index(drop=True)
    return df
Пример #3
0
def get_sme_classified():
    """
        获取中小板股票
    Return
    --------
    DataFrame
        code :股票代码
        name :股票名称
    """
    df = fd.get_stock_basics()
    df.reset_index(inplace=True)
    df = df[ct.FOR_CLASSIFY_COLS]
    df = df.ix[df.code.str[0:3] == '002']
    df = df.sort_values('code').reset_index(drop=True)
    return df
Пример #4
0
def bar2h5(market='', date='', freq='D', asset='E', filepath=''):
    cons = get_apis()
    stks = get_stock_basics()
    fname = "%s%s%sbar%s.h5" % (filepath, market, date, freq)
    store = pd.HDFStore(fname, "a")
    if market in ['SH', 'SZ']:
        if market == 'SH':
            stks = stks.ix[stks.index.str[0] == '6', :]
        elif market == 'SZ':
            stks = stks.ix[stks.index.str[0] != '6', :]
        else:
            stks = ''
        market = 1 if market == 'SH' else 0
        for stk in stks.index:
            symbol = '%s.SH' % stk
            if 'min' in freq:
                df = bar(stk,
                         conn=cons,
                         start_date=date,
                         end_date=date,
                         freq=freq,
                         market=market,
                         asset=asset)
                df['Time'] = df.index
                df['Time'] = df['Time'].apply(get_dt_time)
                df.index = df['Time']
                df.drop(['code', 'Time'], axis=1, inplace=True)
                df.rename(columns={'open': 'OPEN'}, inplace=True)
                df.rename(columns={'close': 'CLOSE'}, inplace=True)
                df.rename(columns={'low': 'LOW'}, inplace=True)
                df.rename(columns={'high': 'HIGH'}, inplace=True)
                df.rename(columns={'vol': 'VOLUME'}, inplace=True)
                df.rename(columns={'amount': 'TURNOVER'}, inplace=True)
                df.loc[:, 'HIGH'] = df.loc[:, 'HIGH'].astype("int64")
                df.loc[:, 'LOW'] = df.loc[:, 'LOW'].astype("int64")
                df.loc[:, 'OPEN'] = df.loc[:, 'OPEN'].astype("int64")
                df.loc[:, 'CLOSE'] = df.loc[:, 'CLOSE'].astype("int64")
                df.loc[:, 'VOLUME'] = df.loc[:, 'VOLUME'].astype("int64")
                df.loc[:, 'TURNOVER'] = df.loc[:, 'TURNOVER'].astype("int64")
                df.loc[:, 'OPEN'] *= 10000
                df.loc[:, 'CLOSE'] *= 10000
                df.loc[:, 'HIGH'] *= 10000
                df.loc[:, 'LOW'] *= 10000
                df.loc[:, 'ASKPRICE1'] = 0
                df.loc[:, 'ASKPRICE2'] = 0
                df.loc[:, 'ASKPRICE3'] = 0
                df.loc[:, 'ASKPRICE4'] = 0
                df.loc[:, 'ASKPRICE5'] = 0
                df.loc[:, 'ASKPRICE6'] = 0
                df.loc[:, 'ASKPRICE7'] = 0
                df.loc[:, 'ASKPRICE8'] = 0
                df.loc[:, 'ASKPRICE9'] = 0
                df.loc[:, 'ASKPRICE10'] = 0
                df.loc[:, 'BIDPRICE1'] = 0
                df.loc[:, 'BIDPRICE2'] = 0
                df.loc[:, 'BIDPRICE3'] = 0
                df.loc[:, 'BIDPRICE4'] = 0
                df.loc[:, 'BIDPRICE5'] = 0
                df.loc[:, 'BIDPRICE6'] = 0
                df.loc[:, 'BIDPRICE7'] = 0
                df.loc[:, 'BIDPRICE8'] = 0
                df.loc[:, 'BIDPRICE9'] = 0
                df.loc[:, 'BIDPRICE10'] = 0
                df.loc[:, 'ASKVOL1'] = 0
                df.loc[:, 'ASKVOL2'] = 0
                df.loc[:, 'ASKVOL3'] = 0
                df.loc[:, 'ASKVOL4'] = 0
                df.loc[:, 'ASKVOL5'] = 0
                df.loc[:, 'ASKVOL6'] = 0
                df.loc[:, 'ASKVOL7'] = 0
                df.loc[:, 'ASKVOL8'] = 0
                df.loc[:, 'ASKVOL9'] = 0
                df.loc[:, 'ASKVOL10'] = 0
                df.loc[:, 'BIDVOL1'] = 0
                df.loc[:, 'BIDVOL2'] = 0
                df.loc[:, 'BIDVOL3'] = 0
                df.loc[:, 'BIDVOL4'] = 0
                df.loc[:, 'BIDVOL5'] = 0
                df.loc[:, 'BIDVOL6'] = 0
                df.loc[:, 'BIDVOL7'] = 0
                df.loc[:, 'BIDVOL8'] = 0
                df.loc[:, 'BIDVOL9'] = 0
                df.loc[:, 'BIDVOL10'] = 0
                df.loc[:, 'VWAP'] = 0.0
                df.loc[:, 'VOL30'] = 0.0
                df.loc[:, 'TOTAL_VOLUME'] = 0.0
                df.loc[:, 'TOTAL_TURNOVER'] = 0.0
                df.loc[:, 'INTEREST'] = 0.0
                print(df)


#             if market == 1 and stk[0] == '6':
#                 df = bar(stk, conn=cons, start_date=date, end_date=date, freq=freq, market=market, asset=asset)

            store[symbol] = df

    store.close()
    close_apis(cons)