BennyThadikaran / stock-pattern

A Python CLI tool to scan, detect, and plot stock chart patterns
GNU General Public License v3.0
156 stars 32 forks source link

Getting Error while Backtesting #63

Closed Suresh-py closed 1 month ago

Suresh-py commented 2 months ago

When trying to run the backtest the below error messages are displayed. Can you please look into it

` Microsoft Windows [Version 10.0.22621.4112] (c) Microsoft Corporation. All rights reserved.

C:\Users\Desktop\stock-pattern-main\src>py backtest.py -p trng --date 2023-12-01 --tf weekly 2%|█▉ | 46/1864 [00:02<01:50, 16.41it/s] concurrent.futures.process._RemoteTraceback: """ Traceback (most recent call last): File "C:\Program Files\Python312\Lib\concurrent\futures\process.py", line 263, in _process_worker r = call_item.fn(*call_item.args, **call_item.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Desktop\stock-pattern-main\src\backtest.py", line 151, in scan start = df.index[pos - period]


  File "C:\Users\AppData\Roaming\Python\Python312\site-packages\pandas\core\indexes\base.py", line 5389, in __getitem__
    return getitem(key)
           ^^^^^^^^^^^^
  File "C:\Users\AppData\Roaming\Python\Python312\site-packages\pandas\core\arrays\datetimelike.py", line 381, in __getitem__
    result = cast("Union[Self, DTScalarOrNaT]", super().__getitem__(key))
                                                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AppData\Roaming\Python\Python312\site-packages\pandas\core\arrays\_mixins.py", line 284, in __getitem__
    result = self._ndarray[key]
             ~~~~~~~~~~~~~^^^^^
IndexError: index -18 is out of bounds for axis 0 with size 14
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Desktop\stock-pattern-main\src\backtest.py", line 321, in <module>
    main(sym_list, output_file, loader, args.date, period)
  File "C:\Users\Desktop\stock-pattern-main\src\backtest.py", line 240, in main
    result = future.result()
             ^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\concurrent\futures\_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
IndexError: index -18 is out of bounds for axis 0 with size 14

`
BennyThadikaran commented 2 months ago

I fixed this one. Just running tests to see if anything else crops up. I will post the update once its done.

Thanks for the good work.

BennyThadikaran commented 2 months ago

I fixed errors in backtest.py. You can update your repo to the latest.

Note for backtest.py -d/--date is mandatory now. This prevents a lots of potential bugs especially on intraday tf. I will update the wiki docs on the weekend.

I've put best efforts to check for errors but if you do find any let me know. I will get them fixed. Thanks again.

Suresh-py commented 1 month ago

Thank you for fixing the errors. I will test and let you know