Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_benchmark() does not work #2072

Closed
jasonchk opened this issue Jan 2, 2018 · 5 comments
Closed

set_benchmark() does not work #2072

jasonchk opened this issue Jan 2, 2018 · 5 comments

Comments

@jasonchk
Copy link

jasonchk commented Jan 2, 2018

Dear Zipline Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

  • Operating System: (Mac OS X High Sierra)
  • Python Version: Python 3.5.4 :: Anaconda, Inc.
  • Python Bitness: 64
  • How did you install Zipline: conda install -c Quantopian zipline
  • Python packages: Zipline, Matplotlib and Plotly only.

Now that you know a little about me, let me tell you about the issue I am
having:

Description of Issue

I am receiving the following error, which appears to be caused by an issue with Google's finance data URL when trying to retrieve the default benchmark (SPY) when running the algorithm.

I have previously managed to update the URL in the appropriate file in pandas-datareader to resolve the issue but I wanted to try and use the set_benchmark function to work around this error.

  • What did you expect to happen?
    Set_benchmark to apply a different asset for benchmarking purpose.

  • What happened instead?
    The following error occurred:
    RemoteDataError: Unable to read URL: http://www.google.com/finance/historical?startdate=Dec+31%2C+1989&q=SPY&enddate=Dec+31%2C+2017&output=csv

It indicated that it's still trying to query data for a default asset (SPY) instead of the assigned asset in set_benchmark(symbol('AAPL')).

Here is how you can reproduce this issue on your machine:

Reproduction Steps

  1. Run the following code using a Jupyter Notebook:

`%%zipline --start 2010-1-1 --end 2011-1-1

from zipline.api import order, record, symbol, set_benchmark

def initialize(context):
set_benchmark(symbol('AAPL'))

def handle_data(context, data):
order(symbol('AAPL'), 10)
record(AAPL=data.current(symbol('AAPL'), 'price'))`

...

What steps have you taken to resolve this already?

I have tried to run the algorithm using the CLI but the same error message appears.
...

Anything else?

...

Sincerely,
Jason

@freddiev4
Copy link
Contributor

freddiev4 commented Jan 2, 2018

Hi @jasonchk this is due to some changes that Google had made to their API, so we removed that code in #2031. If you install the latest zipline master branch from GitHub, you should be able to run a backtest up to 5 years ago from the current day.

Installing from GitHub:
Make sure you have Git, or just download the .zip file via the GitHub GUI.

git clone git@github.com:quantopian/zipline.git
pip install zipline/

Running a Backtest:

zipline ingest -b quantopian-quandl # or use Quandl directly and have an API key; read more here: www.zipline.io/bundles.html
zipline run -f youralgo.py -s 2016-1-1 -e 2018-1-1 -b quantopian-quandl

@jasonchk
Copy link
Author

jasonchk commented Jan 2, 2018

Hi @freddiev4 thanks for the quick reply. I created a new Condo environment and installed the latest zipline master branch by downloading the zip file and running pip install. After installation, I ran zipline bundles and received the following error message.

bash-3.2$ zipline bundles
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
Traceback (most recent call last):
  File "/Users/user/anaconda3/envs/zipline_p35_v3/bin/zipline", line 7, in <module>
    from zipline.__main__ import main
  File "/Users/user/anaconda3/envs/zipline_p35_v3/lib/python3.5/site-packages/zipline/__init__.py", line 21, in <module>
    from . import finance
  File "/Users/user/anaconda3/envs/zipline_p35_v3/lib/python3.5/site-packages/zipline/finance/__init__.py", line 16, in <module>
    from . import execution, trading
  File "/Users/user/anaconda3/envs/zipline_p35_v3/lib/python3.5/site-packages/zipline/finance/execution.py", line 22, in <module>
    import zipline.utils.math_utils as zp_math
  File "/Users/user/anaconda3/envs/zipline_p35_v3/lib/python3.5/site-packages/zipline/utils/math_utils.py", line 53, in <module>
    nanmean = bn.nanmean
AttributeError: module 'bottleneck' has no attribute 'nanmean'

I have read somewhere that bottleneck is optional and that zipline can function without it. After removing 'bottleneck' (pip uninstall bottleneck) and running zipline bundles, I get the following error message.

RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
Traceback (most recent call last):
  File "/Users/user/anaconda3/envs/zipline_p35_v3/bin/zipline", line 7, in <module>
    from zipline.__main__ import main
  File "/Users/user/anaconda3/envs/zipline_p35_v3/lib/python3.5/site-packages/zipline/__init__.py", line 25, in <module>
    from .utils.run_algo import run_algorithm
  File "/Users/user/anaconda3/envs/zipline_p35_v3/lib/python3.5/site-packages/zipline/utils/run_algo.py", line 17, in <module>
    from zipline.algorithm import TradingAlgorithm
  File "/Users/user/anaconda3/envs/zipline_p35_v3/lib/python3.5/site-packages/zipline/algorithm.py", line 40, in <module>
    from zipline.data.data_portal import DataPortal
  File "/Users/user/anaconda3/envs/zipline_p35_v3/lib/python3.5/site-packages/zipline/data/data_portal.py", line 47, in <module>
    from zipline.data.resample import (
  File "/Users/user/anaconda3/envs/zipline_p35_v3/lib/python3.5/site-packages/zipline/data/resample.py", line 29, in <module>
    from zipline.data.minute_bars import MinuteBarReader
  File "/Users/user/anaconda3/envs/zipline_p35_v3/lib/python3.5/site-packages/zipline/data/minute_bars.py", line 22, in <module>
    import bcolz
  File "/Users/user/anaconda3/envs/zipline_p35_v3/lib/python3.5/site-packages/bcolz/__init__.py", line 55, in <module>
    from bcolz.carray_ext import (
ImportError: numpy.core.multiarray failed to import

@freddiev4
Copy link
Contributor

Hmm.. so it looks like there's a mismatch for the version numpy that you have and the and the version zipline is compiled against.

Two other options here in the meantime:

pip install zipline --no-binary :all: --no-cache-dir
or
conda install -c quantopian/label/ci zipline

@jasonchk
Copy link
Author

jasonchk commented Jan 5, 2018

I created a new conda environment (via Anaconda Navigator) and tried conda install -c quantopian/label/ci zipline but got the following error message.

(zipline_p35_v3) bash-3.2$ conda install -c quantopian/label/ci zipline
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  - zipline

Current channels:

  - https://conda.anaconda.org/quantopian/label/ci/osx-64
  - https://conda.anaconda.org/quantopian/label/ci/noarch
  - https://repo.continuum.io/pkgs/main/osx-64
  - https://repo.continuum.io/pkgs/main/noarch
  - https://repo.continuum.io/pkgs/free/osx-64
  - https://repo.continuum.io/pkgs/free/noarch
  - https://repo.continuum.io/pkgs/r/osx-64
  - https://repo.continuum.io/pkgs/r/noarch
  - https://repo.continuum.io/pkgs/pro/osx-64
  - https://repo.continuum.io/pkgs/pro/noarch

@freddiev4
Copy link
Contributor

Closing this as you should be able to do this in the latest release of zipline. You can see the release notes here Feel free to update to 1.2.0 with either:

pip install -U zipline

or

conda update zipline -c quantopian

If there are any problems, please open a new issue 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants