예제 #1
0
    def cal_fund_regression_exposure_index_all(self,
                                               beg_date,
                                               end_date,
                                               period="D",
                                               fund_pool="指数+主动股票+灵活配置60基金",
                                               file_rewrite=False):
        """ 回归基金池内所有基金指数暴露 """

        quarter_date = Date().get_last_fund_quarter_date(end_date)
        fund_pool = FundPool().get_fund_pool_all(quarter_date, fund_pool)
        fund_pool = fund_pool[fund_pool['if_etf'] == "非ETF基金"]
        fund_pool = fund_pool[fund_pool['if_a'] == "A类基金"]
        fund_pool = fund_pool[fund_pool['if_connect'] == "非联接基金"]
        fund_pool = fund_pool[fund_pool['if_hk'] == "非港股基金"]
        fund_pool = fund_pool.reset_index(drop=True)
        fund_pool.index = fund_pool['wind_code']
        print(len(fund_pool))

        for i_fund in range(0, len(fund_pool)):
            fund_code = fund_pool.index[i_fund]
            fund_name = fund_pool.sec_name[i_fund]
            file = '%s_%s_%s.csv' % (self.file_prefix, self.folder_name,
                                     fund_code)
            out_file = os.path.join(self.index_exposure_path, file)
            if not os.path.exists(out_file) or file_rewrite:
                print(fund_name, fund_code)
                self.cal_fund_regression_exposure_index(
                    fund_code, beg_date, end_date, period)
예제 #2
0
    def get_etf_fund_data(self, beg_date, end_date):
        """ 得到etf数据"""

        print("ETF Data %s %s" % (beg_date, end_date))
        exchange_share = FundFactor().get_fund_factor("Exchange_Share")
        exchange_share = exchange_share.fillna(method='pad', limit=3)

        unit_nav = FundFactor().get_fund_factor("Unit_Nav")
        unit_nav = unit_nav.fillna(method='pad', limit=1)

        exchange_share_date = pd.DataFrame(exchange_share.T[end_date])
        exchange_share_date.columns = ['Share']
        exchange_share_date_last = pd.DataFrame(exchange_share.T[beg_date])
        exchange_share_date_last.columns = ['ShareLast']

        unit_nav_date = pd.DataFrame(unit_nav.T[end_date])
        unit_nav_date.columns = ['UnitNav']

        fund_pool = FundPool().get_fund_pool_all(name="ETF基金", date="20181231")
        fund_pool = fund_pool[[
            'sec_name', 'wind_code', 'setupdate', 'bench_code', 'bench_name'
        ]]
        fund_pool.index = fund_pool.wind_code
        concat_data = pd.concat([
            fund_pool, unit_nav_date, exchange_share_date,
            exchange_share_date_last
        ],
                                axis=1)
        concat_data = concat_data.dropna()
        concat_data['MvEnd'] = concat_data['Share'] * concat_data['UnitNav']
        concat_data['Inflow'] = (
            concat_data['Share'] -
            concat_data['ShareLast']) * concat_data['UnitNav']
        concat_data['MvEnd'] /= 100000000.0
        concat_data['Inflow'] /= 100000000.0

        return concat_data