def set_all_data(self, quantity_change_info, price_change_info, index_info): df, _ = self.read() if df.empty: logger.error("read empty file for:%s" % self.code) return False #modify price and quanity for all split-adjusted share prices df = self.adjust_share(df, quantity_change_info) if df.empty: logger.error("adjust share %s failed" % self.code) return False df = self.qfq(df, price_change_info) if df.empty: logger.error("qfq %s failed" % self.code) return False #transfer data to split-adjusted share prices df = self.transfer2adjusted(df) #compute strength relative index df = self.relative_index_strength(df, index_info) if df is None: logger.error("length of code %s is not equal to index." % self.code) return False #set chip distribution dist_data = self.compute_distribution(df) if dist_data.empty: logger.error("%s is empty distribution." % self.code) return False if not self.set_chip_distribution(dist_data): logger.error("store %s distribution failed" % self.code) return False df['uprice'] = mac(dist_data, 0) df['sprice'] = mac(dist_data, 5) df['mprice'] = mac(dist_data, 13) df['lprice'] = mac(dist_data, 37) df = pro_nei_chip(df, dist_data) if is_df_has_unexpected_data(df): logger.error("data for %s is not clean." % self.code) return False day_table = self.get_day_table() if not self.mysql_client.delsert(df, day_table): logger.error("save %s data to mysql failed." % self.code) return False self.redis.sadd(day_table, *set(df.date.tolist())) return True
def set_today_data(self, df, index_df, pre_date, cdate): day_table = self.get_day_table() if self.is_date_exists(day_table, cdate): logger.debug("existed data for code:%s, date:%s" % (self.code, cdate)) return True index_df = index_df.loc[index_df.date == cdate] preday_df = self.get_k_data(date=pre_date) if preday_df is None: logger.error("%s get pre date data failed." % self.code) return False if preday_df.empty: logger.error("%s get pre date data empty." % self.code) return False df['adj'] = 1.0 df['preclose'] = preday_df['close'][0] df['totals'] = preday_df['totals'][0] df['outstanding'] = preday_df['outstanding'][0] #transfer data to split-adjusted share prices df = self.transfer2adjusted(df) df = self.relative_index_strength(df, index_df, cdate) if df is None: return False #set chip distribution dist_df = df.append(preday_df, sort=False) dist_df = dist_df.sort_values(by='date', ascending=True) dist_data = self.compute_distribution(dist_df, cdate) if dist_data.empty: logger.error("%s chip distribution compute failed." % self.code) return False if self.set_chip_distribution(dist_data, zdate=cdate): df['uprice'] = mac(dist_data, 0) df['sprice'] = mac(dist_data, 5) df['mprice'] = mac(dist_data, 13) df['lprice'] = mac(dist_data, 37) df = pro_nei_chip(df, dist_data, preday_df, cdate) if is_df_has_unexpected_data(df): logger.error("data for %s is not clean." % self.code) return False if self.mysql_client.set(df, self.get_day_table()): return self.redis.sadd(day_table, cdate) return False