Exemplo n.º 1
0
def Cal_AllFund_HalfYear_Holding_Exposure(path, report_date, today):
    """
    计算重点基金最近一个半年报 的持仓风格暴露
    """
    # 参数举例
    #####################################################################
    # path = 'E:\\3_Data\\4_fund_data\\8_fund_index_exposure_weekly\\'
    # report_date = '20171231'
    # today = datetime.today().strftime("%Y%m%d")

    # 基金池
    #####################################################################
    fund_pool_file = os.path.join(path, "fund_pool", '重点基金信息.csv')
    fund_pool = pd.read_csv(fund_pool_file, index_col=[0], encoding='gbk')
    fund_pool = fund_pool[fund_pool['种类'] != '1专户量化']
    date = Date().get_trade_date_offset(report_date, 0)

    # 计算重点所有重点 基金最近一个半年报 的持仓风格暴露
    #####################################################################
    for i_fund in range(0, len(fund_pool)):

        fund_code = fund_pool.index[i_fund]
        Fund().cal_fund_holder_exposure_halfyear(fund_code,
                                                 beg_date="20171231",
                                                 end_date=today)
        print(fund_code, report_date)

        if i_fund == 0:
            exposure = Fund().get_fund_holder_exposure_halfyear_date(
                fund_code, date=report_date, type_list=["STYLE", "COUNTRY"])
        else:
            exposure_add = Fund().get_fund_holder_exposure_halfyear_date(
                fund_code, date=report_date, type_list=["STYLE", "COUNTRY"])
            exposure = pd.concat([exposure, exposure_add], axis=0)

    #####################################################################
    exposure.index = fund_pool['基金名称']
    cols = list(exposure.columns)
    cols.insert(0, 'Type')
    exposure['Type'] = fund_pool['种类'].values
    exposure = exposure[cols]
    exposure['CTY'] = "ChinaEquity"
    del exposure['ChinaEquity']

    exposure_file = os.path.join(
        path, "halfyear_holding_exposure",
        'FundHalfYearExposure_' + report_date + '.csv')
    exposure.to_csv(exposure_file)
Exemplo n.º 2
0
    def get_fund_pool(self, end_date):

        """ 成立时间满足一定时间的基金 """

        print("Project Nice Stock Fund Getting Fund Pool at %s ......" % end_date)
        fund_pool = Fund().get_fund_pool_all(name=self.fund_pool_name, date="20181231")
        fund_info = Fund().get_wind_fund_info()
        fund_pool.index = fund_pool['wind_code']
        fund_data = pd.concat([fund_pool, fund_info], axis=1)

        setup_date = Date().get_trade_date_offset(end_date, -self.setup_date_len)

        fund_data = fund_data[fund_data['SetupDate'] <= setup_date]
        fund_data = fund_data[['sec_name', 'SetupDate', 'InvestType', 'Corp']]
        fund_data.columns = ['SecName', 'SetupDate', 'InvestType', 'Corp']
        fund_data = fund_data.dropna()

        return fund_data