Figuring out what dependencies are needed

Discussion in 'Python' started by sal, Dec 11, 2013.

  1. sal

    sal Guest

    I'm a Python beginner. I want to use it for stats work, so I downloaded Anaconda which has several of the popular libraries already packaged for Mac OS X.

    Now I'd like to use the backtesting package from zipline (, but while running the test script in iPython, I receive the following error:

    AssertionError Traceback (most recent call last)
    <ipython-input-6-f921351f78e2> in <module>()
    ----> 1 data = load_from_yahoo()
    2 dma = DualMovingAverage()
    3 results =

    1) I assume that I'm missing some packages that aren't included in Anaconda, but how do I know which ones to upload?

    2) Often I'll just unzip a library file and put the main folder in the iPython folder, but I notice there's usually a file in the main library folder. I've been ignoring this. Should I be using it?

    sal, Dec 11, 2013
    1. Advertisements

  2. and probably others.
    Mark Lawrence, Dec 11, 2013
    1. Advertisements

  3. ".io" is not normally a file extension for Python files. Are you sure
    that's Python code?

    I think you may be missing one or more lines? Perhaps something like
    "AssertionError: blah blah blah" appearing after that?

    For those unfamiliar with iPython, rather than a standard Traceback, that
    appears to suggest that is raising AssertionError, but we
    can't see what (if any) error message is given by that assert, or how it

    Can you explain what precise command you are running? Please copy and
    paste the exact command line you used that gives that error.

    Also, whenever you get unexpected errors while running from an IDE or non-
    standard environment like IDLE or iPython, your first step should be to
    run the same script from the command line using the vanilla Python
    interpreter and see if the error goes away. Do you need assistance with
    doing that? Feel free to ask for additional instructions.

    Why do you make that assumption? I would expect missing packages to give
    an ImportError, not an AssertionError.

    Absolutely! You'll probably see a READ ME file in the unzipped folder,
    you should read that for instructions.

    It may be that sometimes the file will do nothing more than copy
    the main folder into your site-packages folder, but it may do a lot more.
    Also, if you just dump random packages into iPython's private library
    area, you may even break iPython.
    Steven D'Aprano, Dec 11, 2013
  4. sal

    Robert Kern Guest

    That's a package name, not a filename.
    No, the ----> arrow points to the active line in that frame of the traceback.
    Unfortunately, the OP cut off the remaining frames under `load_from_yahoo()`
    actually has the assert that is failing.

    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
    Robert Kern, Dec 11, 2013
  5. sal

    alex23 Guest

    You're not missing a package, you're missing parameters. This is the
    signature for load_from_yahoo:

    def load_from_yahoo(indexes=None,

    The first thing it does is call a helper function
    `_load_raw_yahoo_data`, which has this assertion:

    assert indexes is not None or stocks is not None, """

    As you're passing no parameters into `load_from_yahoo`, both `indexes`
    and `stocks` default to None, so the assertion fails. Take a look at the
    examples in the zipline library to see what it is expecting.
    alex23, Dec 12, 2013
  6. sal

    sal i Guest

    Thanks everyone.

    This is the entire testing file along with the error at the bottom. It looks like a stock is specified as data['AAPL']:

    %pylab inline
    Populating the interactive namespace from numpy and matplotlib
    In [14]:

    from zipline.algorithm import TradingAlgorithm
    from zipline.transforms import MovingAverage
    from zipline.utils.factory import load_from_yahoo
    In [15]:

    class DualMovingAverage(TradingAlgorithm):
    """Dual Moving Average algorithm.
    def initialize(self, short_window=200, long_window=400):
    # Add 2 mavg transforms, one with a long window, one
    # with a short window.
    self.add_transform(MovingAverage, 'short_mavg', ['price'],

    self.add_transform(MovingAverage, 'long_mavg', ['price'],

    # To keep track of whether we invested in the stock or not
    self.invested = False

    self.short_mavg = []
    self.long_mavg = []

    def handle_data(self, data):
    if (data['AAPL'].short_mavg['price'] > data['AAPL'].long_mavg['price']) and not self.invested:
    self.order('AAPL', 100)
    self.invested = True
    elif (data['AAPL'].short_mavg['price'] < data['AAPL'].long_mavg['price']) and self.invested:
    self.order('AAPL', -100)
    self.invested = False

    # Save mavgs for later analysis.

    In [16]:

    data = load_from_yahoo()
    dma = DualMovingAverage()
    results =
    AssertionError Traceback (most recent call last)
    <ipython-input-16-f921351f78e2> in <module>()
    ----> 1 data = load_from_yahoo()
    2 dma = DualMovingAverage()
    3 results =

    /Users/my_mac/zipline/data/loader.pyc in load_from_yahoo(indexes, stocks, start, end, adjusted)
    303 """
    --> 304 data = _load_raw_yahoo_data(indexes, stocks, start, end)
    305 if adjusted:
    306 close_key = 'Adj Close'

    /Users/my_mac/zipline/data/loader.pyc in _load_raw_yahoo_data(indexes, stocks, start, end)
    246 assert indexes is not None or stocks is not None, """
    --> 247 must specify stocks or indexes"""
    249 if start is None:

    must specify stocks or indexes
    sal i, Dec 12, 2013
  7. sal

    alex23 Guest

    You're _still_ not passing into `load_from_yahoo` either `indexes` or
    `stocks` parameters, as I tried to point out by highlighting:

    assert indexes is not None or stocks is not None, """

    Either `indexes` must have a value or stocks must.
    Which is exactly what the error is telling you.

    This isn't a dependency issue. You just need to read the documentation,
    work out what format it requires indexes or stocks to be specified in,
    and then pass them to `load_from_yahoo`. Calling it without _any_
    arguments will give you the exception you're seeing.

    Look at the file examples/, it shows you exactly
    what you need:

    data = load_from_yahoo(stocks=['AAPL'], indexes={}, start=start,
    alex23, Dec 17, 2013
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.