예제 #1
0
    def equal_weighted_factor(self, factors_dict):
        """
        将若干个因子等权重合成新因子
        :param factors_dict: 若干因子组成的字典(dict),形式为:
                             {"factor_name_1":factor_1,"factor_name_2":factor_2}
                            每个因子值格式为一个MultiIndex Series,索引(index)为date(level 0)和asset(level 1),
                            包含一列factor值。
        :return: MultiFactor 对象。包含三个属性:
             "name":合成的因子名称(str)
                "multifactor_value":合成因子值(MultiIndex Series,索引(index)为date(level 0)和asset(level 1),
                                    包含一列factor值)
                "weight": 加权方式 (str)
        """

        from fxdayu_alphaman.factor.utility import MultiFactor

        # 因子累加
        gather_result = self.combine_factor(list(factors_dict.values()))
        multifactor_name = "+".join(list(factors_dict.keys()))

        multifactor = MultiFactor()
        multifactor["name"] = multifactor_name
        multifactor["multifactor_value"] = gather_result
        multifactor["weight"] = "equal_weight"

        return multifactor
예제 #2
0
    def ic_shrink_cov_weighted_factor(self, factors_dict, ic_weight_shrink_df):
        """
        根据 Ledoit-Wolf 压缩的协方差矩阵估算方法得到的因子权重,将若干个因子按该权重加权合成新因子
        :param factors_dict: 若干因子组成的字典(dict),形式为:
                             {"factor_name_1":factor_1,"factor_name_2":factor_2}
                            每个因子值格式为一个MultiIndex Series,索引(index)为date(level 0)和asset(level 1),
                             包含一列factor值。
        :param ic_weight_shrink_df: 使用Ledoit-Wolf 压缩的协方差矩阵估算方法得到的因子权重(pd.Dataframe),
                                  可通过Admin.get_ic_weight_shrink_df 获取。
                                 索引(index)为datetime,columns为待合成的因子名称,与factors_dict一致。
        :return: MultiFactor 对象。包含三个属性:
             "name":合成的因子名称(str)
                "multifactor_value":合成因子值(MultiIndex Series,索引(index)为date(level 0)和asset(level 1),
                                    包含一列factor值)
                "weight": 加权方式 (str)
        """
        from fxdayu_alphaman.factor.utility import MultiFactor

        weight = ic_weight_shrink_df
        weighted_factor_value_list = []
        for factor_name in factors_dict.keys():
            original_factor = factors_dict[factor_name]
            w = pd.DataFrame(
                weight[factor_name].loc[original_factor.index.get_level_values(
                    level=0)])
            weighted_factor = pd.DataFrame(original_factor)
            weighted_factor.columns = [
                "factor",
            ]
            w.columns = [
                "factor",
            ]
            w.index = weighted_factor.index
            weighted_factor = weighted_factor * w
            weighted_factor_value_list.append(weighted_factor)

        # 因子累加
        gather_result = self.combine_factor(weighted_factor_value_list)
        multifactor_name = "+".join(list(factors_dict.keys()))

        multifactor = MultiFactor()
        multifactor["name"] = multifactor_name
        multifactor["multifactor_value"] = gather_result
        multifactor["weight"] = " ic_shrink_cov_weight"

        return multifactor