Esempio n. 1
0
 def fetch_predict_data(self, ref_date: str, alpha_model: ModelBase):
     return fetch_predict_phase(self.engine,
                                alpha_model.formulas,
                                ref_date,
                                self.freq,
                                self.universe,
                                self.batch,
                                self.neutralized_risk,
                                self.risk_model,
                                self.pre_process,
                                self.post_process,
                                self.warm_start,
                                fillna=True)
Esempio n. 2
0
    def predict(self, ref_date: str, x: pd.DataFrame = None) -> pd.DataFrame:
        if x is None:
            predict_data = fetch_predict_phase(
                self.data_meta.engine, self.data_meta.alpha_factors, ref_date,
                self.data_meta.freq, self.data_meta.universe,
                self.data_meta.batch, self.data_meta.neutralized_risk,
                self.data_meta.risk_model, self.data_meta.pre_process,
                self.data_meta.post_process, self.data_meta.warm_start)

            x_values = predict_data['predict']['x']
            codes = predict_data['predict']['code']
        else:
            x_values = x.values
            codes = x.index

        model = self._fetch_latest_model(ref_date)
        return pd.DataFrame(model.predict(x_values).flatten(), index=codes)
Esempio n. 3
0
    def model_predict(self, ref_date: str) -> pd.DataFrame:
        if self.cached_data and ref_date in self.scheduled_dates:
            ref_date = dt.datetime.strptime(ref_date, '%Y-%m-%d')
            ne_x = self.cached_data['predict']['x'][ref_date]
            settlement_data = self.cached_data['settlement']
            codes = settlement_data.loc[settlement_data.trade_date == ref_date,
                                        'code'].values
        else:
            data = fetch_predict_phase(self.data_source, self.features,
                                       ref_date, self.freq, self.universe,
                                       self.batch, self.neutralize_risk,
                                       self.risk_model, self.pre_process,
                                       self.post_process, self.warm_start)

            ne_x = data['predict']['x']
            codes = data['predict']['code']

        prediction = self.model.predict(ne_x).flatten()
        return pd.DataFrame({'prediction': prediction, 'code': codes})