def bp(self): pb_daily = self.pb_daily pb = CALFUNC.d_freq_to_m_freq(pb_daily) bp = 1 / pb res = CALFUNC.del_dat_early_than(bp, START_YEAR) return res
def ep(self): pe_daily = self.pe_daily pe = CALFUNC.d_freq_to_m_freq(pe_daily) ep = 1 / pe res = CALFUNC.del_dat_early_than(ep, START_YEAR) return res
def MIDCAP(self): lncap = np.log(self.negotiablemv_daily * 10000) lncap = CALFUNC.d_freq_to_m_freq(lncap) y = lncap**3 X = lncap y = y.T X = X.T resid = pd.DataFrame() for code in y.columns: y_ = y[[code]] x_ = X[[code]] x_['const'] = 1 dat = pd.concat([x_, y_], axis=1) dat = dat.dropna(how='any', axis=0) X_, y_ = dat.iloc[:, :-1], dat.iloc[:, -1:] if len(y_) > 0: model = sm.WLS(y_, X_) result = model.fit() params_ = result.params resid_ = y_ - pd.DataFrame( np.dot(X_, params_), index=y_.index, columns=[code]) else: resid_ = pd.DataFrame([np.nan] * len(y), index=y.index, columns=[code]) resid = pd.concat([resid, resid_], axis=1) resid = resid.T resid = CALFUNC.del_dat_early_than(resid, START_YEAR) return resid
def return_n_m(self): close = self.closeprice_daily adj = self.adjfactor close, adj = self._align(close, adj) c_p = close * adj c_p = c_p.T c_v = c_p.values hh, ll = c_v.shape # 1个月、3个月、6个月、12个月 m1 = np.zeros(c_v.shape) m3 = np.zeros(c_v.shape) m6 = np.zeros(c_v.shape) m12 = np.zeros(c_v.shape) for i in range(21, ll): m1[:, i] = c_v[:, i] / c_v[:, i - 21] for i in range(21 * 3, ll): m3[:, i] = c_v[:, i] / c_v[:, i - 21 * 3] for i in range(21 * 6, ll): m6[:, i] = c_v[:, i] / c_v[:, i - 21 * 6] for i in range(21 * 12, ll): m12[:, i] = c_v[:, i] / c_v[:, i - 21 * 12] m1_df = pd.DataFrame(data=m1, index=c_p.index, columns=c_p.columns) m3_df = pd.DataFrame(data=m3, index=c_p.index, columns=c_p.columns) m6_df = pd.DataFrame(data=m6, index=c_p.index, columns=c_p.columns) m12_df = pd.DataFrame(data=m12, index=c_p.index, columns=c_p.columns) m1_df_m = CALFUNC.d_freq_to_m_freq(m1_df) m3_df_m = CALFUNC.d_freq_to_m_freq(m3_df) m6_df_m = CALFUNC.d_freq_to_m_freq(m6_df) m12_df_m = CALFUNC.d_freq_to_m_freq(m12_df) m1_df_m1 = CALFUNC.del_dat_early_than(m1_df_m, START_YEAR) m3_df_m1 = CALFUNC.del_dat_early_than(m3_df_m, START_YEAR) m6_df_m1 = CALFUNC.del_dat_early_than(m6_df_m, START_YEAR) m12_df_m1 = CALFUNC.del_dat_early_than(m12_df_m, START_YEAR) res_dict = { 'RETURN_1M': m1_df_m1 - 1, 'RETURN_3M': m3_df_m1 - 1, 'RETURN_6M': m6_df_m1 - 1, 'RETURN_12M': m12_df_m1 - 1, } return res_dict
def is_open(self): open = self.openPrice_daily high = self.highprice_daily low = self.lowPrice_daily if self._status == 'all': # 不是停牌的 is_open = ~pd.isna(open) # 不是开盘涨跌停的 tmp1 = open == high tmp2 = high == low tmp = ~(tmp1 & tmp2) is_open = tmp & is_open is_open = CALFUNC.d_freq_to_m_freq(is_open, shift=True) is_open = CALFUNC.del_dat_early_than(is_open, START_YEAR) elif self._status == 'update': factor = self.IS_OPEN # 先删除过去计算的bug to_del = [c for c in factor.columns if c not in self._mes] factor.drop(to_del, axis=1, inplace=True) latest_dt = factor.columns[-1] # 删除无用的日频数据 saved_cols = [i for i in open.columns if i > latest_dt] open = open[saved_cols] high = high[saved_cols] low = low[saved_cols] is_open = ~pd.isna(open) # 不是开盘涨跌停的 tmp1 = open == high tmp2 = high == low tmp = ~(tmp1 & tmp2) is_open = tmp & is_open is_open = CALFUNC.d_freq_to_m_freq(is_open, shift=True) is_open = pd.concat([factor, is_open], axis=1) return is_open
def LNCAP_Barra(self): lncap = np.log(self.negotiablemv_daily * 10000) lncap = CALFUNC.d_freq_to_m_freq(lncap) lncap = CALFUNC.del_dat_early_than(lncap, START_YEAR) return lncap
def Mkt_cap_float(self): negotiablemv = self.negotiablemv_daily negotiablemv = CALFUNC.d_freq_to_m_freq(negotiablemv) res = CALFUNC.del_dat_early_than(negotiablemv, START_YEAR) return res