ricequant / rqalpha

A extendable, replaceable Python algorithmic backtest && trading framework supporting multiple securities
http://rqalpha.io
Other
5.36k stars 1.61k forks source link

'NoneType' object is not callable when "before trading" undefined and force_run_init_when_pt_resume enabled. #375

Closed BurdenBear closed 6 years ago

BurdenBear commented 6 years ago

1. RQAlpha的版本

3.1.2

2. Python的版本

3.6.6

3. 是Windows/Linux/MacOS or others?

window10

4. 出现问题对应的源码/或者能复现问题的简易代码 以及对应的配置

{'base': {'accounts': {'STOCK': 10000000.0},
          'benchmark': None,
          'data_bundle_path': 'C:\\Users\\Morri/.rqalpha\\bundle',
          'end_date': datetime.date(2050, 1, 1),
          'frequency': '1m',
          'init_positions': [],
          'margin_multiplier': 1,
          'persist': True,
          'persist_mode': PERSIST_MODE.REAL_TIME,
          'resume_mode': True,
          'round_price': False,
          'run_type': RUN_TYPE.PAPER_TRADING,
          'source_code': None,
          'start_date': datetime.date(2018, 9, 17),
          'strategy_file': 'strategy.py'},
 'extra': {'context_vars': None,
           'enable_profiler': False,
           'force_run_init_when_pt_resume': True,
           'is_hold': False,
           'locale': 'cn',
           'log_level': 'verbose',
           'logger': (),
           'user_log_disabled': False,
           'user_system_log_disabled': False},
 'mod': {'fxdayu_source': {'enabled': True,
                           'mongo_url': 'mongodb://192.168.0.101:27017,192.168.0.102:27017',
                           'persist_path': './persist',
                           'quantos_token': '',
                           'quantos_user': '',
                           'redis_url': 'redis://192.168.0.102:6379',
                           'source': 'quantos'},
         'shipane_wrapper': {'enabled': False},
         'sys_accounts': {'cash_return_by_stock_delisted': True,
                          'dividend_reinvestment': False,
                          'enabled': True},
         'sys_analyser': {'enabled': True},
         'sys_booking': {'enabled': False},
         'sys_funcat': {'enabled': False},
         'sys_incremental': {'enabled': False},
         'sys_progress': {'enabled': True, 'show': False},
         'sys_risk': {'enabled': True, 'validate_stock_position': True},
         'sys_simulation': {'enabled': True, 'signal': True},
         'sys_stock_realtime': {'enabled': False},
         'trading_monitor': {'enabled': False}},
 'validator': {'cash_return_by_stock_delisted': False, 'close_amount': True},
 'version': '0.1.6',
 'whitelist': ['base', 'extra', 'validator', 'mod']}

mainly:

base:
    ...
    run_type: p
    resume_mode: true
    ...
extra:
    ...
    force_run_init_when_pt_resume: true
    ...

and there is no before_trading defined in strategy, which, AFAK, is unneccessary.

5. 出现的错误堆栈日志信息

[2018-09-17 11:23:30.446124] DEBUG: basic_system_log:
{'base': {'accounts': {'STOCK': 10000000.0},
          'benchmark': None,
          'data_bundle_path': 'C:\\Users\\Morri/.rqalpha\\bundle',
          'end_date': datetime.date(2050, 1, 1),
          'frequency': '1m',
          'init_positions': [],
          'margin_multiplier': 1,
          'persist': True,
          'persist_mode': PERSIST_MODE.REAL_TIME,
          'resume_mode': True,
          'round_price': False,
          'run_type': RUN_TYPE.PAPER_TRADING,
          'source_code': None,
          'start_date': datetime.date(2018, 9, 17),
          'strategy_file': 'strategy.py'},
 'extra': {'context_vars': None,
           'enable_profiler': False,
           'force_run_init_when_pt_resume': True,
           'is_hold': False,
           'locale': 'cn',
           'log_level': 'verbose',
           'logger': (),
           'user_log_disabled': False,
           'user_system_log_disabled': False},
 'mod': {'fxdayu_source': {'enabled': True,
                           'mongo_url': 'mongodb://192.168.0.101:27017,192.168.0.102:27017',
                           'persist_path': './persist',
                           'quantos_token': '',
                           'quantos_user': '',
                           'redis_url': 'redis://192.168.0.102:6379',
                           'source': 'quantos'},
         'shipane_wrapper': {'enabled': False},
         'sys_accounts': {'cash_return_by_stock_delisted': True,
                          'dividend_reinvestment': False,
                          'enabled': True},
         'sys_analyser': {'enabled': True},
         'sys_booking': {'enabled': False},
         'sys_funcat': {'enabled': False},
         'sys_incremental': {'enabled': False},
         'sys_progress': {'enabled': True, 'show': False},
         'sys_risk': {'enabled': True, 'validate_stock_position': True},
         'sys_simulation': {'enabled': True, 'signal': True},
         'sys_stock_realtime': {'enabled': False},
         'trading_monitor': {'enabled': False}},
 'validator': {'cash_return_by_stock_delisted': False, 'close_amount': True},
 'version': '0.1.6',
 'whitelist': ['base', 'extra', 'validator', 'mod']}
[2018-09-17 11:23:30.449127] DEBUG: system_log: 载入 Mod rqalpha.mod.rqalpha_mod_sys_accounts
[2018-09-17 11:23:30.457114] DEBUG: system_log: 载入 Mod rqalpha.mod.rqalpha_mod_sys_simulation
[2018-09-17 11:23:30.466113] DEBUG: system_log: 载入 Mod rqalpha.mod.rqalpha_mod_sys_progress
[2018-09-17 11:23:30.468119] DEBUG: system_log: 载入 Mod rqalpha.mod.rqalpha_mod_sys_risk
[2018-09-17 11:23:30.474114] DEBUG: system_log: 载入 Mod rqalpha.mod.rqalpha_mod_sys_analyser
[2018-09-17 11:23:30.477116] DEBUG: system_log: 载入 Mod rqalpha_mod_fxdayu_source
[2018-09-17 11:23:30.505113] DEBUG: basic_system_log: mod start_up [START] sys_accounts
[2018-09-17 11:23:30.506114] DEBUG: basic_system_log: mod start_up [END]   sys_accounts
[2018-09-17 11:23:30.507112] DEBUG: basic_system_log: mod start_up [START] sys_simulation
[2018-09-17 11:23:30.508111] DEBUG: basic_system_log: mod start_up [END]   sys_simulation
[2018-09-17 11:23:30.509112] DEBUG: basic_system_log: mod start_up [START] sys_progress
[2018-09-17 11:23:30.510114] DEBUG: basic_system_log: mod start_up [END]   sys_progress
[2018-09-17 11:23:30.511119] DEBUG: basic_system_log: mod start_up [START] sys_risk
[2018-09-17 11:23:30.512112] DEBUG: basic_system_log: mod start_up [END]   sys_risk
[2018-09-17 11:23:30.512112] DEBUG: basic_system_log: mod start_up [START] sys_analyser
[2018-09-17 11:23:30.513122] DEBUG: basic_system_log: mod start_up [END]   sys_analyser
[2018-09-17 11:23:30.514116] DEBUG: basic_system_log: mod start_up [START] fxdayu_source
2018-09-17 11:23:33.947127 WARN [Warning] When you use this version of RealtimeTradeMod, history_bars can only get data from yesterday.
[2018-09-17 11:23:33.948112] DEBUG: basic_system_log: mod start_up [END]   fxdayu_source
[2018-09-17 11:23:33.970148] DEBUG: system_log: restore core with state = b'{"scheduler": {"py/b64": "eyJ0b2RheSI6ICIyMDE4LTA5LTE3IiwgImxhc3RfbWludXRlIjogNjgwfQ==\\n"}}'
[2018-09-17 11:23:33.971148] DEBUG: system_log: restore user_context with state = b'\x80\x03}q\x00(X\x02\x00\x00\x00s1q\x01C\x15\x80\x03X\x0b\x00\x00\x00000001.XSHEq\x00.q\x02X\x06\x00\x00\x00PERIODq\x03C\x05\x80\x03KP.q\x04X\x11\x00\x00\x00stoplossmultiplerq\x05C\x0c\x80\x03G?\xef\n=p\xa3\xd7\n.q\x06X\x12\x00\x00\x00takepofitmultiplerq\x07C\x05\x80\x03K\x04.q\x08u.'
[2018-09-17 11:23:33.972160] DEBUG: system_log: restore context.s1 <class 'str'>
[2018-09-17 11:23:33.973159] DEBUG: system_log: restore context.PERIOD <class 'int'>
[2018-09-17 11:23:33.974143] DEBUG: system_log: restore context.stoplossmultipler <class 'float'>
[2018-09-17 11:23:33.974143] DEBUG: system_log: restore context.takepofitmultipler <class 'int'>
[2018-09-17 11:23:33.975148] DEBUG: system_log: restore global_vars with state = b'\x80\x03}q\x00.'
[2018-09-17 11:23:33.976132] DEBUG: system_log: restore universe with state = b'[]'
[2018-09-17 11:23:33.976132] DEBUG: system_log: restore event_source with state = b'{"before_trading_fire_date": {"__date__": true, "as_str": "20180917"}, "after_trading_fire_date": {"__date__": true, "as_str": "20000101"}, "settlement_fire_date": {"__date__": true, "as_str": "20000101"}}'
[2018-09-17 11:23:33.979116] DEBUG: system_log: restore portfolio with state = b'{"accounts": {"STOCK": {"backward_trade_set": [], "dividend_receivable": {}, "frozen_cash": 0, "positions": {}, "total_cash": 10000000.0, "transaction_cost": 0}}, "last_unit_net_value": 1, "start_date": {"py/object": "datetime.date", "__reduce__": [{"py/type": "datetime.date"}, ["B+IJEQ=="]]}, "static_unit_net_value": 1.0, "units": 10000000.0}'
[2018-09-17 11:23:33.982135] DEBUG: system_log: restore executor with state = b'{"last_before_trading": {"__date__": true, "as_str": "20180917"}}'
[2018-09-17 11:23:33.984116] DEBUG: system_log: real_dt 2018-09-17 11:23:33.984116, dt 2018-09-17 11:23:33.984116, event EVENT.BEFORE_TRADING
[2018-09-17 11:23:33.985133] DEBUG: system_log: real_dt 2018-09-17 11:23:33.985133, dt 2018-09-17 11:23:33.984116, event EVENT.BAR
Traceback (most recent call last):
  File "d:\anaconda3\envs\rqalpha\lib\site-packages\rqalpha\core\strategy.py", line 80, in before_trading
    self._before_trading(self._user_context)
TypeError: 'NoneType' object is not callable
2018-09-17 11:23:33.985133 ERROR 'NoneType' object is not callable
[2018-09-17 11:23:33.989114] DEBUG: basic_system_log: mod tear_down [START] fxdayu_source
[2018-09-17 11:23:33.991173] DEBUG: basic_system_log: mod tear_down [END]   fxdayu_source
[2018-09-17 11:23:33.998151] DEBUG: basic_system_log: mod tear_down [START] sys_analyser
[2018-09-17 11:23:33.999128] DEBUG: basic_system_log: mod tear_down [END]   sys_analyser
[2018-09-17 11:23:34.000114] DEBUG: basic_system_log: mod tear_down [START] sys_risk
[2018-09-17 11:23:34.001138] DEBUG: basic_system_log: mod tear_down [END]   sys_risk
[2018-09-17 11:23:34.002114] DEBUG: basic_system_log: mod tear_down [START] sys_progress
[2018-09-17 11:23:34.003115] DEBUG: basic_system_log: mod tear_down [END]   sys_progress
[2018-09-17 11:23:34.003115] DEBUG: basic_system_log: mod tear_down [START] sys_simulation
[2018-09-17 11:23:34.004115] DEBUG: basic_system_log: mod tear_down [END]   sys_simulation
[2018-09-17 11:23:34.004115] DEBUG: basic_system_log: mod tear_down [START] sys_accounts
[2018-09-17 11:23:34.005131] DEBUG: basic_system_log: mod tear_down [END]   sys_accounts
Cuizi7 commented 6 years ago

fixed in master branch

BurdenBear commented 6 years ago

Thanks, close it.