大家在做回测的时候,通常需要过滤新股的一字涨停阶段,毕竟这个时间点是没办法买入的。
话不多说,代码如下:
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 是 一字涨停股