连板指标是交易软件常见的指标,便于我们了解热点和股票
# 本代码由可视化策略环境自动生成 2022年5月12日 22:33
# 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
m1 = M.instruments.v2(
start_date='2018-01-01',
end_date='2020-12-31',
market='CN_STOCK_A',
instrument_list='',
max_count=0
)
m3 = M.input_features.v1(
features="""# 当天涨停 即为TRUE ,否则为FALSE
_bool = where(price_limit_status_0==3 , True, False)"""
)
m15 = M.general_feature_extractor.v7(
instruments=m1.data,
features=m3.data,
start_date='',
end_date='',
before_start_days=90
)
m16 = M.derived_feature_extractor.v3(
input_data=m15.data,
features=m3.data,
date_col='date',
instrument_col='instrument',
drop_na=False,
remove_extra_columns=False
)
[2022-05-12 22:17:30.786048] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-05-12 22:17:30.835341] INFO: moduleinvoker: 命中缓存
[2022-05-12 22:17:30.837274] INFO: moduleinvoker: instruments.v2 运行完成[0.05124s].
[2022-05-12 22:17:30.842317] INFO: moduleinvoker: input_features.v1 开始运行..
[2022-05-12 22:17:30.870000] INFO: moduleinvoker: input_features.v1 运行完成[0.027675s].
[2022-05-12 22:17:30.887158] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2022-05-12 22:17:30.893252] INFO: moduleinvoker: 命中缓存
[2022-05-12 22:17:30.894748] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[0.00761s].
[2022-05-12 22:17:30.906244] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2022-05-12 22:17:35.138923] INFO: derived_feature_extractor: 提取完成 _bool = where(price_limit_status_0==3 , True, False), 0.003s
[2022-05-12 22:17:35.605964] INFO: derived_feature_extractor: /y_2017, 193398
[2022-05-12 22:17:36.745480] INFO: derived_feature_extractor: /y_2018, 816987
[2022-05-12 22:17:37.997116] INFO: derived_feature_extractor: /y_2019, 884867
[2022-05-12 22:17:39.390939] INFO: derived_feature_extractor: /y_2020, 945961
[2022-05-12 22:17:39.591775] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[8.685541s].
df = m16.data.read()
def cal_lianban_num(df):
# "计算个股连板数量"
df['lianban_num'] = df.groupby(df['_bool'].astype(int).diff().ne(0).cumsum())['_bool'].cumsum()
return df
# 按标的进行分区
result = df.groupby('instrument').apply(cal_lianban_num)