kernc / backtesting.py

:mag_right: :chart_with_upwards_trend: :snake: :moneybag: Backtest trading strategies in Python.
https://kernc.github.io/backtesting.py/
GNU Affero General Public License v3.0
5.18k stars 1.02k forks source link

ValueError: assignment destination is read-only #14

Closed alexlusak closed 5 years ago

alexlusak commented 5 years ago

I was simply trying to run the demo, but I am getting the following error:

Traceback (most recent call last):
  File "backtest.py", line 49, in <module>
    output = bt.run()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtesting/backtesting.py", line 675, in run
    strategy.init()
  File "backtest.py", line 29, in init
    self.sma1 = self.I(SMA, self.data.Close, self.n1)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtesting/backtesting.py", line 124, in I
    value = func(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtesting/test/__init__.py", line 23, in SMA
    return pd.Series(arr).rolling(n).mean()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/window.py", line 1875, in mean
    return super().mean(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/window.py", line 1178, in mean
    return self._apply("roll_mean", "mean", **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/window.py", line 910, in _apply
    values = self._prep_values(b.values)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/window.py", line 239, in _prep_values
    values[np.isinf(values)] = np.NaN
ValueError: assignment destination is read-only

I have downloaded the latest version of numpy (1.17.0) in addition to pandas (0.25.0), so I'm suspecting there may be something different in one of the newer version of these libraries. Any insight to why this may be throwing this error would be appreciated.

kernc commented 5 years ago

The issue is with pandas 0.25.0. The temporary workaround is to:

pip install pandas==0.24.2
kernc commented 5 years ago

The issue is fixed in pandas master and in the upcoming pandas 0.25.1 release.

alexlusak commented 5 years ago

Amazing, thanks for staying on top of this.