Closed JeremyWhittaker closed 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.
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
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)
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?
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.
I was confusing your installation sections "parts" and "chapters" So you are correct. I was using the wrong Conda environment.
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'
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.
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
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.
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')
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)