zipline
zipline copied to clipboard
Zipline installation on Google Colab
Dear Zipline Maintainers,
Before I tell you about my issue, let me describe my environment:
Environment
- Operating System: google colab (MAC OS)
- Python Version: google colab python (not sure)
- Python Bitness: not sure
- How did you install Zipline: !pip
- Python packages: not sure
Now that you know a little about me, let me tell you about the issue I am having:
Description of Issue
-
What did you expect to happen? I can't seem to install zipline on google colab. An error came up and I ignored it and carried on with the example on the website.
-
What happened instead? ModuleNotFoundError: No module named 'Zipline'
The above message popped up...
Here is how you can reproduce this issue on your machine:
Reproduction Steps
- make a file in google colab
- !pip install Zipline
- Error! ...
What steps have you taken to resolve this already?
...
Anything else?
...
Sincerely,
rukawa917
I haven't checked myself, but note that Zipline only works with Python 3.5 not Python 3.6.
Currently, the Google Colab Python version is 3.6.9 and works through the POSIX, however, it could still install the Zipline package on this platform. I follow the official documentation to install it, and it could work to run without the benchmark.
You could also check manually as the following code:
[Input]
import os
import platform
import sys
print("OS Name:", os.name)
print("Platfrom:", platform.system())
print("Platform Version:", platform.release())
print("Python Version:", platform.python_version())
[Output]
OS Name: posix
Platform: Linux
Platform Version: 4.19.104+
Python Version: 3.6.9
Installation Step
- Because of it run on GNU/Linux-based OS, you need to install the needed packages by running the following code first:
!apt-get install libatlas-base-dev python-dev gfortran pkg-config libfreetype6-dev hdf5-tools
- You could run install the Zipline package command:
!pip install zipline
Notice that: You would get some error message like the following, but it could automate to solve these kind of issues. ERROR: xarray 0.15.1 has requirement pandas>=0.25, but you'll have pandas 0.22.0 which is incompatible. ERROR: scikit-image 0.16.2 has requirement networkx>=2.0, but you'll have networkx 1.11 which is incompatible. ...
- You have to restart the runtime, click the top tools line
Runtime > Restart Runtime. - Then you could set the Qundal API Key (You need to register an account.) to the environment variable.
import os
os.environ['QUANDL_API_KEY'] = 'Your Key'
- Load the zipline and run the ingest command.
%load_ext zipline
!zipline ingest -b quantopian-quandl
- Finally, you could run your trading algorithm without the benchmark.
%%zipline --start 2016-1-1 --end 2018-1-1 --no-benchmark
from zipline.api import order_target, record, symbol
import pandas as pd
def initialize(context):
context.i = 0
context.asset = symbol('AAPL')
def handle_data(context, data):
# Skip first 300 days to get full windows
context.i += 1
if context.i < 300:
return
# Compute averages
# data.history() has to be called with the same params
# from above and returns a pandas dataframe.
short_mavg = data.history(context.asset, 'price', bar_count=100, frequency="1d").mean()
long_mavg = data.history(context.asset, 'price', bar_count=300, frequency="1d").mean()
# Trading logic
if short_mavg > long_mavg:
# order_target orders as many shares as needed to
# achieve the desired number of shares.
order_target(context.asset, 100)
elif short_mavg < long_mavg:
order_target(context.asset, 0)
# Save values for later inspection
record(AAPL=data.current(context.asset, 'price'),
short_mavg=short_mavg,
long_mavg=long_mavg)
P.S.You could access this Notebook to see the full install record.
just running !pip install zipline works fine on Google colab
Hello All, How about Zipline WITH Benchmark I am not using quantopian .. (I use Google Colab) Code: from zipline.data import bundles import os os.environ['QUANDL_API_KEY'] = 'XXXXXXXXXXXXXXXXXXXXXXX'
%%zipline --start 2016-1-1 --end 2017-12-31 --capital-base 10000.0 -o buy_and_hold.pkl
imports from zipline.api import order_percent, symbol, record from zipline.finance import commission bundles.ingest('quandl')
Error i got: no data for bundle 'quantopian-quandl' on or before 2020-12-10 14:37:21.206189+00:00 maybe you need to run: $ zipline ingest -b quantopian-quandl
How can I fix this error?
AttributeError Traceback (most recent call last)
<ipython-input-15-48e32e2ff76d> in <module>()
9 from pathlib import Path
10 from dotenv import load_dotenv
---> 11 from zipline import run_algorithm
12 from zipline.api import order, symbol
13 # from oandapyV20.contrib.factories import InstrumentsCandlesFactory
3 frames
/usr/local/lib/python3.7/dist-packages/zipline/utils/pandas_utils.py in <module>()
221
222 _INDEXER_NAMES = [
--> 223 '_' + name for (name, _) in pd.core.indexing.get_indexers_list()
224 ]
225
AttributeError: module 'pandas.core.indexing' has no attribute 'get_indexers_list'
If you're running this in IPython or a Jupyter Notebook you should shut down the notebook and restart it again.
I had this issue in IPython and I shut it down and it worked when I rebooted it.
On Sun, Feb 28, 2021 at 5:26 AM Rob [email protected] wrote:
AttributeError Traceback (most recent call last)
in () 9 from pathlib import Path 10 from dotenv import load_dotenv ---> 11 from zipline import run_algorithm 12 from zipline.api import order, symbol 13 # from oandapyV20.contrib.factories import InstrumentsCandlesFactory 3 frames /usr/local/lib/python3.7/dist-packages/zipline/utils/pandas_utils.py in
() 221 222 INDEXER_NAMES = [ --> 223 '' + name for (name, _) in pd.core.indexing.get_indexers_list() 224 ] 225 AttributeError: module 'pandas.core.indexing' has no attribute 'get_indexers_list'
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/quantopian/zipline/issues/2706#issuecomment-787429572, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMLIYUFKG6OOYC4ZE4KJVXLTBIK3ZANCNFSM4M7SQ65A .
-- George Adams Head Prefect at Selwyn House School Founder & CEO of Neptune Financial Inc. "It always seems impossible until it's done" -Nelson Mandela