def _init_estimation_flow(self): flow_name = self.user_context.flow_config.get("est_flow_name", "est_flow") self._estimation_flow = SensorFlow(name=flow_name, data_manager=self.user_context.DM) # factor date = yesterday self._estimation_flow.add_next_step2(name="factor_as_of_date", sensor=GetDate, kwds={'offset': 1} ) # module 4. 确定对Risk数据进行数据清洗的集合 self._estimation_flow.add_next_step2(name="riskPool", sensor=GetPool, call=None, # 这里用factor_as_of_date input_var=[f"{flow_name}.factor_as_of_date.date"], kwds={"pool_name": self.user_context.pool_name, "benchmark_weight": "weight_index_500" }) # module 11. 保存 self._estimation_flow.add_next_step2( name="saveToNpy_pool", sensor=SaveToBundleSensor, call=None, input_var=[f"{flow_name}.factor_as_of_date.date", f"{flow_name}.riskPool.pool"], kwds={ 'bundle': self.user_context.config.base.data_bundle_path, 'type': "pool", 'name': "pool_01_final" } )
def _init_prepare_flow(self): self._prepare_flow = SensorFlow(name="prepare_flow", data_manager=self.user_context.DM) # module 1. 确定Alpha因子清单 self._prepare_flow.add_next_step2( name="alphaFactorList", sensor=GetFactorList, kwds={"factor_list": self.user_context.alphaFactorDataFrame})
def _init_store_flow(self): est_flow = self.user_context.flow_config.get("est_flow_name", "estimation_flow") self._store_flow = SensorFlow(name="store_flow", data_manager=self.user_context.DM) self._store_flow.add_next_step2( name="store", sensor=Store, call=None, input_var=[ "store_flow.store.factorReturn", "store_flow.store.factorName", "store_flow.store.dateList", f"{est_flow}.OLS.coefficient", "prepare_flow.alphaFactorList.factorList" ], alias={ "store_flow.store.factorName": "col_names", "prepare_flow.alphaFactorList.factorList": "factorName" }, kwds={})
def _init_prediction_stock(self): est_flow = self.user_context.flow_config.get("est_flow_name", "estimation_flow") pred_flow = self.user_context.flow_config.get("pred_flow_name", "prediction_stock") # silent = (not self.user_context.debug) if hasattr(self.user_context, "debug") else True self._prediction_stock = SensorFlow(pred_flow, data_manager=self.user_context.DM) # module 2. 预测factor_return self._prediction_stock.add_next_step2( name="predictionFactorReturn", sensor=PredictionFactorReturn, input_var=[ "store_flow.store.factorReturn", "store_flow.store.factorName" ], kwds={"rolling_window": self.user_context.rolling_window}, silent=False) # module 3. 预测因子协方差矩阵 self._prediction_stock.add_next_step2( name="predictionFactorCovariance", sensor=PredictionFactorCovariance, input_var=[ "store_flow.store.factorReturn", "store_flow.store.factorName" ], kwds={"rolling_window": self.user_context.rolling_window}, silent=False) # 取昨日因子数据 self._prediction_stock.add_next_step2(name="factor_as_of_date", sensor=GetDate, kwds={'offset': 1}) factorList = {} for k in self.user_context.alphaFactorDataFrame.factor_dataFrame.factor: factorList[k + "_f1"] = FACTOR_STYLE.SECTOR # module 7. 取alpha数据 self._prediction_stock.add_next_step2( name="orthogonalization", sensor=GetFactorData, call=None, input_var=[f"{pred_flow}.factor_as_of_date.date"], kwds={"factorList": factorList}) # module 7. 预测股票收益 self._prediction_stock.add_next_step2( name="predictionStockReturn", sensor=PredictionStockReturn, input_var=[ f"{pred_flow}.predictionFactorReturn.factorReturn", f"{pred_flow}.orthogonalization.exposure", f"{est_flow}.OLS.model" ], kwds={}, silent=False) self._prediction_stock.add_next_step2( name="saveToNpy_return", sensor=SaveToBundleSensor, call=None, input_var=[ f"{pred_flow}.factor_as_of_date.date", f"{pred_flow}.predictionStockReturn.stockReturn" ], kwds={ 'bundle': self.user_context.config.base.data_bundle_path, 'suffix': 'f1', 'type': "return", 'name': "predicted_stock_return" })
def _init_estimation_flow(self): flow_name = self.user_context.flow_config.get("est_flow_name", "est_flow") self._estimation_flow = SensorFlow(name=flow_name, data_manager=self.user_context.DM) # factor date self._estimation_flow.add_next_step2(name="factor_as_of_date", sensor=GetDate, kwds={'offset': self.user_context.forward_period + 2} ) # module 4. 确定对Risk数据进行数据清洗的集合 self._estimation_flow.add_next_step2(name="riskPool", sensor=GetPool, call=None, # 这里用factor_as_of_date input_var=[f"{flow_name}.factor_as_of_date.date"], kwds={"pool_name": self.user_context.pool_name}) factorList = {} for k in self.user_context.riskFactorDataFrame.factor_dataFrame.factor: factorList[k] = FACTOR_STYLE.SECTOR if k.startswith("industry") else FACTOR_STYLE.RISK # module 6. 取risk数据 self._estimation_flow.add_next_step2(name="riskFactorData", sensor=GetFactorData, call=None, input_var=[f"{flow_name}.riskPool.pool", f"{flow_name}.factor_as_of_date.date" ], kwds={"factorList": factorList, "data_process_methods": { FACTOR_STYLE.SECTOR: [], FACTOR_STYLE.RISK: [ DataProcessing.do_process_extremum_winsorize, DataProcessing.do_z_score_processing ] }}, silent=False) try: open_price_type = self.user_context.est_open_price except Exception as e: user_log.warning("no est_open_price in config file") open_price_type = "open_aft" try: close_price_type = self.user_context.est_close_price except Exception as e: user_log.warning("no est_close_price in config file") close_price_type = "open_aft" user_log.info("est open_price_type is : " + open_price_type) user_log.info("est close_price_type is : " + close_price_type) # module 8. 取return数据 self._estimation_flow.add_next_step2(name="returnData", sensor=GetReturnData, call=None, input_var=[f"{flow_name}.riskFactorData.exposure", f"{flow_name}.riskPool.pool", f"{flow_name}.factor_as_of_date.date" ], alias={ f"{flow_name}.riskFactorData.exposure": "neutralize_matrix", }, kwds={"data_process_methods": [ DataProcessing.do_process_extremum_winsorize, DataProcessing.neutrialize], "n": self.user_context.forward_period, "open_price_type": open_price_type, "close_price_type": close_price_type }, silent=True) self._estimation_flow.add_next_step2( name="saveToNpy_return", sensor=SaveToBundleSensor, call=None, input_var=[f"{flow_name}.factor_as_of_date.date", f"{flow_name}.returnData.stockReturn"], kwds={ 'bundle': self.user_context.config.base.data_bundle_path, 'suffix': 'f1', 'type': "return", 'name': "forward_return_%d" % self.user_context.forward_period } )
def _init_estimation_flow(self): flow_name = self.user_context.flow_config.get("est_flow_name", "est_flow") risk_flow_name = self.user_context.flow_config.get( "forward_return_flow_name", "flow_forward_return") self._estimation_flow = SensorFlow(name=flow_name, data_manager=self.user_context.DM) # factor date = forward_period + 2 self._estimation_flow.add_next_step2(name="factor_as_of_date", sensor=GetDate, kwds={'offset': 1}) # module 4. 确定对Risk数据进行数据清洗的集合 self._estimation_flow.add_next_step2( name="riskPool", sensor=GetPool, call=None, # 这里用factor_as_of_date input_var=[f"{flow_name}.factor_as_of_date.date"], kwds={"pool_name": self.user_context.pool_name}) factorList = {} for k in self.user_context.alphaFactorDataFrame.factor_dataFrame.factor: factorList[k] = FACTOR_STYLE.ALPHA # module 7. 取alpha数据 self._estimation_flow.add_next_step2( name="alphaFactorData", sensor=GetFactorData, call=None, input_var=[ f"{risk_flow_name}.riskFactorData.exposure", f"{flow_name}.riskPool.pool", f"{flow_name}.factor_as_of_date.date" ], kwds={ "factorList": factorList, "data_process_methods": { FACTOR_STYLE.ALPHA: [ DataProcessing.do_process_extremum_winsorize, DataProcessing.do_z_score_processing, DataProcessing.neutrialize ] } }, silent=True) self._estimation_flow.add_next_step2( name="orthogonalization", sensor=Orthogonalization_Schmidt, call=None, input_var=[ f"{flow_name}.alphaFactorData.exposure", f"{flow_name}.alphaFactorData.factorName", f"{flow_name}.riskPool.pool" ], kwds={}) self._estimation_flow.add_next_step2( name="saveToNpy_alpha", sensor=SaveToBundleSensor, call=None, input_var=[ f"{flow_name}.factor_as_of_date.date", f"{flow_name}.orthogonalization.exposure", f"{flow_name}.orthogonalization.factorName" ], kwds={ 'bundle': self.user_context.config.base.data_bundle_path, 'type': "factor", 'suffix': 'f1' })