def cal_factor_liquidity_stom(beg_date, end_date):

    """
    LIQUIDITY_STOM 最近21个交易日的换手率总和的对数值
    """

    # params
    ##################################################################################
    raw_factor_name = "RAW_CNE5_LIQUIDITY_STOM"
    factor_name = "NORMAL_CNE5_LIQUIDITY_STOM"
    M = 21

    # read data
    ##################################################################################
    turnover_daily = Stock().get_factor_h5("TurnOver_Daily", None, 'primary_mfc').T
    data_beg_date = Date().get_trade_date_offset(beg_date, -M)
    end_date = Date().change_to_str(end_date)
    turnover_daily = turnover_daily.ix[data_beg_date:end_date, :]
    turnover_month = turnover_daily.rolling(window=M).sum().applymap(np.log)
    turnover_month = turnover_month.ix[beg_date:end_date, :]
    turnover_month = turnover_month.replace(-np.inf, np.nan)
    turnover_month = turnover_month.replace(np.inf, np.nan)
    turnover_month = turnover_month.dropna(how='all').T

    # save data
    ##################################################################################
    Stock().write_factor_h5(turnover_month, raw_factor_name, 'barra_risk_dfc')
    turnover_month = FactorPreProcess().remove_extreme_value_mad(turnover_month)
    turnover_month = FactorPreProcess().standardization_free_mv(turnover_month)
    Stock().write_factor_h5(turnover_month, factor_name, 'barra_risk_dfc')
    ##################################################################################
    return turnover_month
    def cal_factor_barra_cumulative_range(self, beg_date, end_date):
        """ 过去1-12月最大累计收益 和最小累计收益的差 """

        # param
        t = 12
        month_days = 21

        pct_chg = Stock().read_factor_h5("Pct_chg").applymap(
            lambda x: np.log(x / 100 + 1)).T

        date_series = Date().get_trade_date_series(beg_date, end_date)
        date_series = list(set(date_series) & set(pct_chg.columns))
        date_series.sort()

        pct_chg_panel = pd.Panel()

        for i in range(t):

            length = month_days * (i + 1)
            pct_chg_sum = pct_chg.rolling(length).sum()
            pct_chg_sum = pct_chg_sum.dropna(how='all')
            pct_chg_panel = pd.concat([pct_chg_panel, pct_chg_sum], axis=0)

        pct_max = pct_chg_panel.max(axis=0)
        pct_max = pct_max.applymap(lambda x: np.log(x + 1)).T
        pct_min = pct_chg_panel.min(axis=0)
        pct_min = pct_min.applymap(lambda x: np.log(x + 1)).T
        res = pct_max.sub(pct_min)

        self.save_risk_factor_exposure(res, self.raw_factor_name_range)
        res = Stock().remove_extreme_value_mad(res)
        res = Stock().standardization(res)
        self.save_risk_factor_exposure(res, self.factor_name_range)
Beispiel #3
0
    def cal_factor_liquidity_yearly(self):

        """ LIQUIDITY_STOM 最近252个交易日的换手率总和的对数值 """

        P = 252
        turnover_daily = Stock().read_factor_h5("TurnOver_Daily").T
        turnover_period = turnover_daily.rolling(window=P).sum().applymap(np.log)
        turnover_period = turnover_period.T.dropna(how='all')

        self.save_risk_factor_exposure(turnover_period, self.raw_factor_name_yearly)
        turnover_period = FactorPreProcess().remove_extreme_value_mad(turnover_period)
        turnover_period = FactorPreProcess().standardization(turnover_period)
        self.save_risk_factor_exposure(turnover_period, self.factor_name_yearly)
Beispiel #4
0
    def cal_factor_barra_growth_5years_profit_growth(self, beg_date, end_date):

        """ 过去5年每股盈利 回归 等差数列 的系数 除以 每股盈利的平均值 """

        report_data = Stock().read_factor_h5("ReportDateDaily")
        eps = Stock().read_factor_h5("EPS_basic").T

        eps_ttm = eps.rolling(4).sum()
        month = eps_ttm.index[-1][4:6]
        eps_ttm_quarter = eps_ttm.index
        eps_ttm_year = list(filter(lambda x: x[4:6] == month, list(eps_ttm.index)))
        eps_ttm = eps_ttm.loc[eps_ttm_year, :]

        eps_ttm_growth = eps_ttm.rolling(5).apply(self.slope)
        eps_ttm_growth = eps_ttm_growth.loc[eps_ttm_quarter, :]
        eps_ttm_growth = eps_ttm_growth.fillna(method='pad', limit=3).T
        eps_ttm_growth = StockFactor().change_quarter_to_daily_with_disclosure_date(eps_ttm_growth, report_data,
                                                                                    beg_date, end_date)
        self.save_risk_factor_exposure(eps_ttm_growth, self.raw_factor_name_5y_profit)
        eps_ttm_growth = FactorPreProcess().remove_extreme_value_mad(eps_ttm_growth)
        eps_ttm_growth = FactorPreProcess().standardization(eps_ttm_growth)
        self.save_risk_factor_exposure(eps_ttm_growth, self.factor_name_5y_profit)