def trade_date_into_db(): delete_table() df = ak.tool_trade_date_hist_sina() df['trade_date'] = df['trade_date'].apply( lambda x: int(x[0:10].replace("-", ""))) df.to_sql("share_trade_date", engine, if_exists="append", index=False) return "success"
def __init__(self): self.database = Database() # 获取从1990-12-19至2020-12-31股票交易日数据 self.trade_date = ak.tool_trade_date_hist_sina()["trade_date"].tolist() self.label_range = { 3: "3DaysLabel", 5: "5DaysLabel", 10: "10DaysLabel", 15: "15DaysLabel", 30: "30DaysLabel", 60: "60DaysLabel" }
def if_trade(selectday: date = datetime.now().date()): """判断当日是否交易日""" import akshare as ak try: tool_trade_date_hist_sina_df = ak.tool_trade_date_hist_sina() tradedays = tool_trade_date_hist_sina_df.trade_date.to_list() except Exception as err: print("获取akshare的交易日历失败:", err) tradedays = [datetime.now().date()] if selectday in tradedays or selectday.strftime("%Y-%m-%d") in tradedays: return True else: return False
def __init__(self): self.database = Database() # 获取从1990-12-19至2020-12-31股票交易日数据 self.trade_date = ak.tool_trade_date_hist_sina()["trade_date"].tolist() self.label_range = {3: "3DaysLabel", 5: "5DaysLabel", 10: "10DaysLabel", 15: "15DaysLabel", 30: "30DaysLabel", 60: "60DaysLabel"} self.redis_client = redis.StrictRedis(host=config.REDIS_IP, port=config.REDIS_PORT, db=config.CACHE_NEWS_REDIS_DB_ID) self.redis_client.set("today_date", datetime.datetime.now().strftime("%Y-%m-%d")) self.redis_client.delete("stock_news_num_over_{}".format(config.MINIMUM_STOCK_NEWS_NUM_FOR_ML)) self._stock_news_nums_stat()
def __init__(self): self.database = Database() # 获取从1990-12-19至2020-12-31股票交易日数据 self.trade_date = ak.tool_trade_date_hist_sina()["trade_date"].tolist() self.label_range = { 3: "3DaysLabel", 5: "5DaysLabel", 10: "10DaysLabel", 15: "15DaysLabel", 30: "30DaysLabel", 60: "60DaysLabel" } self.redis_client = redis.StrictRedis(host=config.REDIS_IP, port=config.REDIS_PORT, db=config.CACHE_NEWS_REDIS_DB_ID) self.redis_client.set("today_date", datetime.datetime.now().strftime("%Y-%m-%d"))
def spider(future): vol = 'vol' long = 'long_open_interest' long_chg = 'long_open_interest_chg' short = 'short_open_interest' short_chg = 'short_open_interest_chg' trade_calendar = ak.tool_trade_date_hist_sina() nowdatetime = datetime.datetime.now() if int(nowdatetime.strftime("%H%M"))>1630: pass else: nowdatetime = nowdatetime-datetime.timedelta(days=1) for counts in range(30): if nowdatetime.strftime("%Y-%m-%d") in trade_calendar['trade_date'].values: tradedate = nowdatetime.strftime("%Y%m%d") break else: nowdatetime -= datetime.timedelta(days=1) if counts == 29: print("no trade day found!") return # get_ag_sum_daily_df = ak.get_rank_sum_daily(start_day='20201209',end_day='20201210',vars_list=['AG']) # get_au_sum_daily_df = ak.get_rank_sum_daily(start_day='20201209',end_day='20201210',vars_list=['AU']) ag_rank_table_df = ak.get_shfe_rank_table(date=tradedate,vars_list=[future]) ag = {long:0,short:0,long_chg:0,short_chg:0,vol:0} for df in ag_rank_table_df.values(): ag[vol] += df.loc[20,vol] ag[long] += df.loc[20,long] ag[short] += df.loc[20,short] ag[long_chg] += df.loc[20,long_chg] ag[short_chg] += df.loc[20,short_chg] stat = (ag[long]+ag[short])/ag[vol] ts = (ag[long_chg]-ag[short_chg])/np.abs(ag[long_chg]+ag[short_chg]) # how to use TS? print(ag) print(stat,ts) return ag
def __get_dates(self): dates = ak.tool_trade_date_hist_sina() dates.trade_date = pd.to_datetime(dates.trade_date) return dates
def trade_date_hist(): df = ak.tool_trade_date_hist_sina() return df