Пример #1
0
 def save_ic_analysis_result(self, factor_name):
     with MongoConnect(DatabaseName.MULTI_FACTOR_DATA.value):
         ic_df = self.ic_df.copy()
         p_value_df = self.p_value_df.copy()
         ic_df.index = ic_df.index.format()
         p_value_df.index = p_value_df.index.format()
         doc = FactorIcAnalysisResult(
             factor_name=factor_name,
             # 因子数据开始时间
             begin_date=self.factor.index[0],
             # 因子数据结束时间
             end_date=self.factor.index[-1],
             # IC信号衰减计算,index 是时间序列, columns是decay周期,[1, self.ic_decay], 闭区间
             ic=ic_df,
             # p值信号衰减计算,index 是时间序列, columns是decay周期,[1, self.ic_decay], 闭区间
             p_value=p_value_df,
             ic_result=self.ic_result)
         doc.save()
Пример #2
0
 def save_ic_analysis_result(self, factor_name):
     with MongoConnect(DatabaseName.MULTI_FACTOR_DATA.value):
         ic_df = self.ic_df.copy()
         p_value_df = self.p_value_df.copy()
         ic_df.index = ic_df.index.format()
         p_value_df.index = p_value_df.index.format()
         doc = FactorIcAnalysisResult(
             factor_name=factor_name,
             # 因子数据开始时间
             begin_date=self.factor.index[0],
             # 因子数据结束时间
             end_date=self.factor.index[-1],
             # IC信号衰减计算,index 是时间序列, columns是decay周期,[1, self.ic_decay], 闭区间
             ic=ic_df,
             # p值信号衰减计算,index 是时间序列, columns是decay周期,[1, self.ic_decay], 闭区间
             p_value=p_value_df,
             # IC均值、 IC标准差、 IC_IR比率、 IC > 0 占比、 | IC | > 0.02 占比(绝对值)、 偏度、 峰度、
             # 正相关显著比例、负相关显著比例、状态切换比例、同向比例
             # index_list=['ic_mean', 'ic_std', 'ic_ir', 'ic_ratio', 'ic_abs_ratio', 'ic_skewness', 'ic_kurtosis',
             #             'ic_positive_ratio', 'ic_negative_ratio', 'ic_change_ratio', 'ic_unchange_ratio', ]
             ic_result=self.ic_result)
         doc.save()
Пример #3
0
        factor_ic = {}
        factor_return = {}
        for factor_name in factor_list:
            factor_regression_analysis_result = FactorRegressionAnalysisResult.objects(factor_name=factor_name) \
                .only('factor_name') \
                .only('begin_date') \
                .only('end_date') \
                .only('factor_return') \
                .as_pymongo()
            factor_return[factor_name] = pd.DataFrame(
                factor_regression_analysis_result[0]['factor_return'])
            factor_return[factor_name].index = pd.DatetimeIndex(
                factor_return[factor_name].index)

            factor_ic_result = FactorIcAnalysisResult.objects(factor_name=factor_name) \
                .only('factor_name') \
                .only('begin_date') \
                .only('end_date') \
                .only('ic') \
                .as_pymongo()
            # print(factor_ic_result)
            factor_ic[factor_name] = pd.DataFrame(factor_ic_result[0]['ic'])
            factor_ic[factor_name].index = pd.DatetimeIndex(
                factor_ic[factor_name].index)

    factor_weighting_obj = FactorWeighting(factor_data)
    # factor_weighted = factor_weighting_obj.weighting(weight_method='return_half_life', data=factor_return, half_life=5)
    factor_weighted = factor_weighting_obj.weighting(weight_method='max_ic_ir',
                                                     data=factor_ic,
                                                     window=20)