How to manually provide a landmark in a zipline

I want to create a reproducible example where the sold series and reference are manually listed. It would make the lives of people who are approaching the zipline incredibly easier. In fact, given the recent shutdown of Yahoo! Finance API, even the introductory examples with zipline will no longer work as an HTTP error will be returned when trying to import ^ GSPC benchmark from Yahoo behind the scenes. As a consequence, there is currently no code snippet from the official tutorial that AFAIK works.

import pytz
from pandas_datareader import DataReader
from collections import OrderedDict
from zipline.algorithm import TradingAlgorithm
from zipline.api import order, record, symbol, set_benchmark
# Import data from yahoo
data = OrderedDict()
start_date = '01/01/2014'
end_date = '01/01/2017'
data['AAPL'] = DataReader('AAPL',
                          data_source='google',
                          start=start_date,
                          end=end_date)
data['SPY'] = DataReader('SPY',
                         data_source='google',
                         start=start_date,
                         end=end_date)
# panel.minor_axis is ['Open', 'High', 'Low', 'Close', 'Volume'].
panel = pd.Panel(data)
panel.major_axis = panel.major_axis.tz_localize(pytz.utc)

def initialize(context):
    set_benchmark(data['SPY'])

def handle_data(context, data):
    order(data['AAPL'], 10)
    record(AAPL=data.current(data['AAPL'], 'Close'))

algo_obj = TradingAlgorithm(initialize=initialize,
                            handle_data=handle_data,
                            capital_base=100000)
perf_manual = algo_obj.run(panel)

      

Returns: HTTPError: HTTP Error 404: Not Found

The question is : how to make the strategy work using AAPL as a traded asset and SPY as a benchmark? Restriction : AAPL and SPY must be provided manually as in the example.

+3


source to share


2 answers


Disclaimer: I support Zipline.



You can use a package csvdir

to download csv files (tutorial here ) and then make a call set_benchmark()

in your initialize()

. I'm also working on a branch that allows zipline algorithms without a test, so even if you can't get the benchmark data, your algorithm shouldn't crash.

+1


source


Replace zipline with the requirements.txt

following:

git+https://github.com/quantopian/zipline

      



Then run pip install -r requirements.txt

0


source







All Articles