microsoft / qlib

Qlib is an AI-oriented quantitative investment platform that aims to realize the potential, empower research, and create value using AI technologies in quantitative investment, from exploring ideas to implementing productions. Qlib supports diverse machine learning modeling paradigms. including supervised learning, market dynamics modeling, and RL.
https://qlib.readthedocs.io/en/latest/
MIT License
15.67k stars 2.66k forks source link

examples\nested_decision_execution\workflow.py not work #1623

Open XYUU opened 1 year ago

XYUU commented 1 year ago

🐛 Bug Description

To Reproduce

Steps to reproduce the behavior:

index 4943 is out of bounds for axis 0 with size 4943
  File "C:\Git\qlib\qlib\backtest\utils.py", line 131, in get_step_time
    return self._calendar[calendar_index], epsilon_change(self._calendar[calendar_index + 1])
  File "C:\Git\qlib\qlib\contrib\strategy\signal_strategy.py", line 141, in generate_trade_decision
    trade_start_time, trade_end_time = self.trade_calendar.get_step_time(trade_step)
  File "C:\Git\qlib\qlib\backtest\backtest.py", line 89, in collect_data_loop
    _trade_decision: BaseTradeDecision = trade_strategy.generate_trade_decision(_execute_result)
  File "C:\Git\qlib\qlib\backtest\backtest.py", line 44, in backtest_loop
    for _decision in collect_data_loop(start_time, end_time, trade_strategy, trade_executor, return_value):
  File "C:\Git\qlib\qlib\backtest\__init__.py", line 275, in backtest
    return backtest_loop(start_time, end_time, trade_strategy, trade_executor)
  File "C:\Git\qlib\qlib\workflow\record_temp.py", line 473, in _generate
    portfolio_metric_dict, indicator_dict = normal_backtest(
  File "C:\Git\qlib\qlib\workflow\record_temp.py", line 234, in generate
    return self._generate(*args, **kwargs)
  File "C:\Git\qlib\examples\nested_decision_execution\workflow.py", line 269, in backtest
    par.generate()
  File "C:\Develop\Python3.8\Lib\site-packages\fire-0.5.0-py3.8.egg\fire\core.py", line 691, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "C:\Develop\Python3.8\Lib\site-packages\fire-0.5.0-py3.8.egg\fire\core.py", line 475, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "C:\Develop\Python3.8\Lib\site-packages\fire-0.5.0-py3.8.egg\fire\core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "C:\Git\qlib\examples\nested_decision_execution\workflow.py", line 394, in <module>
    fire.Fire(NestedDecisionExecutionWorkflow)
  File "C:\Develop\Python3.8\Lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Develop\Python3.8\Lib\runpy.py", line 194, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
IndexError: index 4943 is out of bounds for axis 0 with size 4943

Screenshot

Environment

Note: User could run cd scripts && python collect_info.py all under project directory to get system information and paste them here directly.

Additional Notes

Fivele-Li commented 1 year ago

It appears that the issue is due to your local trading calendar having only a few extra days compared to the default backtest start date in the workflow, which is causing a lack of data availability. You can use this script to update the calendar to the latest version or to the desired date.

https://github.com/microsoft/qlib/blob/4c30e5827b74bcc45f14cf3ae0c1715459ed09ae/scripts/data_collector/future_calendar_collector.py#L111

imagebody commented 3 months ago

It appears that the issue is due to your local trading calendar having only a few extra days compared to the default backtest start date in the workflow, which is causing a lack of data availability. You can use this script to update the calendar to the latest version or to the desired date.

https://github.com/microsoft/qlib/blob/4c30e5827b74bcc45f14cf3ae0c1715459ed09ae/scripts/data_collector/future_calendar_collector.py#L111

I've encountered same issue. which due to reason you mentioned.Thank your very much for your response:)