quantopian / zipline

Zipline, a Pythonic Algorithmic Trading Library
https://www.zipline.io
Apache License 2.0
17.68k stars 4.72k forks source link

Non-US equities: "zipline.errors.SymbolNotFound" #1993

Closed SockPastaRock closed 4 years ago

SockPastaRock commented 7 years ago

Dear Zipline Maintainers,

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

Environment

alembic 0.7.7 py27_0 quantopian asn1crypto 0.22.0 py27h94ebe91_1
backports 1.0 py27h63c9359_1
backports.functools_lru_cache 1.4 py27he8db605_1
backports_abc 0.5 py27h7b3c97b_0
bcolz 0.12.1 np111py27_0 quantopian bottleneck 1.2.1 py27h21b16a3_0
bzip2 1.0.6 h0376d23_1
ca-certificates 2017.08.26 h1d4fec5_0
certifi 2017.7.27.1 py27h9ceb091_0
cffi 1.10.0 py27hf1aaaf4_1
chardet 3.0.4 py27hfa10054_1
click 6.7 py27h4225b90_0
contextlib2 0.5.5 py27hbf4c468_0
cryptography 2.0.3 py27hea39389_1
cycler 0.10.0 py27hc7354d3_0
cyordereddict 0.2.2 py27_0 quantopian cython 0.26.1 py27hdbcff32_0
dbus 1.10.22 h3b5a359_0
decorator 4.1.2 py27h1544723_0
empyrical 0.2.2 py27_0 quantopian enum34 1.1.6 py27h99a27e9_1
expat 2.2.4 hc00ebd1_1
fontconfig 2.12.4 h88586e7_1
freetype 2.8 h52ed37b_0
functools32 3.2.3.2 py27h4ead58f_1
glib 2.53.6 hc861d11_1
gst-plugins-base 1.12.2 he3457e5_0
gstreamer 1.12.2 h4f93127_0
hdf5 1.10.1 hb0523eb_0
icu 58.2 h211956c_0
idna 2.6 py27h5722d68_1
intervaltree 2.1.0 py27_0 quantopian ipaddress 1.0.18 py27h337fd85_0
jpeg 9b habf39ab_1
libedit 3.1 heed3624_0
libffi 3.2.1 h4deb6c0_3
libgcc-ng 7.2.0 h7cc24e2_2
libgfortran 3.0.0 1
libgfortran-ng 7.2.0 h9f7466a_2
libpng 1.6.32 hda9c8bc_2
libstdcxx-ng 7.2.0 h7a57d05_2
libxcb 1.12 h84ff03f_3
libxml2 2.9.4 h6b072ca_5
logbook 0.12.5 py27_0 quantopian lru-dict 1.1.4 py27_0 quantopian lzo 2.10 h1bfc0ba_1
mako 1.0.7 py27h3d58d4b_0
markupsafe 1.0 py27h97b2822_1
matplotlib 2.1.0 py27h09aba24_0
mkl 2017.0.3 0
multipledispatch 0.4.9 py27h9b5f95a_0
ncurses 6.0 h06874d7_1
networkx 2.0 py27hfc23926_0
numexpr 2.6.2 np111py27_0
numpy 1.11.3 py27_0
openssl 1.0.2l h077ae2c_5
pandas 0.18.1 np111py27_0
pandas-datareader 0.5.0 py27_0
patsy 0.4.1 py27hd1cf8c0_0
pcre 8.41 hc71a17e_0
pip 9.0.1 py27hbf658b2_3
pycparser 2.18 py27hefa08c5_1
pyopenssl 17.2.0 py27h189ff3b_0
pyparsing 2.2.0 py27hf1513f8_1
pyqt 5.6.0 py27h4b1e83c_5
pysocks 1.6.7 py27he2db6d2_1
pytables 3.4.2 py27h1f7bffc_2
python 2.7.14 hc2b0042_21
python-dateutil 2.6.1 py27h4ca5741_1
pytz 2017.2 py27hcac29fa_1
qt 5.6.2 h974d657_12
readline 7.0 hac23ff0_3
requests 2.18.4 py27hc5b0589_1
requests-file 1.4.1 py27_0
requests-ftp 0.3.1 py27_0
scipy 0.19.0 np111py27_0
setuptools 36.5.0 py27h68b189e_0
singledispatch 3.4.0.3 py27h9bcb476_0
sip 4.18.1 py27he9ba0ab_2
six 1.11.0 py27h5f960f1_1
sortedcontainers 1.4.4 py27_0 quantopian sqlalchemy 1.1.13 py27hb0a01da_0
sqlite 3.20.1 h6d8b0f3_1
ssl_match_hostname 3.5.0.1 py27h4ec10b9_2
statsmodels 0.8.0 py27hc87d62d_0
subprocess32 3.2.7 py27h373dbce_0
tk 8.6.7 h5979e9b_1
toolz 0.8.2 py27hd3b1e7e_0
tornado 4.5.2 py27h97b179f_0
urllib3 1.22 py27ha55213b_0
wheel 0.29.0 py27h411dd7b_1
xz 5.2.3 h2bcbf08_1
zipline 1.1.1 np111py27_0 quantopian zlib 1.2.11 hfbfcf68_1

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

I am attempting to use non-US equities with zipline. I have followed the instructions from this guide:

http://www.prokopyshen.com/create-custom-zipline-data-bundle

Using data from Yahoo for the stock symbol AQF or ASX.AQF (https://au.finance.yahoo.com/quote/AQF.AX?p=AQF.AX). I downloaded the 'max' historical data for this in to a csv and ingested it in to a bundle without any issue. Following the guide linked above, I was able to perform the last step which verifies that the data was ingested correctly.


#!/usr/bin/env python
#
# Copyright 2014 Quantopian, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from zipline.api import order, record, symbol

def initialize(context):
    pass

def handle_data(context, data):
    order(symbol('ASX.AQF'), 10)
    record(ADR=data.current(symbol('ASX.AQF'), 'price'))

# Note: this function can be removed if running
# this algorithm on quantopian.com
def analyze(context=None, results=None):
    import matplotlib.pyplot as plt
    # Plot the portfolio and asset data.
    ax1 = plt.subplot(211)
    results.portfolio_value.plot(ax=ax1)
    ax1.set_ylabel('Portfolio value (AUD)')
    ax2 = plt.subplot(212, sharex=ax1)
    results.ADR.plot(ax=ax2)
    ax2.set_ylabel('AQF price (AUD)')

    # Show the plot.
    plt.gcf().set_size_inches(18, 8)
    plt.show()

def _test_args():
    """Extra arguments to use when zipline's automated tests run this example.
    """
    import pandas as pd

    return {
        'start': pd.Timestamp('2017-01-01', tz='utc'),
        'end': pd.Timestamp('2017-06-06', tz='utc'),
    }

When I run something like "zipline -f buyAQF.py -b csv -s 2017-1-1 -e 2017-6-6" I get the following response:

(zipline_env2) user@ubuntu:~/My_Education/Algo_Trading/2 Git_Clone/zipline/zipline/examples$ zipline run -f buyAQF.py -b csv -s 2017-1-1 -e 2017-6-6 entering viacsv. tuSymbols= ('ASX.AQF',) about to return ingest function [2017-10-24 10:41:43.694868] WARNING: Loader: Refusing to download new benchmark data because a download succeeded at 2017-10-24 10:12:52.666862+00:00. Traceback (most recent call last): File "/home/user/anaconda3/envs/zipline_env2/bin/zipline", line 11, in load_entry_point('zipline==1.1.1', 'console_scripts', 'zipline')() File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/click/core.py", line 722, in call return self.main(args, kwargs) File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/click/core.py", line 535, in invoke return callback(args, kwargs) File "/home/user/anaconda3/envs/ziplineenv2/lib/python2.7/site-packages/zipline/main.py", line 97, in return f(*args, *kwargs) File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func return f(get_current_context(), args, kwargs) File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/main.py", line 240, in run environ=os.environ, File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/utils/run_algo.py", line 179, in _run overwrite_sim_params=False, File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/algorithm.py", line 709, in run for perf in self.get_generator(): File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/gens/tradesimulation.py", line 222, in transform for capital_change_packet in every_bar(dt): File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/gens/tradesimulation.py", line 135, in every_bar handle_data(algo, current_data, dt_to_use) File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/utils/events.py", line 216, in handle_data dt, File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/utils/events.py", line 235, in handle_data self.callback(context, data) File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/algorithm.py", line 459, in handle_data self._handle_data(self, data) File "buyAQF.py", line 25, in handle_data order(symbol('ASX.AQF'), 10) File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/utils/api_support.py", line 57, in wrapped return getattr(algo_instance, f.name)(*args, **kwargs) File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/algorithm.py", line 1182, in symbol """Lookup an Equity by its ticker symbol. File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/algorithm.py", line 1212, in symbol as_of_date=_lookup_date, File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/assets/assets.py", line 838, in lookup_symbol return self._lookup_symbol_strict(symbol, as_of_date) File "/home/user/anaconda3/envs/zipline_env2/lib/python2.7/site-packages/zipline/assets/assets.py", line 708, in _lookup_symbol_strict raise SymbolNotFound(symbol=symbol) zipline.errors.SymbolNotFound: Symbol 'ASX.AQF' was not found.

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

Reproduction Steps

  1. Install zipline in a conda virtual environment.

  2. Follow the steps illustrated in the guide: http://www.prokopyshen.com/create-custom-zipline-data-bundle

  3. Create a bundle using this data from yahoo finance: https://au.finance.yahoo.com/quote/AQF.AX?p=AQF.AX

  4. Create a python file with the code segment pasted above. Save it as buyAQF.py

  5. zipline -f buyAQF.py -b csv -s 2017-1-1 -e 2017-6-6 ...

What steps have you taken to resolve this already?

None, as I am unsure how to troubleshoot this issue ...

Anything else?

...

Sincerely, sockpastarock

freddiev4 commented 6 years ago

Sorry for the late response here @SockPastaRock. Did you run zipline ingest -b <your_bundle_name> after writing the custom bundle?

Also if you'd like to use csv files you can use the csvdir bundle.

Paste from the Gitter chat:

image

ernestoeperez88 commented 4 years ago

@SockPastaRock I'm gonna go ahead and close this issue. Please feel free to reopen if you run into any other issues, or have any questions.