Exemplo n.º 1
0
def get_instrument_industry(order_book_ids, source='citics', level=1):
    # type: (Union[str, List[str]], Optional[str], Optional[int]) -> pd.DataFrame
    """
    获取T日时股票行业分类

    :param order_book_ids: 合约代码,可传入order_book_id, order_book_id list
    :param source: 默认为中信(citics),可选聚源(gildata)
    :param level: 默认为1,可选 0 1 2 3,0表示返回所有级别
    """
    if isinstance(order_book_ids, six.string_types):
        order_book_ids = assure_order_book_id(order_book_ids)
    else:
        order_book_ids = [assure_order_book_id(i) for i in order_book_ids]
    env = Environment.get_instance()
    return rqdatac.get_instrument_industry(order_book_ids, source, level, env.calendar_dt)
Exemplo n.º 2
0
    "shstockholdings",
    f"date={date_end};field=wind_code,sec_name,hold_stocks,change_holdstocks")
sh_holdings = pd.DataFrame(temp.Data, index=temp.Fields).T
temp = w.wset(
    "szstockholdings",
    f"date={date_end};field=wind_code,sec_name,hold_stocks,change_holdstocks")
sz_holdings = pd.DataFrame(temp.Data, index=temp.Fields).T
sh_holdings['rq_code'] = rq.id_convert(sh_holdings['wind_code'].tolist())
sz_holdings['rq_code'] = rq.id_convert(sz_holdings['wind_code'].tolist())
sh_holdings = sh_holdings.set_index('rq_code')
sz_holdings = sz_holdings.set_index('rq_code')

hk_to_all_stock = (sh_holdings['change_holdstocks'].append(
    sz_holdings['change_holdstocks']) * md.loc[date_end]).dropna() / 1e8
citics = rq.get_instrument_industry(hk_to_all_stock.index,
                                    source='citics_2019',
                                    level=1,
                                    date=date_end)

temp_sh = w.wset("shszhkstockholdings", "date=" + date + ";tradeboard=shn")
temp_sz = w.wset("shszhkstockholdings", "date=" + date + ";tradeboard=szn")
sh_holding_detail = pd.DataFrame(temp_sh.Data, index=temp_sh.Fields).T
sh_holding_detail['wind_code'] = sh_holding_detail['wind_code'].apply(
    rq.id_convert)
sz_holding_detail = pd.DataFrame(temp_sz.Data, index=temp_sz.Fields).T
sz_holding_detail['wind_code'] = sz_holding_detail['wind_code'].apply(
    rq.id_convert)
all_holding = pd.concat([sh_holding_detail,
                         sz_holding_detail]).set_index('wind_code')
md_t = md.T
all_holding = all_holding.reindex(md_t.index).fillna(0)
all_holding['cash_flow'] = all_holding['change_holdstocks'].mul(md_t[date])