akumidv / trade-strategies-backtesting-optimization

Python based trade strategies optimization
GNU General Public License v3.0
4 stars 1 forks source link

Numpy or talib error #1

Open mpetrishchev opened 1 year ago

mpetrishchev commented 1 year ago

I've tried to run the file "sma_cross_backtesting_v1.ipynb" in Google Colab, but get an error due the exucution in the Setup section #3 (below). How it can be fixed?


RuntimeError Traceback (most recent call last) init.pxd in numpy.import_array()

RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf . Check the section C-API incompatibility at the Troubleshooting ImportError section at https://numpy.org/devdocs/user/troubleshooting-importerror.html#c-api-incompatibility for indications on how to solve this problem .

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last)

in () 13 from backtesting import Backtest 14 ---> 15 import talib 16 import pandas_ta as ta 17 import numpy as np /usr/local/lib/python3.9/dist-packages/talib/__init__.py in 91 92 ---> 93 from ._ta_lib import ( 94 _ta_initialize, _ta_shutdown, MA_Type, __ta_version__, 95 _ta_set_unstable_period as set_unstable_period, talib/_func.pxi in init talib._ta_lib() __init__.pxd in numpy.import_array() ImportError: numpy.core.multiarray failed to import --------------------------------------------------------------------------- NOTE: If your import is failing due to a missing package, you can manually install dependencies using either !pip or !apt. To view examples of installing some common dependencies, click the "Open Examples" button below.
akumidv commented 1 year ago

Yeah, there are some changes in libraries versions. But mostly problem not in libraries, but that the Binance ban requests from servers that places in US (and Google Collabs servers placed in US), I didn't figure out how to fix this problem. Probably later.

mpetrishchev commented 1 year ago

The problem with the library version can be fixed the follow way. I've added the string (usage of numpy version 1.23 because 1.24 is not compatible):

!pip install --force-reinstall numpy==1.23

to the Setup section and now it works. But the next problem, you are right with the access to the Binance api. I've tried several ways that are described on forums but no luck.

Also I've tried to use data file that was exported from Tradingview. I have some errors in the data conversions. Can you provide the example of the file?

Thanks.

mpetrishchev commented 1 year ago

Uploaded csv from Tradingview with UNIX time. The next problem is in the "Run Strategy" section (see below). Data looks like ok (see below after the error message). Any idea how to fix it?

========== Error message ============

============== Attention . Resulting values shows in "best loss" with negative sign (need it for selected optimization method which uses search for minimum values). 0%| | 0/100 [00:00<?, ?trial/s, best loss=?]ERROR:hyperopt.fmin:job exception: Indicator "SMA(C,9)" errored with exception: input array type is not double 0%| | 0/100 [00:00<?, ?trial/s, best loss=?]

Exception Traceback (most recent call last) /usr/local/lib/python3.9/dist-packages/backtesting/backtesting.py in I(self, func, name, plot, overlay, color, scatter, *args, *kwargs) 126 try: --> 127 value = func(args, **kwargs) 128 except Exception as e:

11 frames talib/_func.pxi in talib._ta_lib.SMA()

talib/_func.pxi in talib._ta_lib.check_array()

Exception: input array type is not double

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last)

in [/usr/local/lib/python3.9/dist-packages/backtesting/backtesting.py](https://localhost:8080/#) in I(self, func, name, plot, overlay, color, scatter, *args, **kwargs) 127 value = func(*args, **kwargs) 128 except Exception as e: --> 129 raise RuntimeError(f'Indicator "{name}" errored with exception: {e}') 130 131 if isinstance(value, pd.DataFrame): RuntimeError: Indicator "SMA(C,9)" errored with exception: input array type is not double #============ Example of the data ============ index Open High Low Close Plot Plot.1 Long \ time 2023-04-20 17:45:00 0 28513 28561 28488 28537 NaN NaN NaN 2023-04-20 17:48:00 1 28533 28533 28496 28502 NaN NaN NaN