stefan-jansen / machine-learning-for-trading

Code for Machine Learning for Algorithmic Trading, 2nd edition.
https://ml4trading.io
13.16k stars 4.17k forks source link

Chapter 4: cannot set WRITEABLE flag to True of this array #100

Closed JeremyWhittaker closed 3 years ago

JeremyWhittaker commented 3 years ago

Get this error on this code block. Any suggestions?

with pd.HDFStore(DATA_STORE) as store: prices = (store['quandl/wiki/prices'] .loc[idx[str(START):str(END), :], 'adj_close'] .unstack('ticker')) stocks = store['us_equities/stocks'].loc[:, ['marketcap', 'ipoyear', 'sector']]

`--------------------------------------------------------------------------- ValueError Traceback (most recent call last)

in 3 .loc[idx[str(START):str(END), :], 'adj_close'] 4 .unstack('ticker')) ----> 5 stocks = store['us_equities/stocks'].loc[:, ['marketcap', 'ipoyear', 'sector']] /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pandas/io/pytables.py in __getitem__(self, key) 551 552 def __getitem__(self, key: str): --> 553 return self.get(key) 554 555 def __setitem__(self, key: str, value): /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pandas/io/pytables.py in get(self, key) 745 if group is None: 746 raise KeyError(f"No object named {key} in the file") --> 747 return self._read_group(group) 748 749 def select( /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pandas/io/pytables.py in _read_group(self, group) 1716 s = self._create_storer(group) 1717 s.infer_axes() -> 1718 return s.read() 1719 1720 /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pandas/io/pytables.py in read(self, where, columns, start, stop) 3068 3069 blk_items = self.read_index(f"block{i}_items") -> 3070 values = self.read_array(f"block{i}_values", start=_start, stop=_stop) 3071 3072 columns = items[items.get_indexer(blk_items)] /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pandas/io/pytables.py in read_array(self, key, start, stop) 2723 2724 if isinstance(node, tables.VLArray): -> 2725 ret = node[0][start:stop] 2726 else: 2727 dtype = getattr(attrs, "value_type", None) /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/tables/vlarray.py in __getitem__(self, key) 679 key += self.nrows 680 (start, stop, step) = self._process_range(key, key + 1, 1) --> 681 return self.read(start, stop, step)[0] 682 elif isinstance(key, slice): 683 start, stop, step = self._process_range( /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/tables/vlarray.py in read(self, start, stop, step) 819 listarr = [] 820 else: --> 821 listarr = self._read_array(start, stop, step) 822 823 atom = self.atom tables/hdf5extension.pyx in tables.hdf5extension.VLArray._read_array() ValueError: cannot set WRITEABLE flag to True of this array`
stefan-jansen commented 3 years ago

Which notebook? This is usually due to a bug in a specific NumPy version as discussed here. I have not encountered this issue while testing but as I mentioned in your other issue I need to update the Docker image, which I'll do as soon as things normalize here in Austin, TX.

Meanwhile, could you please run

conda update -n ml4t-dl --all -y

to get the latest versions of the software? Please let me know if the issue persists.

JeremyWhittaker commented 3 years ago

I thought it was chapter 4 but I can't find it now. I ran the command you suggested.

`(ml4t-dl) packt@26b3fd22ef00:~/ml4t$ conda update -n ml4t-dl --all -y

(ml4t-dl) packt@26b3fd22ef00:~/ml4t$ conda activate ml4t-dl

(ml4t-dl) packt@26b3fd22ef00:~/ml4t$ lab`

I'm getting errors in almost all the lessons. Is it ok to install these missing modules? I wasn't sure if that would mess up the dependencies for the other code. But I thought the Docker image would be turn-key and already have all of these? Perhaps it is corrupt and I should try re-downloading it?

Lesson 1: `%matplotlib inline !pip3 install pyfinance

from datetime import datetime import matplotlib.pyplot as plt import seaborn as sns import pandas as pd import pandas_datareader.data as web from pyfinance.ols import PandasRollingOLS`

`--------------------------------------------------------------------------- ImportError Traceback (most recent call last) /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pyfinance/utils.py in 77 try: ---> 78 from pandas.tseries.frequencies import FreqGroup, get_freq_code 79 except ImportError: # 0.24+, or somewhere around then

ImportError: cannot import name 'FreqGroup' from 'pandas.tseries.frequencies' (/opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pandas/tseries/frequencies.py)

During handling of the above exception, another exception occurred:

ModuleNotFoundError Traceback (most recent call last)

in 7 import pandas as pd 8 import pandas_datareader.data as web ----> 9 from pyfinance.ols import PandasRollingOLS /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pyfinance/__init__.py in 30 31 # Echoing Pandas, bring these to top-level namespace. ---> 32 from .returns import TFrame, TSeries # noqa /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pyfinance/returns.py in 40 import pandas as pd 41 ---> 42 from pyfinance import ols, utils 43 44 SECS_PER_CAL_YEAR = 365.25 * 24 * 60 * 60 /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pyfinance/ols.py in 13 from statsmodels.tools import add_constant 14 ---> 15 from pyfinance import utils 16 17 /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pyfinance/utils.py in 78 from pandas.tseries.frequencies import FreqGroup, get_freq_code 79 except ImportError: # 0.24+, or somewhere around then ---> 80 from pandas._libs.tslibs.frequencies import FreqGroup, get_freq_code 81 82 ModuleNotFoundError: No module named 'pandas._libs.tslibs.frequencies'` **Lessson 3:** `%matplotlib inline from datetime import datetime import itertools import pandas as pd import pandas_datareader.data as web from pykalman import KalmanFilter import pywt import matplotlib.pyplot as plt import seaborn as sns` `--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) in 6 import pandas as pd 7 import pandas_datareader.data as web ----> 8 from pykalman import KalmanFilter 9 import pywt 10 ModuleNotFoundError: No module named 'pykalman'` **Lesson 4:** `%load_ext zipline` `--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) in ----> 1 get_ipython().run_line_magic('load_ext', 'zipline') /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth) 2334 kwargs['local_ns'] = self.get_local_scope(stack_depth) 2335 with self.builtin_trap: -> 2336 result = fn(*args, **kwargs) 2337 return result 2338 in load_ext(self, module_str) /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/IPython/core/magic.py in (f, *a, **k) 185 # but it's overkill for just that one bit of state. 186 def magic_deco(arg): --> 187 call = lambda f, *a, **k: f(*a, **k) 188 189 if callable(arg): /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/IPython/core/magics/extension.py in load_ext(self, module_str) 31 if not module_str: 32 raise UsageError('Missing module name.') ---> 33 res = self.shell.extension_manager.load_extension(module_str) 34 35 if res == 'already loaded': /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/IPython/core/extensions.py in load_extension(self, module_str) 78 if module_str not in sys.modules: 79 with prepended_to_syspath(self.ipython_extension_dir): ---> 80 mod = import_module(module_str) 81 if mod.__file__.startswith(self.ipython_extension_dir): 82 print(("Loading extensions from {dir} is deprecated. " /opt/conda/envs/ml4t-dl/lib/python3.7/importlib/__init__.py in import_module(name, package) 125 break 126 level += 1 --> 127 return _bootstrap._gcd_import(name[level:], package, level) 128 129 /opt/conda/envs/ml4t-dl/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level) /opt/conda/envs/ml4t-dl/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_) /opt/conda/envs/ml4t-dl/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_) ModuleNotFoundError: No module named 'zipline'` **Lesson 5:** `from quantopian.research import run_pipeline from quantopian.pipeline import Pipeline from quantopian.pipeline.data.builtin import USEquityPricing from quantopian.pipeline.data.morningstar import income_statement, operation_ratios, balance_sheet from quantopian.pipeline.data.psychsignal import stocktwits from quantopian.pipeline.factors import CustomFactor, SimpleMovingAverage, Returns from quantopian.pipeline.filters import QTradableStocksUS import numpy as np import pandas as pd from time import time` `--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) in ----> 1 from quantopian.research import run_pipeline 2 from quantopian.pipeline import Pipeline 3 from quantopian.pipeline.data.builtin import USEquityPricing 4 from quantopian.pipeline.data.morningstar import income_statement, operation_ratios, balance_sheet 5 from quantopian.pipeline.data.psychsignal import stocktwits ModuleNotFoundError: No module named 'quantopian'` **Lesson 6:** `--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) in ----> 1 from quantopian.research import run_pipeline 2 from quantopian.pipeline import Pipeline 3 from quantopian.pipeline.data.builtin import USEquityPricing 4 from quantopian.pipeline.data.morningstar import income_statement, operation_ratios, balance_sheet 5 from quantopian.pipeline.data.psychsignal import stocktwits ModuleNotFoundError: No module named 'quantopian'` `--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) in ----> 1 performance = pd.read_pickle('single_factor.pickle') /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pandas/io/pickle.py in read_pickle(filepath_or_buffer, compression, storage_options) 188 compression=compression, 189 is_text=False, --> 190 storage_options=storage_options, 191 ) as handles: 192 /opt/conda/envs/ml4t-dl/lib/python3.7/site-packages/pandas/io/common.py in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options) 649 else: 650 # Binary mode --> 651 handle = open(handle, ioargs.mode) 652 handles.append(handle) 653 FileNotFoundError: [Errno 2] No such file or directory: 'single_factor.pickle'` **Lesson 7:** `import pandas as pd import numpy as np from time import time import talib import re from statsmodels.api import OLS from sklearn.metrics import mean_squared_error from scipy.stats import spearmanr from sklearn.linear_model import LinearRegression, Ridge, RidgeCV, Lasso, LassoCV, LogisticRegression from sklearn.preprocessing import StandardScaler from quantopian.research import run_pipeline from quantopian.pipeline import Pipeline, factors, filters, classifiers from quantopian.pipeline.data.builtin import USEquityPricing from quantopian.pipeline.factors import (Latest, Returns, AverageDollarVolume, SimpleMovingAverage, EWMA, BollingerBands, CustomFactor, MarketCap, SimpleBeta) from quantopian.pipeline.filters import QTradableStocksUS, StaticAssets from quantopian.pipeline.data.quandl import fred_usdontd156n as libor from empyrical import max_drawdown, sortino_ratio import seaborn as sns import matplotlib.pyplot as plt` `--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) in 10 from sklearn.preprocessing import StandardScaler 11 ---> 12 from quantopian.research import run_pipeline 13 from quantopian.pipeline import Pipeline, factors, filters, classifiers 14 from quantopian.pipeline.data.builtin import USEquityPricing ModuleNotFoundError: No module named 'quantopian'`
stefan-jansen commented 3 years ago

Sorry, my answer wasn't very clear. The ml4t-dl image is only for the deep learning chapters 16+. I had just noticed the day before that this image has TensorFlow 2.1 when it should have 2.2 and this was causing an error for someone in ch 18, updating solved that.

The problematic NumPy version is 1.16.0, and only the environment ml4t-zipline has this version; ml4t and ml4t-dl have 1.18.5. Have you perhaps been running notebooks other than the ones that actually use Zipline for backtesting with this image?

stefan-jansen commented 3 years ago

The errors above related to quantopian (last and second before last) occur because these were notebooks intended to run on Quantopian's research platform, not on you machine. Unfortunately, Quantopian shut down last November, so this is no longer an option.

The error regarding the missing file occurs because this file is created by notebook 4, which in turn needs to be run using ml4t-zipine.

Notebook 3 uses pykalman which is part of ml4t, not ml4t-dl because the deep leanrning examples do not use it.

Finally, the error in notebook 1 occurs because pyfinance (which stopped being maintained recently) requires pandas <1.1, so this indeed breaks after updating (I'll change this notebook to use the new RollingOLS from statsmodels instead soon, which is compatible with the latest pandas versions).

In most cases, updating libraries won't create problems. I have been updating the environments to the latest versions and am testing the notebook so I hope to be able to make this available soon.

JeremyWhittaker commented 3 years ago

I was confusing your installation sections "parts" and "chapters" So you are correct. I was using the wrong Conda environment.

image

I completely recreated the Docker image. I ran conda activate ml4t

Then re-ran all the lessons in Chapter 4 here are the errors I'm getting:

01 worked, 02 worked, 03 worked

04_single_factor_zipline: %load_ext zipline ModuleNotFoundError: No module named 'zipline'

I thought I had the fix to this by running

conda activate ml4t-zipline
zipline ingest
lab

However, I tried to run it again and got ImportError: No module named 'seaborn' Is it ok to just start installing missing modules as necessary when they are not installed? Or am I doing something wrong here?

05_multiple_factors_quantopian_research

Same question here - Is it ok to just start installing missing modules as necessary when they are not installed? Or am I doing something wrong here?

from quantopian.research import run_pipeline
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.data.morningstar import income_statement, operation_ratios, balance_sheet
from quantopian.pipeline.data.psychsignal import stocktwits
from quantopian.pipeline.factors import CustomFactor, SimpleMovingAverage, Returns
from quantopian.pipeline.filters import QTradableStocksUS

import numpy as np
import pandas as pd
from time import time

ModuleNotFoundError: No module named 'quantopian'

06_performance_eval_alphalens performance = pd.read_pickle('single_factor.pickle') FileNotFoundError: [Errno 2] No such file or directory: 'single_factor.pickle'

07_factor_library_quantopian

import pandas as pd
import numpy as np
from time import time
import talib
import re
from statsmodels.api import OLS
from sklearn.metrics import mean_squared_error
from scipy.stats import spearmanr
from sklearn.linear_model import LinearRegression, Ridge, RidgeCV, Lasso, LassoCV, LogisticRegression
from sklearn.preprocessing import StandardScaler

from quantopian.research import run_pipeline
from quantopian.pipeline import Pipeline, factors, filters, classifiers
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import (Latest, 
                                         Returns, 
                                         AverageDollarVolume, 
                                         SimpleMovingAverage,
                                         EWMA,
                                         BollingerBands,
                                         CustomFactor,
                                         MarketCap,
                                        SimpleBeta)
from quantopian.pipeline.filters import QTradableStocksUS, StaticAssets
from quantopian.pipeline.data.quandl import fred_usdontd156n as libor
from empyrical import max_drawdown, sortino_ratio

import seaborn as sns
import matplotlib.pyplot as plt

ModuleNotFoundError: No module named 'quantopian'

stefan-jansen commented 3 years ago

Thank you. The container ml4t-zipline is indeed missing seaborn, sorry about that. Actually, this notebook (single_factor_zipline) doesn' use seaborn other than for the style setting. I'll update this in the coming days alongside other updates, but you can just install it using !conda install -n ml4t-zipline seaborn. You should be able to run the notebook without other problems; it will create the file single_factor.pickle, the absence of which is currently preventing you from running notebook 6.

As mentioned above and highlighted in the first cell of notebooks 5 and 7. Nothing we can do here, unfortunately, the platform and the data it provided are simply gone.

Hope this helps, please feel free to reopen if you run into additional issues on these matters.

JeremyWhittaker commented 3 years ago

I was able to get lesson 4 to run using conda install -n ml4t-zipline seaborn I did have to run in shell because it wanted a confirmation y to proceed. Now that is running, I'm getting an error ValueError: Failed to find any assets with country_code 'US' that traded between 2015-01-02 00:00:00+00:00 and 2015-01-09 00:00:00+00:00. This probably means that your asset db is old or that it has incorrect country/exchange metadata. I went into db browser and modified the ?? to us applied and wrote database.

(ml4t-zipline) packt@a20fd7fbed78:~/ml4t$ zipline ingest
[2021-02-23 16:49:42.085057] INFO: zipline.data.bundles.quandl: Downloading WIKI metadata.
Downloading WIKI Prices table from Quandl  [####################################]  100%
[2021-02-23 16:51:15.760390] INFO: zipline.data.bundles.quandl: Parsing raw data.
[2021-02-23 16:51:44.586030] INFO: zipline.data.bundles.quandl: Generating asset metadata.
Merging daily equity files:  [--------#---------------------------]  1731/opt/conda/envs/ml4t-zipline/lib/python3.5/site-packages/zipline/data/bcolz_daily_bars.py:367: UserWarning: Ignoring 1 values because they are out of bounds for uint32:             open  high   low  close        volume  ex_dividend  split_ratio
2011-04-11  1.79  1.84  1.55    1.7  6.674913e+09          0.0          1.0
  winsorise_uint32(raw_data, invalid_data_behavior, 'volume', *OHLC)
Merging daily equity files:  [####################################]
[2021-02-23 16:53:59.838743] INFO: zipline.data.bundles.quandl: Parsing split data.
[2021-02-23 16:53:59.989280] INFO: zipline.data.bundles.quandl: Parsing dividend data.
/opt/conda/envs/ml4t-zipline/lib/python3.5/site-packages/zipline/data/adjustments.py:403: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.  if not np.issubdtype(actual, expected):
[2021-02-23 16:54:00.659701] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=67, ex_date=2017-11-09, amount=0.620
[2021-02-23 16:54:00.659883] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=93, ex_date=2017-11-09, amount=0.240
[2021-02-23 16:54:00.659975] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=161, ex_date=2017-11-09, amount=0.110
[2021-02-23 16:54:00.660066] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=283, ex_date=2017-11-09, amount=0.415
[2021-02-23 16:54:00.660176] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=298, ex_date=2017-11-09, amount=1.420
[2021-02-23 16:54:00.660265] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=318, ex_date=2017-11-09, amount=0.330
[2021-02-23 16:54:00.660353] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=434, ex_date=2017-11-09, amount=0.110
[2021-02-23 16:54:00.660442] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=516, ex_date=1996-05-30, amount=0.310
[2021-02-23 16:54:00.660532] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=524, ex_date=2017-11-09, amount=0.050
[2021-02-23 16:54:00.660621] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=556, ex_date=2017-11-09, amount=0.075
[2021-02-23 16:54:00.660720] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=578, ex_date=2017-11-09, amount=0.160
[2021-02-23 16:54:00.660849] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=605, ex_date=2017-11-09, amount=0.040
[2021-02-23 16:54:00.660945] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=666, ex_date=1990-03-26, amount=0.140
[2021-02-23 16:54:00.661039] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=694, ex_date=1990-03-27, amount=0.100
[2021-02-23 16:54:00.661134] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=723, ex_date=2017-11-09, amount=1.620
[2021-02-23 16:54:00.661228] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=758, ex_date=2017-11-09, amount=0.500
[2021-02-23 16:54:00.661321] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=788, ex_date=2017-11-09, amount=0.060
[2021-02-23 16:54:00.661415] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=859, ex_date=1995-05-09, amount=0.100
[2021-02-23 16:54:00.661508] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=904, ex_date=2017-11-09, amount=0.135
[2021-02-23 16:54:00.661600] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=975, ex_date=2017-11-09, amount=0.030
[2021-02-23 16:54:00.661693] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1057, ex_date=2017-11-09, amount=0.250
[2021-02-23 16:54:00.661787] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1088, ex_date=1990-03-26, amount=0.240
[2021-02-23 16:54:00.661919] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1091, ex_date=2017-11-09, amount=0.075
[2021-02-23 16:54:00.662027] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1111, ex_date=1993-03-04, amount=0.070
[2021-02-23 16:54:00.662159] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1172, ex_date=2017-11-09, amount=0.130
[2021-02-23 16:54:00.662252] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1209, ex_date=2017-11-09, amount=0.010
[2021-02-23 16:54:00.662346] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1322, ex_date=1995-05-25, amount=0.150
[2021-02-23 16:54:00.662481] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1441, ex_date=2017-11-09, amount=1.500
[2021-02-23 16:54:00.662578] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1525, ex_date=2017-11-09, amount=0.090
[2021-02-23 16:54:00.662671] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1600, ex_date=2015-07-06, amount=16.500
[2021-02-23 16:54:00.662765] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1642, ex_date=2017-11-09, amount=0.270
[2021-02-23 16:54:00.662897] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1748, ex_date=2017-11-09, amount=0.740
[2021-02-23 16:54:00.662991] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1876, ex_date=2017-11-09, amount=0.120
[2021-02-23 16:54:00.663084] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1922, ex_date=2017-11-09, amount=0.040
[2021-02-23 16:54:00.663178] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=1947, ex_date=1990-03-26, amount=0.150
[2021-02-23 16:54:00.663269] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2098, ex_date=2017-11-09, amount=0.200
[2021-02-23 16:54:00.663361] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2118, ex_date=2014-11-06, amount=0.050
[2021-02-23 16:54:00.663454] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2120, ex_date=2017-11-09, amount=0.110
[2021-02-23 16:54:00.663545] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2149, ex_date=2017-11-09, amount=0.330
[2021-02-23 16:54:00.663638] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2204, ex_date=2017-11-09, amount=0.320
[2021-02-23 16:54:00.663738] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2220, ex_date=2017-11-09, amount=0.660
[2021-02-23 16:54:00.663849] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2281, ex_date=2017-11-09, amount=0.450
[2021-02-23 16:54:00.663942] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2389, ex_date=2017-11-09, amount=0.140
[2021-02-23 16:54:00.664037] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2441, ex_date=2017-11-09, amount=0.215
[2021-02-23 16:54:00.664131] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2517, ex_date=2017-11-09, amount=0.080
[2021-02-23 16:54:00.664224] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2582, ex_date=2017-11-09, amount=0.780
[2021-02-23 16:54:00.664318] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2622, ex_date=2017-11-09, amount=0.390
[2021-02-23 16:54:00.664411] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2662, ex_date=2015-01-14, amount=0.750
[2021-02-23 16:54:00.664504] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2754, ex_date=2000-12-27, amount=0.250
[2021-02-23 16:54:00.664597] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2754, ex_date=2009-09-11, amount=0.420
[2021-02-23 16:54:00.664690] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2754, ex_date=2009-12-11, amount=0.420
[2021-02-23 16:54:00.664784] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2754, ex_date=2010-03-11, amount=0.420
[2021-02-23 16:54:00.664915] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2754, ex_date=2010-12-15, amount=0.180
[2021-02-23 16:54:00.665010] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2766, ex_date=2017-11-09, amount=0.320
[2021-02-23 16:54:00.665125] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2798, ex_date=2017-11-09, amount=0.065
[2021-02-23 16:54:00.665219] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2817, ex_date=1992-03-03, amount=0.300
[2021-02-23 16:54:00.665313] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2824, ex_date=2017-11-09, amount=0.120
[2021-02-23 16:54:00.665407] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2843, ex_date=2017-11-09, amount=0.150
[2021-02-23 16:54:00.665501] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2857, ex_date=2011-09-07, amount=0.410
[2021-02-23 16:54:00.665596] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=2968, ex_date=1990-03-26, amount=0.100
[2021-02-23 16:54:00.665688] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=3005, ex_date=1990-03-26, amount=0.070
[2021-02-23 16:54:00.665782] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=3078, ex_date=2014-05-12, amount=0.060
[2021-02-23 16:54:00.665905] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=3117, ex_date=2017-11-09, amount=0.430
[2021-02-23 16:54:00.665998] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=3138, ex_date=2010-08-16, amount=0.060
[2021-02-23 16:54:00.666092] WARNING: zipline.data.adjustments: Couldn't compute ratio for dividend sid=3145, ex_date=2017-11-09, amount=0.050
/opt/conda/envs/ml4t-zipline/lib/python3.5/site-packages/zipline/data/adjustments.py:515: RuntimeWarning: invalid value encountered in greater
  positive_ratio_mask = ratio > 0
[2021-02-23 16:54:00.666329] WARNING: zipline.data.adjustments: Dividend ratio <= 0 for dividend sid=501, ex_date=2006-01-03, amount=41.560
[2021-02-23 16:54:00.666423] WARNING: zipline.data.adjustments: Dividend ratio <= 0 for dividend sid=1557, ex_date=2007-07-02, amount=88.530
[2021-02-23 16:54:00.666516] WARNING: zipline.data.adjustments: Dividend ratio <= 0 for dividend sid=1632, ex_date=2000-07-13, amount=181.000
[2021-02-23 16:54:00.666608] WARNING: zipline.data.adjustments: Dividend ratio <= 0 for dividend sid=1657, ex_date=2013-09-30, amount=21.355
[2021-02-23 16:54:00.666700] WARNING: zipline.data.adjustments: Dividend ratio <= 0 for dividend sid=1775, ex_date=1994-12-01, amount=76.000
[2021-02-23 16:54:00.666820] WARNING: zipline.data.adjustments: Dividend ratio <= 0 for dividend sid=1776, ex_date=1996-11-04, amount=36.708
[2021-02-23 16:54:00.666918] WARNING: zipline.data.adjustments: Dividend ratio <= 0 for dividend sid=2455, ex_date=2016-10-03, amount=25.611
[2021-02-23 16:54:00.667013] WARNING: zipline.data.adjustments: Dividend ratio <= 0 for dividend sid=2687, ex_date=2008-06-26, amount=10.000
[2021-02-23 16:54:00.667106] WARNING: zipline.data.adjustments: Dividend ratio <= 0 for dividend sid=2900, ex_date=2007-07-02, amount=88.530
[2021-02-23 16:54:00.667198] WARNING: zipline.data.adjustments: Dividend ratio <= 0 for dividend sid=3088, ex_date=2015-04-27, amount=31.291
(ml4t-zipline) packt@a20fd7fbed78:~/ml4t$ lab
stefan-jansen commented 3 years ago

Looks like it's working then?

You can also run !conda install -n ml4t-zipline seaborn -y in the notebook, the -y implies you are confirming and avoids the prompt. I'll have a new Zipline image with Python 3.6 and seaborn up in the coming days.

JeremyWhittaker commented 2 years ago

If we can update the code this should fix this error.

spreads.to_hdf('heuristics.h5', key='spreads', format='table')
spreads = pd.read_hdf('heuristics.h5', key='spreads')