zipline icon indicating copy to clipboard operation
zipline copied to clipboard

SymbolNotFound if changing AAPL -> QQQ

Open marcejohnson opened this issue 9 years ago • 4 comments

Starting with a fresh install of lastest zipline from github (1e28743), on Ubuntu 16.04, virtualenv pip install.

Performing default zipline ingest and then using sample code from: http://www.zipline.io/beginner-tutorial.html ...works as shown in the tutoral. So far so good.

But merely changing AAPL to QQQ as shown here:

from zipline.api import order, record, symbol

def initialize(context):
    pass

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

Returns

zipline.errors.SymbolNotFound: Symbol 'QQQ' was not found.

Before that I notice it says "Downloading benchmark data for 'SPY'" although SPY is nowhere in the code.

In detail:

(zipline) marc@marcj:~/zipline$ zipline run -f test.py --start 2017-1-1 --end 2017-4-1
[2017-06-07 02:52:04.028969] INFO: Loader: Cache at /home/marc/.zipline/data/SPY_benchmark.csv does not have data from 1990-01-02 00:00:00+00:00 to 2017-06-05 00:00:00+00:00.
[2017-06-07 02:52:04.029275] INFO: Loader: Downloading benchmark data for 'SPY' from 1989-12-29 00:00:00+00:00 to 2017-06-05 00:00:00+00:00
[2017-06-07 02:52:05.646311] WARNING: Loader: Still don't have expected data after redownload!
Traceback (most recent call last):
  File "/home/marc/zipline/bin/zipline", line 11, in <module>
    load_entry_point('zipline==1.1.0+177.g1e28743', 'console_scripts', 'zipline')()
  File "/home/marc/zipline/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/marc/zipline/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/marc/zipline/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/marc/zipline/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/marc/zipline/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/__main__.py", line 97, in _
    return f(*args, **kwargs)
  File "/home/marc/zipline/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/__main__.py", line 240, in run
    environ=os.environ,
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/utils/run_algo.py", line 179, in _run
    overwrite_sim_params=False,
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/algorithm.py", line 709, in run
    for perf in self.get_generator():
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/gens/tradesimulation.py", line 222, in transform
    for capital_change_packet in every_bar(dt):
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/gens/tradesimulation.py", line 135, in every_bar
    handle_data(algo, current_data, dt_to_use)
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/utils/events.py", line 216, in handle_data
    dt,
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/utils/events.py", line 235, in handle_data
    self.callback(context, data)
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/algorithm.py", line 459, in handle_data
    self._handle_data(self, data)
  File "test.py", line 9, in handle_data
    order(symbol('QQQ'), 10)
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/utils/api_support.py", line 57, in wrapped
    return getattr(algo_instance, f.__name__)(*args, **kwargs)
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/algorithm.py", line 1182, in symbol
    """Lookup an Equity by its ticker symbol.
  File "/home/marc/zipline/local/lib/python2.7/site-packages/zipline/algorithm.py", line 1212, in symbol
    as_of_date=_lookup_date,
  File "/home/marc/zipline/local/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/marc/zipline/local/lib/python2.7/site-packages/zipline/assets/assets.py", line 708, in _lookup_symbol_strict
    raise SymbolNotFound(symbol=symbol)
zipline.errors.SymbolNotFound: Symbol 'QQQ' was not found.

Is this a bug, or am I doing something wrong?

Also, as a foonote: when I reinstall and use release 1.1.0 (instead of master@1e28743), the error is: Downloading benchmark data for '^GSPC'.... rllib2.HTTPError: HTTP Error 404: Not Found ...although nowhere in the code am I referencing symbol ^GSPC. I think this is mentioned in other tickets.

marcejohnson avatar Jun 07 '17 02:06 marcejohnson

Hi @marcejohnson thanks for posting your issue. There are several questions/concerns here it seems so I'll try to address them one at a time.

  • AAPL to QQQ : When you run zipline ingest, by default you end up downloading the quantopian-quandl bundle, which uses the Quandl WIKI dataset. After inspecting the dataset, it looks like there is no equity in it called QQQ, which is why it is not in your bundle, and is the reason for your SymbolNotFound error. You can find more info about zipline bundles here (though ignore the custom Yahoo bundle info, as that will be removed in the next release and is no longer functional)

  • Downloading benchmark data for SPY : When you run your algorithm using zipline run, by default we download SPY data from Google Finance to be used as the benchmark for your algorithm. You can see the code for this in zipline/data/loader.py and zipline/data/benchmarks.py.

  • Downloading benchmark data for ^GSPC : In our most recent release, 1.1.0, we had downloaded data from Yahoo Finance, to download ^GSPC data (Yahoo's ticker for the S&P 500) to be used as a benchmark, but Yahoo made some breaking changes to their API and so we had to swap out our benchmark code to use Google Finance instead; so benchmarks work on master but not in the latest release (we'll need to cut a new release at some point to reflect this changes). You can see the issue that was opened up to get a better sense of what was happening.

I hope I was able to answer your questions. If you're confused by anything or have other questions feel free to add them here or open up separate issue 😄

freddiev4 avatar Jun 07 '17 14:06 freddiev4

Thank you for the detailed response @FreddieV4!

How to best integrate so to obtain basic symbols (like QQQ)? The unresolved problem I'm trying to solve is to create a workflow that enables going back and forth between Quantopian and Zipline. Do we know what data vendor Quantopian uses to supply the basic pipeline (daily resolution is fine)? Thanks again. 😄

marcejohnson avatar Jun 07 '17 16:06 marcejohnson

Hey @marcejohnson if you already have your own data for QQQ you would just need to have that both locally and on Quantopian to switch back and forth; in terms of ingesting your data to run with zipline, you'd need to build your own data bundle.

In regards to data vendors, Quantopian uses several data vendors. Most of the pricing data, including the live pricing for paper trading, comes from Nanex.

freddiev4 avatar Jun 07 '17 17:06 freddiev4

Thanks for the details @FreddieV4. The remaining issues are covered in other tickets (such as #1776) so closing this ticket.

marcejohnson avatar Jun 08 '17 12:06 marcejohnson