def load_daily_factor(self, file_name): load_path = f'{self.root_path}/EM_Funda/daily/' tmp_df = bt.AZ_Load_csv(os.path.join(load_path, file_name + '.csv')) if self.xinx[-1] not in tmp_df.index: send_email.send_email(file_name + self.sector_name, ['*****@*****.**'], [], '[LOADDATA]error') tmp_df = tmp_df.reindex(index=self.xinx, columns=self.xnms) target_df = self.row_extre(tmp_df, self.sector_df, 0.3) if self.if_only_long: target_df = target_df[target_df > 0] return target_df
def load_tech_factor(self, file_name): load_path = os.path.join('/media/hdd1/DAT_PreCalc/PreCalc_whs/' + self.sector_name) target_df = pd.read_pickle(os.path.join(load_path, file_name + '.pkl')) if self.xinx[-1] not in target_df.index: send_email.send_email(file_name + self.sector_name, ['*****@*****.**'], [], '[LOADDATA]error') target_df = target_df.reindex(index=self.xinx, columns=self.xnms) if self.if_only_long: target_df = target_df[target_df > 0] return target_df
def plot_send_result(pnl_df, sharpe_ratio, subject): figure_save_path = '/mnt/mfs/dat_whs/tmp_figure' plt.figure(figsize=[16, 8]) plt.plot(pnl_df.index, pnl_df.cumsum(), label='sharpe_ratio={}'.format(sharpe_ratio)) plt.legend() plt.savefig(os.path.join(figure_save_path, '{}.png'.format(subject))) text = '' to = ['*****@*****.**'] filepath = [os.path.join(figure_save_path, '{}.png'.format(subject))] send_email.send_email(text, to, filepath, subject)
def check_factor(self, name_list, file_name, check_path=None): if check_path is None: load_path = os.path.join('/mnt/mfs/dat_whs/data/new_factor_data/' + self.sector_name) else: load_path = check_path exist_factor = set([x[:-4] for x in os.listdir(load_path)]) print() use_factor = set(name_list) a = use_factor - exist_factor if len(a) != 0: print('factor not enough!') print(a) print(len(a)) send_email.send_email(f'{file_name} factor not enough!', ['*****@*****.**'], [], 'Factor Test Warning!')
def load_remy_factor(self, file_name): load_path = f'{self.root_path}/EM_Funda/DERIVED_F1' raw_df = bt.AZ_Load_csv(f'{load_path}/{file_name}') a = list(set(raw_df.iloc[-1, :100].dropna().values)) if self.xinx[-1] not in raw_df.index: send_email.send_email(file_name + self.sector_name, ['*****@*****.**'], [], '[LOADDATA]error') tmp_df = raw_df.reindex(index=self.xinx, columns=self.xnms) if len(a) > 5: target_df = self.row_extre(tmp_df, self.sector_df, 0.3) else: target_df = tmp_df pass if self.if_only_long: target_df = target_df[target_df > 0] return target_df
if hasattr(algorithm, 'labels_'): y_pred = algorithm.labels_.astype(np.int) else: y_pred = algorithm.predict(X) plt.subplot(len(datasets), len(clustering_algorithms), plot_num) if i_dataset == 0: plt.title(name, size=18) colors = np.array(list(islice(cycle(['#377eb8', '#ff7f00', '#4daf4a', '#f781bf', '#a65628', '#984ea3', '#999999', '#e41a1c', '#dede00']), int(max(y_pred) + 1)))) plt.scatter(X[:, 0], X[:, 1], s=10, color=colors[y_pred]) plt.xlim(-2.5, 2.5) plt.ylim(-2.5, 2.5) plt.xticks(()) plt.yticks(()) plt.text(.99, .01, ('%.2fs' % (t1 - t0)).lstrip('0'), transform=plt.gca().transAxes, size=15, horizontalalignment='right') plot_num += 1 plt.savefig('/mnt/mfs/dat_whs/tmp_figure/cluster.png') text = 'cluster figure' to = ['*****@*****.**'] filepath = ['/mnt/mfs/dat_whs/tmp_figure/cluster.png'] subject = 'haha' send_email.send_email(text, to, filepath, subject)