Exemple #1
0
def get_zz500s():
    """
    获取中证500成份股
    Return
    --------
    DataFrame
        code :股票代码
        name :股票名称
    """
    from quantkits.stock.fundamental import get_stock_basics
    try:
        #         df = pd.read_excel(ct.HS300_CLASSIFY_URL_FTP%(ct.P_TYPE['ftp'], ct.DOMAINS['idxip'],
        #                                                   ct.PAGES['zz500b']), parse_cols=[0,1])
        #         df.columns = ct.FOR_CLASSIFY_B_COLS
        #         df['code'] = df['code'].map(lambda x :str(x).zfill(6))
        wt = pd.read_excel(
            ct.HS300_CLASSIFY_URL_FTP %
            (ct.P_TYPE['ftp'], ct.DOMAINS['idxip'], ct.PAGES['zz500wt']),
            parse_cols=[0, 3, 6])
        wt.columns = ct.FOR_CLASSIFY_W_COLS
        wt['code'] = wt['code'].map(lambda x: str(x).zfill(6))
        df = get_stock_basics()[['name']]
        df = df.reset_index()
        return pd.merge(df, wt)
    except Exception as er:
        print(str(er))
Exemple #2
0
def get_gem_classified():
    """
        获取创业板股票
    Return
    --------
    DataFrame
        code :股票代码
        name :股票名称
    """
    df = fd.get_stock_basics()
    df.reset_index(level=0, inplace=True)
    df = df[ct.FOR_CLASSIFY_B_COLS]
    df = df.ix[df.code.str[0] == '3']
    df = df.sort('code').reset_index(drop=True)
    return df
Exemple #3
0
def get_area_classified():
    """
        获取地域分类数据
    Return
    --------
    DataFrame
        code :股票代码
        name :股票名称
        area :地域名称
    """
    df = fd.get_stock_basics()
    df = df[['name', 'area']]
    df.reset_index(level=0, inplace=True)
    df = df.sort('area').reset_index(drop=True)
    return df
Exemple #4
0
def get_st_classified():
    """
        获取风险警示板股票
    Return
    --------
    DataFrame
        code :股票代码
        name :股票名称
    """
    df = fd.get_stock_basics()
    df.reset_index(level=0, inplace=True)
    df = df[ct.FOR_CLASSIFY_B_COLS]
    df = df.ix[df.name.str.contains('ST')]
    df = df.sort('code').reset_index(drop=True)
    return df
Exemple #5
0
def get_hs300s():
    """
    获取沪深300当前成份股及所占权重
    Return
    --------
    DataFrame
        code :股票代码
        name :股票名称
        date :日期
        weight:权重
    """
    from quantkits.stock.fundamental import get_stock_basics
    try:
        wt = pd.read_excel(
            ct.HS300_CLASSIFY_URL_FTP %
            (ct.P_TYPE['ftp'], ct.DOMAINS['idxip'], ct.PAGES['hs300w']),
            parse_cols=[0, 3, 6])
        wt.columns = ct.FOR_CLASSIFY_W_COLS
        wt['code'] = wt['code'].map(lambda x: str(x).zfill(6))
        df = get_stock_basics()[['name']]
        df = df.reset_index()
        return pd.merge(df, wt)
    except Exception as er:
        print(str(er))