Don't Miss
Home » Articles » Trading Evolved – Errata and Updates

Trading Evolved – Errata and Updates

A book like Trading Evolved will without a doubt have errors. On top of errors, updates may also be needed as new versions of dependent software packages are released. I will keep a running log on this site of issues found, and suggested solutions. After this list grows long enough, I will update the book itself, and put a version number on it.

This article will be continuously updated.

 

Book Version 1.0

Version 1.0 of the book was released on August 8, 2019.

Unable to Install Zipline with Conda version 4.7.10

Conda version 4.7 seems to break some dependencies and may result in an inability to install Zipline using the syntax “conda install zipline -c quantopian”.

Workaround 1 – Downgrade Conda

https://github.com/quantopian/zipline/issues/2514

Workaround 2 – Install using pip

https://www.zipline.io/install.html#installing-with-pip

 

Typo in “Patching the Framework”

On page 96 there’s a typo and the wrong file name is stated. This was the very last thing I did on the book before shipping it, as the issue that needed patching appeared at the last moment.

The file to be changed is “benchmarks.py”, not “loader.py”.

Here is the complete, corrected version.

Zipline, like most software in Python world is not only free, but open source. You can see and edit all the code as you like, and one big advantage of this is that we can make changes and even fix bugs when needed. You may wonder why you would ever want to go and edit someone else’s code, but it can be very useful to have this possibility.

While writing this book, an interesting example of such a situation came up. One day, all the backtests suddenly stopped working, with an error message about failing to load benchmark data from some web address. As it turns out, there is a web call executed during backtests, where Zipline tries to pull data from an online source. This source, much like what happened to many other free data sources, suddenly stopped working without warning.

As of writing, this issue has not yet been addressed. But no worries, we can do it ourselves easily. We don’t actually need this benchmark data for anything that we will do in this book, and the easiest fix is to simply remove the web call and just return empty data.

My version of Zipline is 1.3, and if you’re working with the same version, you likely need to do this fix manually. It won’t take long.

First locate a file called benchmarks.py, which should be in your Zipline installation folder. You can use the file system search tools to locate it. If you are on Windows, the path will probably be similar to this.

C:\ProgramData\Anaconda3\envs\zip35\Lib\site-packages\zipline\data

It’s always a good idea to keep a backup of the original code, so rename this file to keep a copy. Then make a new file, with the name benchmarks.py, and put the following code in it before saving.

This code will simply return a data series from 1930 to 2030 with all zero values, which will effectively sidestep this web call issue, with no negative impact.

Addition to Patch

You may also need to bypass the cache in loader.py, in the same folder:

https://github.com/quantopian/zipline/issues/2480#issuecomment-504387554

 

Zipline Installation: failed with current_repodata.json

Error:

Collecting package metadata (current_repodata.json): done
Solving environment: failed with current_repodata.json, will retry with next repodata source.

Solution:

1) Update Conda to the latest version:

2) Install the free channel:

3) install Zipline:

 

Trouble Ingesting Quandl

Error:

“ValueError: Boolean array expected for the condition, not float64”

Solution:

Downgrading Pandas to 0.18.1

 

Jupyter version 5.0.0 not starting

Solution:

Downgrading “tornado” from 5.1.1 to 4.5.3

 

Trouble ingesting Quandl on Mac

Try

 

Typo Chapter 23 – Bundle Name

In chapter 23, you’re advised to ingest the random stocks bundle using

But that’s not the name of the bundle that we just created a few lines above. The name in used in the bundle was random_stock_data, so we need to use that name when ingesting.

Similar typo in regards to the futures bundle. The name of the file in the sample code is random_futures_data:

And

Note that you can call your bundles whatever you like, but the file names need to match the references, and the registered bundle name needs to match the ingest call.

56 comments

  1. Steven Petersen

    Good new book so far. The following are no big deal but though I’d mention them.

    “If the volatility is exactly half in Microsoft, you would theoretically achieve the same risk level if you invest twice as much in Tesla.” should be “…twice as much AS in Tesla” ?

    “You can create both a folder and a new Python file through that dropdown on the right side, which you can see in Figure 5‑2.” should be “…a new Python FOLDER” ? There is an option to create a file so I got confused.

    • Yes, that first one is unfortunate. Leaving out ‘as’ gave the sentence the opposite meaning…

      But the second sentence seems fine to me, unless I’m still missing something. It’s not a Python folder, it’s a regular folder that you can create. Or ‘directory’ if you’re so inclined.

      So you can create folders in Jupyter, as well as Jupyter Notebook python files. Click the dropdown, and you’ll see.

  2. hi Andreas, thank you for the book. Great book. Hope to be even better at backtesting in time to come. By the way, the sp500 downloaded did not show sp500 values but it showed all the components within instead. My understanding from the book is 2 columns, 1 date and the other would be values under sp500. Am i right to say that? Thank you for taking the time to read this.

    • The file under “/Chapter 6 Pandas” contains a price series of the index, for use in the code in that chapter.

      The file under “/data/index_members/” contains the historical components.

      Yes, naming both files sp500.csv was unfortunate…

      Also, please write an Amazon review. These days far too many authors are paying for bulk reviews, having hundreds of reviews in the first week. I don’t resort to that, but I do resort to nagging on people to write reviews. 🙂

  3. Zipline Installation: failed with current_repodata.json

    Missing a dash led to another error. For step 2 it should be:

    conda config –set restore_free_channel true

    I’m loving the book so far. I’m no coder, but have found my interest in investing a useful tool to motivate me to solve problems and tinker.

  4. https://github.com/ContinuumIO/anaconda-issues/issues/1423

    I had an issue trying to install the nb_conda package (pg.101) and while I didn’t save the error message it was something to do with nb_conda not being compatible with Python 3.5. Anyway I used the following command in the terminal from the link above to get it to install
    conda install -c conda-forge nb_conda

  5. Jupyter notebook not downloaded in my zip35 environment, open in jupyter greyed out, and cannot download notebook==6.0

    also can’t ingest quandl already downgraded pandas, or at least i think i did, just used

    conda install pandas=0.18.1

  6. which version of conda I should use to install zipline.

    First part of the message says
    “Workaround 1 – Downgrade Conda” , conda install conda=4.6.11

    The last part of the message says
    1) Update Conda to the latest version:

    What should I do?

  7. Just acquired “Trading Evolved” and want to thank you for your efforts in writing the book. I am finding it extremely useful in my quest to become proficient in using Python for financial analysis and equities trading.

    In the course of following along with the book in Jupyter Notebook I encountered an error in running “first Zipline backtest” as follows:

    ValueError: SQLite file ‘C:\\Users\\r1100/.zipline\\data\\quandl\\2019-08-21T20;57;11.306361\\assets-6.sqlite’ doesn’t exist

    So my question is what is this file and what is required to bring it into existence? Thank you.

    • That sounds like an error during bundle ingest. If you interrupt the ingest process, or if it for any reason fails, this error shows up. Try ingesting it again.

      Also, the Quandl bundle is very limited and I would very much recommend making your own bundle, for your own data, as explained in the later chapters in the book.

    • I don’t recall doing anything that would cause the ingest process to be interrupted. I will certainly try the ingest process again but with the verbose mode on (note I mostly use iPython) to get a better idea of what is going on should the error repeat. I think I will start making my own bundles – I prefer having more control over the overall process.

    • Oh, and be sure to start the kernel in the notebook after ingesting. In case you had the notebook running while doing the ingest, you’ll need to restart the kernel.

  8. Stephen Hankinson

    Great book Andreas. I’ve enjoyed all of your books to date.

    I noticed an issue with the dividend code when trying to import data with dividends. The divs.append method inside the process_stocks function is creating a local copy of the divs DataFrame which doesn’t apply the changes to the divs DataFrame in the random_stock_data function. You can confirm this by adding a print(divs) right before the adjustment_writer.write call, if using a dataset with dividends, and you’ll see the DataFrame being written is empty.

    A simple fix is to change the dividend check to the following:


    # If there's dividend data, add that to the dividend DataFrame
    if 'dividend' in df.columns:

    # Get the current highest index
    idx = len(divs)

    # Append this stock's dividends to the list of all dividends
    tmp = df[df['dividend'] != 0.0]['dividend']
    for ex_date, amount in tmp.iteritems():
    divs.loc[idx] = [sid, amount, ex_date, pd.NaT, pd.NaT, pd.NaT]
    idx = idx + 1

    Another thing I noticed when importing data from alphavantage is that the if your data is ordered newest to oldest you’ll get an error when importing it. This can be fixed by adding df.sort_index(inplace=True) right after the pd.read_csv call.

  9. https://github.com/quantopian/zipline/issues/1591

    im trapped here, please help, already changed the zipline-scrypt.py file, did not work, getting this

    Traceback (most recent call last):
    File “C:\Users\JAY\Anaconda3\envs\zip35\Scripts\zipline-script.py”, line 11, in
    load_entry_point(‘zipline==1.3.0’, ‘console_scripts’, ‘zipline’)()
    File “C:\Users\JAY\Anaconda3\envs\zip35\lib\site-packages\pkg_resources\__init__.py”, line 484, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
    File “C:\Users\JAY\Anaconda3\envs\zip35\lib\site-packages\pkg_resources\__init__.py”, line 2707, in load_entry_point
    return ep.load()
    File “C:\Users\JAY\Anaconda3\envs\zip35\lib\site-packages\pkg_resources\__init__.py”, line 2325, in load
    return self.resolve()
    File “C:\Users\JAY\Anaconda3\envs\zip35\lib\site-packages\pkg_resources\__init__.py”, line 2331, in resolve
    module = __import__(self.module_name, fromlist=[‘__name__’], level=0)
    File “C:\Users\JAY\Anaconda3\envs\zip35\lib\site-packages\zipline\__init__.py”, line 23, in
    from . import data
    File “C:\Users\JAY\Anaconda3\envs\zip35\lib\site-packages\zipline\data\__init__.py”, line 1, in
    from . import loader
    File “C:\Users\JAY\Anaconda3\envs\zip35\lib\site-packages\zipline\data\loader.py”, line 22, in
    from .benchmarks import get_benchmark_returns
    File “C:\Users\JAY\Anaconda3\envs\zip35\lib\site-packages\zipline\data\benchmarks.py”, line 23
    data = data[‘close’] return data.sort_index().iloc[1:]
    ^
    SyntaxError: invalid syntax.

    I’ve been stuck with setting up the environment for quite a while now

    • Hello Jay,

      It looks like a syntax error on line number 23 of the file benchmarks.py:

      File “C:\Users\JAY\Anaconda3\envs\zip35\lib\site-packages\zipline\data\benchmarks.py”, line 23
      data = data[‘close’] return data.sort_index().iloc[1:]
      ^
      SyntaxError: invalid syntax.

      I think you have the return statement in the same line as data = data[‘close’]

      Please change the content of this file “benchmark.py” exactly as follows:

      import pandas as pd
      from datetime import datetime
      from trading_calendars import get_calendar

      def get_benchmark_returns(symbol):
      cal = get_calendar(‘NYSE’)
      first_date = datetime(1930,1,1).date()
      last_date = datetime(2030,1,1).date()
      dates = cal.sessions_in_range(first_date,last_date)
      data = pd.DataFrame(0.0,index=dates,columns=[‘close’])
      data = data[‘close’]
      return data.sort_index().iloc[1:]

  10. Hi Andreas,

    Thank you very much for writing this book.

    When attempting to run the code in “Your First Zipline Backtest”, I get an error when trying to run the moving average window that says “NameError: name ‘context’ is not defined”.

    I’m sure this is something basic that I am missing, though it stops the whole thing from working. Would you happen to know what I am missing in this case.

    Thanks,
    James

  11. Working on a mac.

    After ingesting the quandl bundle, I ran the first zipline backtest and got the following error:

    ValueError: No JSON object could be decoded

  12. Hey Andreas, great book so far.

    In regard to the ‘Making a correlation Graph’, my correlation graph came out a bit different compared to the one showed on the book. (more spikes)

    I used the set of data you provided which is ‘indexes’ in chapter 6 pandas folder.

    Don’t know if it’s the matplotlib format/version or its the way the dataset in computed. Should we expect similar differences throughout the book?

    Thank you.

  13. Hi Andreas, great book and i am digging my way through it. Right stuff at the right time so to speak. Got environment set up on desktop – check! However, laptop is posing and issue re Quandl – despite all same as desktop, i am getting the dreaded “failed to create process”. i tried your suggested remedy of apply a double does of “” to the relevant file but alas…still same result ie “failed t0 create process”. Do you have other good ideas of where to look/what to do? Thanks in advance.

    Michael

    • Hi Michael,

      This is most likely an issue regarding installation path and probably there are spaces in your path. There’s a thread somewhere in the Zipline GitHub about this, and the solution likely involves modding the path with double quotes. I understand you tried this, but it’s probably something highly related.

      Sorry I can’t be more specific, but it’s difficult without actually seeing your exact setup. I’m pretty sure you’re on the right track though. This is a classic error relating to Windows and spaces in the path to the interpreter.

  14. Hello Andreas thanks for the book,

    On page 96 what do you mean “You may also need to bypass the cache in loader.py”?
    Do you mean override the whole file or just the section of the code between the triple quotes?

    Thanks

  15. Hey Andreas,

    You are commendable for writing this book, it is well written, clear, and exactly what young python developers are looking for!

    Was wondering if you, or anyone else watching this thread would be able to assist here. I am having the same issue as mentioned on this github post (https://github.com/quantopian/zipline/issues/2532), and as insult to injury I am unable to downgrade Anaconda to 4.6.11. It looks like this issue has arisen fairly recently based on what the community is saying.

    Has anyone else had this issue?

  16. I can not get past this error, JSONDecodeError: Expecting value: line 1 column 1 (char 0). I’ve read all the github threads, and have tried changing the benchmarks.py and loaders.py files, but to no avail.

    Any suggestions, on mac BTW.

    Thanks

    • Same problem here and I’m using Windows. This happened while trying the first zipline backtest:

      JSONDecodeError Traceback (most recent call last)
      in ()
      53 capital_base = 10000,
      54 data_frequency = ‘daily’,
      —> 55 bundle = ‘quandl’)

    • HELP!!!

      —————————————————————————
      JSONDecodeError Traceback (most recent call last)
      in
      53 capital_base = 10000,
      54 data_frequency = ‘daily’,
      —> 55 bundle = ‘quandl’)

      ~\Anaconda3\envs\zpline35\lib\site-packages\zipline\utils\run_algo.py in run_algorithm(start, end, initialize, capital_base, handle_data, before_trading_start, analyze, data_frequency, data, bundle, bundle_timestamp, trading_calendar, metrics_set, default_extension, extensions, strict_extensions, environ, blotter)
      428 local_namespace=False,
      429 environ=environ,
      –> 430 blotter=blotter,
      431 )

      ~\Anaconda3\envs\zpline35\lib\site-packages\zipline\utils\run_algo.py in _run(handle_data, initialize, before_trading_start, analyze, algofile, algotext, defines, data_frequency, capital_base, data, bundle, bundle_timestamp, start, end, output, trading_calendar, print_algo, metrics_set, local_namespace, environ, blotter)
      157 trading_calendar=trading_calendar,
      158 trading_day=trading_calendar.day,
      –> 159 trading_days=trading_calendar.schedule[start:end].index,
      160 )
      161 first_trading_day =\

      ~\Anaconda3\envs\zpline35\lib\site-packages\zipline\finance\trading.py in __init__(self, load, bm_symbol, exchange_tz, trading_calendar, trading_day, trading_days, asset_db_path, future_chain_predicates, environ)
      101 trading_day,
      102 trading_days,
      –> 103 self.bm_symbol,
      104 )
      105

      ~\Anaconda3\envs\zpline35\lib\site-packages\zipline\data\loader.py in load_market_data(trading_day, trading_days, bm_symbol, environ)
      147 # date so that we can compute returns for the first date.
      148 trading_day,
      –> 149 environ,
      150 )
      151 tc = ensure_treasury_data(

      ~\Anaconda3\envs\zpline35\lib\site-packages\zipline\data\loader.py in ensure_benchmark_data(symbol, first_date, last_date, now, trading_day, environ)
      214
      215 try:
      –> 216 data = get_benchmark_returns(symbol)
      217 data.to_csv(get_data_filepath(filename, environ))
      218 except (OSError, IOError, HTTPError):

      ~\Anaconda3\envs\zpline35\lib\site-packages\zipline\data\benchmarks.py in get_benchmark_returns(symbol)
      33 ‘https://api.iextrading.com/1.0/stock/{}/chart/5y’.format(symbol)
      34 )
      —> 35 data = r.json()
      36
      37 df = pd.DataFrame(data)

      ~\Anaconda3\envs\zpline35\lib\site-packages\requests\models.py in json(self, **kwargs)
      895 # used.
      896 pass
      –> 897 return complexjson.loads(self.text, **kwargs)
      898
      899 @property

      ~\Anaconda3\envs\zpline35\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
      317 parse_int is None and parse_float is None and
      318 parse_constant is None and object_pairs_hook is None and not kw):
      –> 319 return _default_decoder.decode(s)
      320 if cls is None:
      321 cls = JSONDecoder

      ~\Anaconda3\envs\zpline35\lib\json\decoder.py in decode(self, s, _w)
      337
      338 “””
      –> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      340 end = _w(s, end).end()
      341 if end != len(s):

      ~\Anaconda3\envs\zpline35\lib\json\decoder.py in raw_decode(self, s, idx)
      355 obj, end = self.scan_once(s, idx)
      356 except StopIteration as err:
      –> 357 raise JSONDecodeError(“Expecting value”, s, err.value) from None
      358 return obj, end

      JSONDecodeError: Expecting value: line 1 column 1 (char 0)

    • Hi Stephen.

      I finally managed to get passed that problem by also adding:

      from trading_calendars import get_calendar
      from datetime import datetime

      to the benchmarks.py fix that Andreas provided. So the full code would become:

      import pandas as pd
      import requests
      from trading_calendars import get_calendar
      from datetime import datetime

      def get_benchmark_returns(symbol):
      cal = get_calendar(‘NYSE’)
      first_date = datetime(1930,1,1)
      last_date = datetime(2030,1,1)
      dates = cal.sessions_in_range(first_date, last_date)
      data = pd.DataFrame(0.0, index=dates, columns=[‘close’])
      data = data[‘close’]
      return data.sort_index().iloc[1:]

      Moreover, please note that the loader.py contains the following statement twice, so make sure you find them both and apply the triple quotes to bypass them.
      “””
      if data is not None:
      return data
      “””

      I hope that works for you too.

  17. Thank you for this community here. I am currently facing a zipline issue. Used to work okay when I followed the instructions in chapter 7. Ingested the customized bundle as mentioned in chapter 23 but it did not work. Was unsure why so I uninstall anaconda and reinstalled everything. The same issue remains, zipline does not seem to be available/working.

    (zip35) C:\Users\chuam>zipline ingest -b quandl
    ‘zipline’ is not recognized as an internal or external command,
    operable program or batch file.

    The above is what I was given from the terminal. Not sure what is going on. Appreciate your advice. I have browsed through various forums the past one week but to no avail. Look forward to overcoming this. Thank you once again Andreas!

  18. Hello Andreas,
    Thank you very much for the book!
    I have a question for you, I have an API which gives me access to intraday data for futures and equities and I would like to have zipline connected to my API (which is from TradeStation).
    Could you please show me where I could find a guide for doing that? I am not a programmer and the chapter “Importing your data” in the book does not report the example.
    Thank you very much.

    Kind regards,
    Mark

  19. For the code in chapter 15, I keep getting AttributeError: ‘BundleData’ object has no attribute ‘equity_bar_reader’. This is after ingesting the random_futures_data bundle, editing the extensions.py file to register the bundle, and then patching the framework.

  20. Trying to use norgate data-zipline to implement your momentum 50 . but when I tried to get symbol(‘SPY’) or symbol(‘TLT’). it shows SymbolNotFound: Symbol ‘SPY’ was not found.

  21. Hi Andreas,

    Enjoying the book! I am using csi data, but having trouble reproducing results from the futures models (focusing on Time Return model since it is the simplest). Equity models are working fine.

    One issue at least is I have not been successful in creating a bundle with correct price_multiplier information. I have adapted the random_futures_bundle.py to include this in the metadata df and included a print(metadata) so I can see the info when I ingest. The print provides the correct price_multiplier. But for some reason running the Time Return model, the algo uses default price_multiplier = 1.0.

    Any idea how where the issue might be?

  22. Hi Anreas,

    Great book.
    Something I have always wanted to do. (Test systems with python)
    Now I am much much closer.
    Just wondering if you used norgate index constituents in back testing any models?
    I’m having some troubles but will try figure it out.

  23. Im on page 106 – Your First Zipline Backtest

    When running the complete source code i downloaded, i run into these errors:

    Any one can point me to the direction to fix this? Thanks!

    —————————————————————————
    NameError Traceback (most recent call last)
    in ()
    71 handle_data=handle_data,
    72 capital_base=10000,
    —> 73 data_frequency = ‘daily’, bundle=’quandl’
    74 )

    C:\Users\Anaconda3\envs\zip35v2\lib\site-packages\zipline\utils\run_algo.py in run_algorithm(start, end, initialize, capital_base, handle_data, before_trading_start, analyze, data_frequency, data, bundle, bundle_timestamp, trading_calendar, metrics_set, default_extension, extensions, strict_extensions, environ, blotter)
    428 local_namespace=False,
    429 environ=environ,
    –> 430 blotter=blotter,
    431 )

    C:\Users\Anaconda3\envs\zip35v2\lib\site-packages\zipline\utils\run_algo.py in _run(handle_data, initialize, before_trading_start, analyze, algofile, algotext, defines, data_frequency, capital_base, data, bundle, bundle_timestamp, start, end, output, trading_calendar, print_algo, metrics_set, local_namespace, environ, blotter)
    157 trading_calendar=trading_calendar,
    158 trading_day=trading_calendar.day,
    –> 159 trading_days=trading_calendar.schedule[start:end].index,
    160 )
    161 first_trading_day =\

    C:\Users\Anaconda3\envs\zip35v2\lib\site-packages\zipline\finance\trading.py in __init__(self, load, bm_symbol, exchange_tz, trading_calendar, trading_day, trading_days, asset_db_path, future_chain_predicates, environ)
    101 trading_day,
    102 trading_days,
    –> 103 self.bm_symbol,
    104 )
    105

    C:\Users\Anaconda3\envs\zip35v2\lib\site-packages\zipline\data\loader.py in load_market_data(trading_day, trading_days, bm_symbol, environ)
    147 # date so that we can compute returns for the first date.
    148 trading_day,
    –> 149 environ,
    150 )
    151 tc = ensure_treasury_data(

    C:\Users\Anaconda3\envs\zip35v2\lib\site-packages\zipline\data\loader.py in ensure_benchmark_data(symbol, first_date, last_date, now, trading_day, environ)
    215
    216 try:
    –> 217 data = get_benchmark_returns(symbol)
    218 data.to_csv(get_data_filepath(filename, environ))
    219 except (OSError, IOError, HTTPError):

    C:\Users\Anaconda3\envs\zip35v2\lib\site-packages\zipline\data\benchmarks.py in get_benchmark_returns(symbol)
    21 Andreas Solution to side step the problem
    22 “””
    —> 23 cal = get_calendar(‘NYSE’)
    24 first_date = datetime(1930,1,1)
    25 last_date = datetime(2030,1,1)

    NameError: name ‘get_calendar’ is not defined

    • i managed to troubleshoot the issue. i’ve forgotten to import get_calendar when patching the benchmarks.py

      silly me.

  24. Hi, Andreas. I purchased your kindle book. It is a great one. Really like it. Appreciate your effort putting on the book.
    I have a question on charter 12. For calculating annual slope, your code is ann_slope = (np.power(np.exp(slope), 252) -1)*100. Should it be ann_slope = (np.power(1+np.exp(slope)), 252) -1)*100?
    I will appreciate your response.

  25. Jose Andres Riveros

    Hi Andreas and everybody, Im currently now installing as it says in page 100, Matplotlib and nb_conda in my zip35 enviroment. i was able to install Matplotlib but when i try to do the same with nb_conda im getting this error it seems there is come incompatibility about the versions but in im doing it in the zip35 enviroment as supposed to, no clue how to solve this one appreciate in advance any help regarding this issue.

    UnsatisfiableError: The following specifications were found
    to be incompatible with the existing python installation in your environment:

    – nb_conda -> python[version=’>=3.6,=3.7, nb_conda_kernels[version=’>=2.0.0′] -> notebook[version=’>=4.2.0′] -> terminado[version=’>=0.8.1′] -> pywinpty -> python[version=’>=3.6,=3.7, pip -> wheel -> setuptools
    python=3.5 -> pip -> wheel -> setuptools
    Package wheel conflicts for:
    python=3.5 -> pip -> wheel
    nb_conda -> nb_conda_kernels[version=’>=2.0.0′] -> notebook[version=’>=4.2.0′] -> terminado[version=’>=0.8.1′] -> pywinpty -> python[version=’>=3.6,=3.7, pip -> wheel
    Package pip conflicts for:
    python=3.5 -> pip
    nb_conda -> nb_conda_kernels[version=’>=2.0.0′] -> notebook[version=’>=4.2.0′] -> terminado[version=’>=0.8.1′] -> pywinpty -> python[version=’>=3.6,=3.7, pip
    Package colorama conflicts for:
    python=3.5 -> pip -> colorama
    nb_conda -> nb_conda_kernels[version=’>=2.0.0′] -> notebook[version=’>=4.2.0′] -> terminado[version=’>=0.8.1′] -> pywinpty -> python[version=’>=3.6,=3.7, pip -> colorama
    Package wincertstore conflicts for:
    python=3.5 -> pip -> wheel -> setuptools -> wincertstore[version=’>=0.2′]
    nb_conda -> nb_conda_kernels[version=’>=2.0.0′] -> notebook[version=’>=4.2.0′] -> terminado[version=’>=0.8.1′] -> pywinpty -> python[version=’>=3.6,=3.7, pip -> wheel -> setuptools -> wincertstore[version=’>=0.2′]
    Package certifi conflicts for:
    nb_conda -> nb_conda_kernels[version=’>=2.0.0′] -> notebook[version=’>=4.2.0′] -> terminado[version=’>=0.8.1′] -> pywinpty -> python[version=’>=3.6,=3.7, pip -> cachecontrol -> requests -> urllib3[version=’>=1.21.1,=1.21.1,=1.21.1, certifi
    python=3.5 -> pip -> cachecontrol -> requests -> urllib3[version=’>=1.21.1,=1.21.1,=1.21.1, certifi
    Package six conflicts for:
    nb_conda -> nb_conda_kernels[version=’>=2.0.0′] -> notebook[version=’>=4.2.0′] -> terminado[version=’>=0.8.1′] -> pywinpty -> python[version=’>=3.6,=3.7, pip -> cachecontrol -> requests -> urllib3[version=’>=1.21.1,=1.21.1,=1.21.1, pyopenssl[version=’>=0.14′] -> cryptography[version=’>=1.9,>=2.2.1′] -> six[version=’>=1.4.1′]
    python=3.5 -> pip -> cachecontrol -> requests -> urllib3[version=’>=1.21.1,=1.21.1,=1.21.1, pyopenssl[version=’>=0.14′] -> cryptography[version=’>=1.9,>=2.2.1′] -> six[version=’>=1.4.1′]

    not pretty sure what the issue is in here

  26. Thanks for the very informative book and for releasing the kindle version at such a reasonable price.

    Just for info I’ve managed to get the first zipline backtest (Chapter 7) working on Windows 10 using the stock Python 3.5 and pip and avoiding the need for anaconda (in case anyone was thinking of going that way and wondered if it was possible).

    Cheers,
    Jamie.

  27. Dear Andreas,

    Thank you for producing another great book! I have very much enjoyed reading all three of your books.

    I had trouble ingesting futures data into zipline (both your data, as well as my own). No errors were produced during ingestion, but when running an algorithm, switching from contract to contract did not work correctly. Regardless of roll method, Zipline was selecting the next contract in the order that it occurred in my file directory! In my case, for instance, it was rolling from March 2017 to March 2018, instead of to June 2018.

    The zipline docs could be better regarding futures ingestion, so I had to look through the zipline code, which was a bit complicated. As far as I can see, rather than checking all live contracts to determine which to roll to next, Zipline seems to only check the next unexpired SID in the list for a given symbol root and wait to roll that one. So if the contracts are out of order, there will be problems.

    A straightforward solution is to adjust your ingest code to sort the file directory list by a combined string of delivery year and delivery month (assuming they are included in the filename) before passing the list on to the rest of the code as normal. This appears to work as expected, but the Zipline library is quite complex and I could easily be missing something else. If you have any further info regarding custom futures ingestion, please advise!

    I hope this may help some of you other readers and save them some grief!

    Thanks again for producing such great books!.

    All the Best,
    Paul

    • Hey Paul, I think I might be running into a similar (the same) issue as you. I am trying to replicate the sample futures backtests that Andreas has in the book. With all of them, I am error’ing out with an issue stitching the continuous futures together, specially in the “roll_finder.py”.
      At the top of the error output:
      —–

      Exception ignored in: ‘zipline.assets.continuous_futures.OrderedContracts.contract_before_auto_close’
      AttributeError: ‘NoneType’ object has no attribute ‘next’

      —–
      But, specifically, at the end of the output:
      —–

      39 session = self.trading_calendar.minute_to_session_label(dt)
      40 front = oc.contract_before_auto_close(session.value)
      —>41 back = oc.contract_at_offset(front, 1, dt.value)
      42 if back is None:
      43 return front
      with the additional trailing detail:
      ~\zipline\assets\continuous_futures.pyx in zipline.assets.continuous_futures.OrderedContracts.contract_at_offset (zipline/assets\continuous_futures.c:7309)()

      ~\zipline\assets\continuous_futures.pyx in zipline.assets.continuous_futures.OrderedContracts.contract_at_offset (zipline/assets\continuous_futures.c:7061)()

      KeyError: 0

      —–
      Is this what you are encountering? I am completely stymied at this point and am wondering if I have found someone with the same problem! I’m continuing to work on this and will of course report any progress… would welcome anyone else’s too! Cheers

      • Hi Devon,

        I’m not sure if I got that error specifically, but I expect we had the same problem.

        When digging through that part of the Zipline code I couldn’t see where OrderedContracts actually did any ordering! It seemed to me that OrderedContracts expected the contracts to already be in order! But I could have missed something.

        Everything seems to be OK for me now once I made sure that I ingested the futures contracts in expiration order. Prior to that, most all of the functionality related to futures and continuous futures was not working properly. Of course, one must make all the changes that Andreas talks about in his book (constants.py for instance).

        If you have ordered the contracts and you are still having problems, feel free to let me know as I did make one or two other (presumably) minor changes to the ingest code during the process of solving this issue which seemingly didn’t make a difference to the outcome at the time, but may have actually played a role in fixing the issue.

        Best of luck!
        Paul

  28. Hi Paul, That’s interesting. I did find one minor issue in my setup (was calling up futures contracts that weren’t included in Andreas’ “random futures data” set (are you using this data source or another futures data source?) but after fixing that I am still at an impasse that is precluding me from completing my first futures backtest.
    For what it’s worth, at the top of the error output:
    —–

    IndexError Traceback (most recent call last)
    in ()
    218 capital_base=initial_portfolio_millions * 1000000,
    219 data_frequency = ‘daily’,
    –> 220 bundle=’random_futures_data’ )

    —–
    But, specifically, at the end of the output:
    —–

    ~\Anaconda3\envs\env_zipline\lib\site-packages\pandas\core\indexing.py in _getitem_axis(self, key, axis)
    1828
    1829 # validate the location
    -> 1830 self._is_valid_integer(key, axis)
    1831
    1832 return self._get_loc(key, axis=axis)

    ~\Anaconda3\envs\env_zipline\lib\site-packages\pandas\core\indexing.py in _is_valid_integer(self, key, axis)
    1711 l = len(ax)
    1712 if key >= l or key 1713 raise IndexError(“single positional indexer is out-of-bounds”)
    1714 return True
    1715

    IndexError: single positional indexer is out-of-bounds

    —–
    At this point, I’d be interested in your “minor changes” that you made. On a broader scale, I wonder if there is any interest in setting up a Google Group or something similar to allow for broader idea swapping… Anyways, cheers! Devon

  29. Hey Paul, I’m still stuck on my issue but, to your point re: ordered contracts, check out this thread, starting with the comment I’m posting here: https://github.com/quantopian/zipline/issues/2293#issuecomment-424337172

  30. Hello Andreas,

    first thank you for your books and contstant attention to everyone writing to you in this site.

    Iwanted to ask for your opinion on the following issue. I have done a 18 yr backtest on the strategy explained in “Stocks on the move” and as I read your latest book, “Trading Evolved”, you recall something that i saw while doing my backtest but could not find the way of fixing it on that moment, which is the following: how to deal with already nonexistent stocks. My backtest was done over more than 700 european stocks, so I am not limited to an index with the risk of trading only the current stocks and not the historical. But still I figure my backtest is “not-trading” some stocks that are no currently in the market anymore. How do you thta could be fixed or, do you think on such an ample stock base, would have had a very significant impact?

    thank you,

    Javier

  31. Hey Paul, would you mind sharing with the group the amendment you made to the code to get the futures bundle to properly ingest the underlying futures files in the appropriate (chronological) order? Many thanks!

  32. Hi Andreas, great book with a lot of insights! I am having however some problems populating the mysql database as per Chapter 24. I have a problem for the vals part of the insert statement where I get an error message saying that symbol and df are defined. Also get an error in the process symbol function but managed to fix it by changing data_location to data_path and importing tqdm_notebook from tqdm. Any help would be greatly appreciated. Thanks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *

*