shepherdpp / qteasy

a python-based fast quantitative investment module
BSD 3-Clause "New" or "Revised" License
73 stars 28 forks source link

运行大量股票选股策略效率降低 #177

Open shepherdpp opened 2 months ago

shepherdpp commented 2 months ago

Describe the bug / 描述bug内容 升级到最近版本qteasy后,运行大规模股票选股策略时(股票池数量300~400支股票)效率急剧降低,在升级前策略回测耗时40秒左右,升级新版本后耗时约24分钟

To Reproduce / 复现问题

  1. Your Input / 您的输入 运行下面代码,运行耗时24分钟左右
    
    shares = qt.filter_stock_codes(index='000300.SH', date='20210101')
    print(len(shares), shares[:10])

alpha = MultiFactors() op = qt.Operator(alpha, signal_type='PT')

op.op_type = 'stepwise' op.set_blender("0.8*s0", 'close') op.run(mode=1, invest_start='20210101', invest_end='20220501', asset_type='E', invest_cash_amounts=[1000000], asset_pool=shares, trade_batch_size=100, sell_batch_size=1, trade_log=True)

2. Actual Output or error message / 您得到的输出或错误信息:

``` text
     ====================================
     |                                  |
     |       BACK TESTING RESULT        |
     |                                  |
     ====================================
qteasy running mode: 1 - History back testing
time consumption for operate signal creation: 5 sec 61.3 ms
time consumption for operation back looping:  24 min 40 sec 822.8 ms
investment starts on      2007-01-04 00:00:00
ends on                   2017-12-28 00:00:00
Total looped periods:     11.0 years.
-------------operation summary:------------

Expected behavior / 期望的输出 A clear and concise description of what you expected to happen. / 简明扼要描述您期望得到怎样的输出 在老板本qteasy环境下运行,总运行时间约为40秒 Environment (please complete the following information) / 请提供更多环境信息: