quantopian / zipline

Zipline, a Pythonic Algorithmic Trading Library
https://www.zipline.io
Apache License 2.0
17.61k stars 4.72k forks source link

How to do ingestion with QUANDL_API_KEY=<yourkey> on windows platform? #2133

Closed kelvinho8 closed 6 years ago

kelvinho8 commented 6 years ago

Dear Zipline Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

Now that you know a little about me, let me tell you about the issue I am having:

Description of Issue

I would like to replicate the quick start tutorial by running codes below:

========================== $ QUANDL_API_KEY= zipline ingest -b quandl

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:

Reproduction Steps

1. 2. 3. ...

What steps have you taken to resolve this already?

...

Anything else?

...

Sincerely, Kelvin

freddiev4 commented 6 years ago

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.

freddiev4 commented 6 years ago

IIRC, you might be able to run set QUANDL_API_KEY=<yourapikey> from the Command Prompt, and then call zipline ingest -b quandl.

kelvinho8 commented 6 years ago

Hi @freddiev4 . Thank you for your answer.

In fact, I already did what you suggested by running set QUANDL_API_KEY= from the Command Prompt, before running zipline ingest -b quandl. But it didn't make any difference than ingesting as an anonymous quandl user (with no API key) that only allows me to ingest 100 equities at a time. Any other suggestion for me?

Have a good day Kelvin

rodrigosnader commented 6 years ago

I'm having exactly the same problem here. Did you guys find any solution to work this out on windows?

yiorgosn commented 6 years ago

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.

wilsonZWS commented 6 years ago

like freddiev4 said. Input set QUANDL_API_KEY= first seperately and then call zipline ingest -b quandl

freddiev4 commented 6 years ago

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.

zash121 commented 6 years ago

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 👍

TManicom commented 6 years ago

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

mark2n commented 6 years ago

Had the same issue. The above mentioned method somehow didn't work. I manually edited in file "..\site-packages\zipline\data\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.

CJDC28 commented 5 years ago

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.

ghost commented 5 years ago

For Mac users, this work:

$ export QUANDL_API_KEY="your_api_key" $ zipline ingest -b quandl

singhvivek2503 commented 5 years ago

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 👍

After setting the env I had to restart my win machine to get it working

MattMiller-01 commented 4 years ago

Had the same issue. The above mentioned method somehow didn't work. I manually edited in file "..\site-packages\zipline\data\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.

This was the only way for making it work for me. Thank you!

stylesaler commented 3 years ago

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: Screenshot 2020-11-03 at 10 39 48

How can I do?

angelbenitezmd commented 2 years ago

This is how I made it work in python. import os os.environ['QUANDL_API_KEY'] = 'Your_API_key'

andycwang commented 2 years ago

@.***邮箱联系我,谢谢!

ari62 commented 1 year ago

Now that Quandl is gone, where do we get a Quandl API key? Will https://data.nasdaq.com/ API keys work?

ari62 commented 1 year ago

Now that Quandl is gone, where do we get a Quandl API key? Will https://data.nasdaq.com/ API keys work?

Seems like https://data.nasdaq.com/ api keys do work. On mac you can use the export command: export QUANDL_API_KEY=...

Now I am getting a different error

benwaldner commented 1 year ago

This is how I made it work in python. import os os.environ['QUANDL_API_KEY'] = 'Your_API_key'

This worked for me in Google Colab using the https://data.nasdaq.com/ API key