qlib踩坑记录

张开发
2026/4/6 11:44:17 15 分钟阅读

分享文章

qlib踩坑记录
涨跌停原始的qlib对涨跌停支持的比较简陋1、需要feature中有 change 数据2、设置 limit_threshold0.095更精确一点的做法是需要手工设置涨跌停数据此方案暂未测试extra_quotepd.DataFrame(data{$close:[10.0,10.5,11.0],# 必需字段$factor:[1.0,1.0,1.0],# 必需字段limit_buy:[False,True,False],# 自定义买入限制limit_sell:[False,False,True],# 自定义卖出限制# 其他字段...},indexpd.MultiIndex.from_tuples([(SH600000,2020-01-01),(SH600000,2020-01-02),(SH600000,2020-01-03)],names[instrument,datetime]))停牌股qlib 默认处理停牌是要判断 $close 是否为NaN有些数据源的处理不是如此defcheck_stock_suspended(self,stock_id:str,start_time:pd.Timestamp,end_time:pd.Timestamp,)-bool:if stock is suspended(hence not tradable), True will be returned# is suspendedifstock_idinself.quote.get_all_stock():# suspended stocks are represented by None $close stock# The $close may contain NaN,closeself.quote.get_data(stock_id,start_time,end_time,$close)ifcloseisNone:# if no close record existsreturnTrueelifisinstance(close,IndexData):# **any** non-NaN $close represents trading opportunity may exist# if all returned is nan, then the stock is suspendedreturncast(bool,cast(IndexData,close).isna().all())else:# it is single value, make sure is not Nonereturnnp.isnan(close)else:# if the stock is not in the stock list, then it is not tradable and regarded as suspendedreturnTrue

更多文章