vn.py官网
开源量化社区
Member
avatar
加入于:
帖子: 17
声望: 0

RT,代码如下

from vnpy.app.cta_strategy.backtesting import BacktestingEngine, OptimizationSetting
from vnpy.app.cta_strategy.strategies.strategy_bollinger_bias import Bollinger_bias

from datetime import datetime

#%%
engine = BacktestingEngine()
engine.set_parameters(
    vt_symbol="BTC-USDT.BINANCE",
    interval="1m",
    start=datetime(2018, 1, 1),
    end=datetime(2021, 4, 1),
    rate=0.3/10000,
    slippage=0.2,
    size=300,
    pricetick=0.2,
    capital=1_000_000,
)
engine.add_strategy(Bollinger_bias, {})
engine.load_data()

setting = OptimizationSetting()
setting.set_target("sharpe_ratio")
setting.add_parameter("period", 10, 500, 10)
setting.add_parameter("band_width", 1.5, 5.0, 0.5)
setting.add_parameter("bias_pct", 0.02, 0.1, 0.02)

engine.run_optimization(setting)

我是按照github的example来的,这个错在哪儿了呢?
给我报错是这样的,一直循环报错。。。

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\vnstudio\lib\multiprocessing\spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "C:\vnstudio\lib\multiprocessing\spawn.py", line 114, in _main
    prepare(preparation_data)
  File "C:\vnstudio\lib\multiprocessing\spawn.py", line 225, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "C:\vnstudio\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
    run_name="__mp_main__")
  File "C:\vnstudio\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\vnstudio\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\vnstudio\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Administrator\PycharmProjects\vnTrade\optimize.py", line 28, in <module>
    engine.run_optimization(setting)
  File "C:\vnstudio\lib\site-packages\vnpy\app\cta_strategy\backtesting.py", line 607, in run_optimization
    pool = ctx.Pool(multiprocessing.cpu_count()-1)
  File "C:\vnstudio\lib\multiprocessing\context.py", line 119, in Pool
    context=self.get_context())
  File "C:\vnstudio\lib\multiprocessing\pool.py", line 177, in __init__
    self._repopulate_pool()
  File "C:\vnstudio\lib\multiprocessing\pool.py", line 238, in _repopulate_pool
    self._wrap_exception)
  File "C:\vnstudio\lib\multiprocessing\pool.py", line 257, in _repopulate_pool_static
    w.start()
  File "C:\vnstudio\lib\multiprocessing\process.py", line 112, in start
    self._popen = self._Popen(self)
  File "C:\vnstudio\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\vnstudio\lib\multiprocessing\popen_spawn_win32.py", line 33, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\vnstudio\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
    _check_not_importing_main()
  File "C:\vnstudio\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
    is not going to be frozen to produce an executable.''')
RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

Process finished with exit code -1
Administrator
avatar
加入于:
帖子: 4887
声望: 284

搜索下:

if __name__ == "__main__":

这个重要的Python概念

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3

沪公网安备 31011502017034号