Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61563 > unrolled thread
| Started by | sal@nearlocal.com |
|---|---|
| First post | 2013-12-11 04:44 -0800 |
| Last post | 2013-12-17 13:30 +1000 |
| Articles | 8 — 7 participants |
Back to article view | Back to comp.lang.python
Figuring out what dependencies are needed sal@nearlocal.com - 2013-12-11 04:44 -0800
Re: Figuring out what dependencies are needed Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-11 13:27 +0000
Re: Figuring out what dependencies are needed Robert Kern <robert.kern@gmail.com> - 2013-12-11 13:38 +0000
Re: Figuring out what dependencies are needed Ian Kelly <ian.g.kelly@gmail.com> - 2013-12-11 13:21 -0700
Re: Figuring out what dependencies are needed Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-11 13:25 +0000
Re: Figuring out what dependencies are needed alex23 <wuwei23@gmail.com> - 2013-12-12 15:48 +1000
Re: Figuring out what dependencies are needed sal i <sal@nearlocal.com> - 2013-12-11 22:53 -0800
Re: Figuring out what dependencies are needed alex23 <wuwei23@gmail.com> - 2013-12-17 13:30 +1000
| From | sal@nearlocal.com |
|---|---|
| Date | 2013-12-11 04:44 -0800 |
| Subject | Figuring out what dependencies are needed |
| Message-ID | <e84a7ca4-5aa5-4c86-bf36-daa768d92aea@googlegroups.com> |
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?
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
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-12-11 13:27 +0000 |
| Message-ID | <52a8682b$0$29992$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #61563 |
On Wed, 11 Dec 2013 04:44:53 -0800, sal wrote: > Now I'd like to use the backtesting package from zipline (zipline.io), ".io" is not normally a file extension for Python files. Are you sure that's Python code? > 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) 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 dma.run(data) is raising AssertionError, but we can't see what (if any) error message is given by that assert, or how it fails. 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. > 1) I assume that I'm missing some packages that aren't included in > Anaconda, but how do I know which ones to upload? Why do you make that assumption? I would expect missing packages to give an ImportError, not an AssertionError. > 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? 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 setup.py 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
[toc] | [prev] | [next] | [standalone]
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Date | 2013-12-11 13:38 +0000 |
| Message-ID | <mailman.3899.1386769116.18130.python-list@python.org> |
| In reply to | #61568 |
On 2013-12-11 13:27, Steven D'Aprano wrote: > On Wed, 11 Dec 2013 04:44:53 -0800, sal wrote: > >> Now I'd like to use the backtesting package from zipline (zipline.io), > > ".io" is not normally a file extension for Python files. Are you sure > that's Python code? That's a package name, not a filename. >> 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) > > 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 dma.run(data) is raising AssertionError, but we > can't see what (if any) error message is given by that assert, or how it > fails. 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
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2013-12-11 13:21 -0700 |
| Message-ID | <mailman.3933.1386793343.18130.python-list@python.org> |
| In reply to | #61568 |
On Wed, Dec 11, 2013 at 6:38 AM, Robert Kern <robert.kern@gmail.com> wrote: > On 2013-12-11 13:27, Steven D'Aprano wrote: >> >> On Wed, 11 Dec 2013 04:44:53 -0800, sal wrote: >> >>> Now I'd like to use the backtesting package from zipline (zipline.io), >> >> >> ".io" is not normally a file extension for Python files. Are you sure >> that's Python code? > > > That's a package name, not a filename. Actually, the ".io" there appears to be a TLD. At least, "zipline.io" is the address for the website of a "zipline" Python package.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-12-11 13:25 +0000 |
| Message-ID | <mailman.3898.1386768605.18130.python-list@python.org> |
| In reply to | #61563 |
On 11/12/2013 12:44, sal@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? > > 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 > https://pypi.python.org/pypi/z3c.dependencychecker and probably others. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2013-12-12 15:48 +1000 |
| Message-ID | <l8bins$pbr$1@dont-email.me> |
| In reply to | #61563 |
On 11/12/2013 10:44 PM, sal@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
>
[toc] | [prev] | [next] | [standalone]
| From | sal i <sal@nearlocal.com> |
|---|---|
| Date | 2013-12-11 22:53 -0800 |
| Message-ID | <5bb462e2-db2d-4b6f-b682-3be8cd794ae3@googlegroups.com> |
| In reply to | #61665 |
On Thursday, December 12, 2013 1:48:42 PM UTC+8, alex23 wrote:
> On 11/12/2013 10:44 PM, sal@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
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2013-12-17 13:30 +1000 |
| Message-ID | <l8oggj$1ek$1@dont-email.me> |
| In reply to | #61670 |
On 12/12/2013 4:53 PM, sal i wrote:
> This is the entire testing file along with the error at the bottom.
>
> data = load_from_yahoo()
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.
> AssertionError:
> must specify stocks or indexes
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/dual_moving_average.py, it shows you exactly
what you need:
data = load_from_yahoo(stocks=['AAPL'], indexes={}, start=start,
end=end)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web