转自 https://www.joinquant.com/post/15505
大家在做回测的时候,通常需要过滤新股的一字涨停阶段,毕竟这个时间点是没办法买入的。
话不多说,代码如下:
def is_newstock_limit_up(code):
"""是否是新股一字涨停股"""# 获取股票信息 security = jqdatasdk.get_security_info(code) start_date = security.start_date # 从交易日开始遍历该股票的上市日期,看是否全部是涨停板 all_trade_days = jqdatasdk.get_trade_days(start_date=start_date) all_trade_days = all_trade_days.tolist()[::-1][:-1] for trade_day in all_trade_days: stock_price_df = jqdatasdk.get_price(code, start_date=trade_day, end_date=trade_day) open_price = stock_price_df['open'][0] close_price = stock_price_df['close'][0] # 涨停板,收盘价等于开盘价 if close_price != open_price: return False # 最高价和最低价应该是一样的 high_price = stock_price_df['high'][0] low_price = stock_price_df['low'][0] if not high_price == low_price: return False return True
验证代码:
stock1 = '000001.XSHE' print("000001.XSHE", '是' if
is_newstock_limit_up(stock1) else '不是', '一字涨停股')stock2 = '002943.XSHE' print("002943.XSHE", '是' if
is_newstock_limit_up(stock2) else '不是', '一字涨停股')
验证结果:
auth success
000001.XSHE 不是 一字涨停股
002943.XSHE 是 一字涨停股
发布于 22天前8801
Released 22 days ago at 8801
轻灵划译
数据来源: