Dear Zipline Maintainers,
Before I tell you about my issue, let me describe my environment:
Operating System: (Windows Version or $ uname --all)
Windows 8.1
Python Version: $ python --version
Py3.5
Python Bitness: $ python -c 'import math, sys;print(int(math.log(sys.maxsize + 1, 2) + 1))'
How did you install Zipline: (pip, conda, or other (please explain))
install anaconda for py 3.6 and then create py3.5 environment
conda install -c quantopian zipline
Python packages: $ pip freeze or $ conda list
Now that you know a little about me, let me tell you about the issue I am
having:
I would like to replicate the quick start tutorial by running codes below:
==========================
But it seems that the ingestion line above is not the sytnax for windows. I've already got QUANDL_API_KEY, could you advise what I should do to run the same ingest line on windows platform.
Here is how you can reproduce this issue on your machine:
1.
2.
3.
...
...
...
Sincerely,
Kelvin
Hi @kelvinho8 I don't have access to a Windows machine right now (running macOS) but the syntax for running ingest in the README is specific to Linux / macOS.
If you search on your system for Environment Variables I think there's an application that let's you set System / User Environment Variables.
IIRC, you might be able to run set QUANDL_API_KEY=<yourapikey> from the Command Prompt, and then call zipline ingest -b quandl.
Hi @freddiev4 . Thank you for your answer.
In fact, I already did what you suggested by running set QUANDL_API_KEY=
Have a good day
Kelvin
I'm having exactly the same problem here. Did you guys find any solution to work this out on windows?
Solution for Win10 64-bit users. ! I had the same problem the last few days with ingest and benchmarks. To solve it, you will need a Python 3.5 environment. To create a python 3.5 environment, assuming you have an Anaconda installation of Python, open a command prompt and type: [conda create -n py35 python=3.5 anaconda] or if you already have a Python 3.5 environment with an old installation of zipline such as 1.1 uninstall zipline [conda uninstall zipline] but also uninstall empyrical [conda uninstall empyrical]. Then simply: pip install zipline. It will automatically install ver 1.2.0.
To set the quandl key in win 10 execute the following commands in your ipython environment::
import quandl
quandl.ApiConfig.api_key = 'your key'
Now open the terminal and you should be able to ingest data. with the key in the environment.
Thank you @freddiev4 for all the work.
like freddiev4 said. Input set QUANDL_API_KEY=
Going to close this as it's an older issue.
Running either:
>> set QUANDL_API_KEY=<yourapikey>
>> zipline ingest -b quandl
In your Command Prompt
Or
>> import quandl
>> quandl.ApiConfig.api_key = 'your key'
In a Python interpreter followed by zipline ingest -b quandl in your CP should work.
Feel free to open a new issue if there's still any problems.
I had the same problem
so instead of
>> set QUANDL_API_KEY=<yourapikey>
I tried this
>> setx QUANDL_API_KEY <yourapikey>
>> zipline ingest -b quandl
problem solved 馃憤
Hi I think I'm having similar issues and have tried all of the above. I believe I have correctly set up an environment running 3.5.5 so am a bit perplexed!
Using the setx method I receive the following:
(env_zipline) C:\Users\thoma>setx QUANDL_API_KEY "XXXX"
SUCCESS: Specified value was saved.
However
(env_zipline) C:\Users\thoma>zipline ingest -b quandl
Returns the following:
"Please set your QUANDL_API_KEY environment variable and retry."
ValueError: Please set your QUANDL_API_KEY environment variable and retry.
Any help at all would be greatly appreciated!
Thanks
Tom
Had the same issue. The above mentioned method somehow didn't work.
I manually edited in file "..\site-packages\ziplinedata\bundles\quandl.py":
from # api_key = environ.get('QUANDL_API_KEY')
to api_key = 'XXXXXXXXX'
then it's working.
Hope there's a neat solution coming up soon.
I am on a mac and using conda. I've installed zipline but when I try to ingest the quand bundle, all I get is: "Please set your QUANDL_API_KEY environment variable and retry."
ValueError: Please set your QUANDL_API_KEY environment variable and retry.
I tried @mark2n 's suggestion of going into the quandl.py file and manually entering my api_key, but that also didn't seem to work.
For Mac users, this work:
$ export QUANDL_API_KEY="your_api_key"
$ zipline ingest -b quandl
I had the same problem
so instead of
>> set QUANDL_API_KEY=<yourapikey>I tried this
>> setx QUANDL_API_KEY <yourapikey>
>> zipline ingest -b quandlproblem solved 馃憤
After setting the env I had to restart my win machine to get it working
Had the same issue. The above mentioned method somehow didn't work.
I manually edited in file "..\site-packages\ziplinedata\bundles\quandl.py":
from# api_key = environ.get('QUANDL_API_KEY')
toapi_key = 'XXXXXXXXX'
then it's working.
Hope there's a neat solution coming up soon.
This was the only way for making it work for me. Thank you!
Hello, I have IOS and Anaconda, in my terminal I wrote:
set `QUANDL_API_KEY=yourkeywithoutspacesorcommas
and:
zipline ingest -b quandl
in my terminal I wait for the procedure reading
[2020-11-03 09:23:52.692797] INFO: zipline.data.bundles.quandl: Downloading WIKI metadata.
Downloading WIKI Prices table from Quandl [------------------------------------
Downloading WIKI Prices table from Quandl [####################################] 100%
[2020-11-03 09:27:21.650509] INFO: zipline.data.bundles.quandl: Parsing raw data.
[2020-11-03 09:27:58.401093] INFO: zipline.data.bundles.quandl: Generating asset metadata.
Merging daily equity files: [#-----------------------------------] 1731/opt/an
but at the end if I try to run the jupiter notebook "first backtest":
# This ensures that our graphs will be shown properly in the notebook.
%matplotlib inline
# Import Zipline functions that we need
from zipline import run_algorithm
from zipline.api import order_target_percent, symbol
# Import date and time zone libraries
from datetime import datetime
import pytz
# Import visualization
import matplotlib.pyplot as plt
def initialize(context):
# Which stock to trade
context.stock = symbol('AAPL')
# Moving average window
context.index_average_window = 100
def handle_data(context, data):
# Request history for the stock
equities_hist = data.history(context.stock, "close",
context.index_average_window, "1d")
# Check if price is above moving average
if equities_hist[-1] > equities_hist.mean():
stock_weight = 1.0
else:
stock_weight = 0.0
# Place order
order_target_percent(context.stock, stock_weight)
def analyze(context, perf):
fig = plt.figure(figsize=(12, 8))
# First chart
ax = fig.add_subplot(311)
ax.set_title('Strategy Results')
ax.semilogy(perf['portfolio_value'], linestyle='-',
label='Equity Curve', linewidth=3.0)
ax.legend()
ax.grid(False)
# Second chart
ax = fig.add_subplot(312)
ax.plot(perf['gross_leverage'],
label='Exposure', linestyle='-', linewidth=1.0)
ax.legend()
ax.grid(True)
# Third chart
ax = fig.add_subplot(313)
ax.plot(perf['returns'], label='Returns', linestyle='-.', linewidth=1.0)
ax.legend()
ax.grid(True)
# Set start and end date
start_date = datetime(1996, 1, 1, tzinfo=pytz.UTC)
end_date = datetime(2018, 12, 31, tzinfo=pytz.UTC)
# Fire off the backtest
results = run_algorithm(
start=start_date,
end=end_date,
initialize=initialize,
analyze=analyze,
handle_data=handle_data,
capital_base=10000,
data_frequency = 'daily', bundle='quandl'
)
I receive this trivial error:

How can I do?
Most helpful comment
For Mac users, this work:
$ export QUANDL_API_KEY="your_api_key"
$ zipline ingest -b quandl