Example #1
0
    def _calc_factor_loading(cls, code, calc_date):
        """
        计算指定日期、指定个股EGRLF因子载荷
        Parameters:
        --------
        :param code: str
            个股代码, 如SH600000, 600000
        :param calc_date: datetime-like, str
            计算日期, 格式: YYYY-MM-DD
        :return: pd.Series
        --------
            个股的EGRLF因子载荷
            0. code
            1. egrlf
            如果计算失败, 返回None
        """
        code = Utils.code_to_symbol(code)
        calc_date = Utils.to_date(calc_date)
        # 读取个股的预期盈利增长率数据
        earningsgrowth_data = Utils.get_consensus_data(
            calc_date, code, ConsensusType.PredictedEarningsGrowth)
        if earningsgrowth_data is None:
            # 如果个股的预期盈利增长率数据不存在, 那么用过去3年净利润增长率代替
            hist_growth_data = Utils.get_hist_growth_data(code, calc_date, 3)
            if hist_growth_data is None:
                return None
            if np.isnan(hist_growth_data['netprofit']):
                return None
            egrlf = hist_growth_data['netprofit']
        else:
            egrlf = earningsgrowth_data['growth_2y']

        return pd.Series([code, egrlf], index=['code', 'egrlf'])
Example #2
0
    def _calc_factor_loading(cls, code, calc_date):
        """
        计算指定日期、指定个股EPFWD因子载荷
        Parameters:
        --------
        :param code: str
            个股代码, 如SH600000, 600000
        :param calc_date: datetime-like, str
            计算日期, 格式: YYYY-MM-DD
        :return: pd.Series
        --------
            个股的EPFWD因子载荷
            0. code
            1. epfwd
            如果计算失败, 返回None
        """
        code = Utils.code_to_symbol(code)
        # 读取个股的预期盈利数据
        predictedearnings_data = Utils.get_consensus_data(
            calc_date, code, ConsensusType.PredictedEarings)
        if predictedearnings_data is None:
            # 如果个股的预期盈利数据不存在, 那么代替ttm净利润
            ttm_fin_data = Utils.get_ttm_fin_basic_data(code, calc_date)
            if ttm_fin_data is None:
                return None
            predictedearnings_data = pd.Series(
                [code, ttm_fin_data['NetProfit']],
                index=['code', 'predicted_earnings'])
        fpredictedearnings = predictedearnings_data['predicted_earnings']
        if np.isnan(fpredictedearnings):
            return None
        # 读取个股市值
        size_path = os.path.join(factor_ct.FACTOR_DB.db_path,
                                 risk_ct.LNCAP_CT.db_file)
        size_factor_loading = Utils.read_factor_loading(
            size_path, Utils.datetimelike_to_str(calc_date, dash=False), code)
        if size_factor_loading.empty:
            return None
        # epfwd = 盈利预期/市值
        epfwd = fpredictedearnings * 10000.0 / np.exp(
            size_factor_loading['factorvalue'])

        return pd.Series([code, epfwd], index=['code', 'epfwd'])