On Thursday, December 12, 2013 1:48:42 PM UTC+8, alex23 wrote: > On 11/12/2013 10:44 PM, s...@nearlocal.com wrote: > > > 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 (zipline.io), 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 = dma.run(data) > > > > > > 1) I assume that I'm missing some packages that aren't included in > > Anaconda, but how do I know which ones to upload? > > > > You're not missing a package, you're missing parameters. This is the > > signature for load_from_yahoo: > > > > def load_from_yahoo(indexes=None, > > stocks=None, > > start=None, > > end=None, > > adjusted=True): > > > > 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. > > > 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 setup.py file in the main > > library folder. I've been ignoring this. Should I be using it? > > > > > > Thanks > > >
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'], market_aware=True, window_length=short_window) self.add_transform(MovingAverage, 'long_mavg', ['price'], market_aware=True, window_length=long_window) # 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. self.short_mavg.append(data['AAPL'].short_mavg['price']) self.long_mavg.append(data['AAPL'].long_mavg['price']) In [16]: data = load_from_yahoo() dma = DualMovingAverage() results = dma.run(data) --------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-16-f921351f78e2> in <module>() ----> 1 data = load_from_yahoo() 2 dma = DualMovingAverage() 3 results = dma.run(data) /Users/my_mac/zipline/data/loader.pyc in load_from_yahoo(indexes, stocks, start, end, adjusted) 302 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) 245 246 assert indexes is not None or stocks is not None, """ --> 247 must specify stocks or indexes""" 248 249 if start is None: AssertionError: must specify stocks or indexes -- https://mail.python.org/mailman/listinfo/python-list