예제 #1
0
def update_index_wei():
    w.start()
    data = Data()
    zz500_wt = data.zz500_wt
    hs300_wt = data.hs300_wt

    mes = generate_months_ends()
    # 先删除一些不是月末的数据
    to_del = [c for c in zz500_wt.columns if c not in mes]
    if len(to_del) > 0:
        zz500_wt = zz500_wt.drop(to_del, axis=1)
    to_del = [c for c in hs300_wt.columns if c not in mes]
    if len(to_del) > 0:
        hs300_wt = hs300_wt.drop(to_del, axis=1)

    new_mes = [m for m in mes if m > zz500_wt.columns[-1]]

    for m in new_mes:
        m_str = m.strftime("%Y-%m-%d")
        # 沪深300
        res = w.wset("indexconstituent",
                     "date=" + m_str + ";windcode=000300.SH",
                     usedf=True)
        res = res[1]
        res.set_index('wind_code', inplace=True)
        to_add = pd.DataFrame({m: res['i_weight']})
        hs300_wt = pd.concat([hs300_wt, to_add], axis=1)

        # 中证500
        res = w.wset("indexconstituent",
                     "date=" + m_str + ";windcode=000905.SH",
                     usedf=True)
        res = res[1]
        res.set_index('wind_code', inplace=True)
        to_add = pd.DataFrame({m: res['i_weight']})
        zz500_wt = pd.concat([zz500_wt, to_add], axis=1)

    data.save(hs300_wt,
              'hs300_wt',
              save_path=r'D:\pythoncode\IndexEnhancement\指数相关')
    data.save(zz500_wt,
              'zz500_wt',
              save_path=r'D:\pythoncode\IndexEnhancement\指数相关')
예제 #2
0
def update_f_data_from_wind():
    path = r'D:\pythoncode\IndexEnhancement\barra_cne6\download_from_juyuan'
    w.start()

    data = Data()
    stock_basic_inform = data.stock_basic_inform

    # m_list = w.tdays(tds, eds, "Days=Alldays;Period=Q", usedf=True)
    # m_list = m_list[1]
    # m_list = list(m_list[m_list.columns[0]])
    iterms = [
        'rd_exp',  # 研发费用
    ]
    codes_str = ''
    for i in stock_basic_inform.index:
        codes_str = codes_str + ',' + i
    codes_str = codes_str[1:]

    eds = datetime.today().strftime("%Y-%m-%d")

    for it in iterms:
        try:
            tmp_df = eval('data.' + it)
            tds = tmp_df.columns[-1]
        except Exception as e:
            tmp_df = pd.DataFrame()
            tds = datetime(2009, 1, 1)

        if (datetime.today() - tds).days > 110:
            res_tmp = w.wsd(codes_str,
                            it,
                            tds.strftime("%Y-%m-%d"),
                            eds,
                            "unit=1;rptType=1;Period=Q;Days=Alldays",
                            usedf=True)
            res_tmp1 = res_tmp[1]
            res_tmp1 = res_tmp1.T
            tmp_df = pd.concat([tmp_df, res_tmp1], axis=1)
            data.save(tmp_df, it, save_path=path)