Skip to content

Commit a014c6f

Browse files
authored
Merge pull request #101 from zipline-live/iex
Move from Google to IEX for benchmarks
2 parents 6d25653 + 8692111 commit a014c6f

File tree

11 files changed

+28
-570
lines changed

11 files changed

+28
-570
lines changed

docs/source/bundles.rst

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -153,44 +153,6 @@ Quantopian provides a mirror of the quandl WIKI dataset with the data in the
153153
formats that zipline expects. This is available under the name:
154154
``quantopian-quandl`` and is the default bundle for zipline.
155155

156-
Yahoo Bundle Factories
157-
``````````````````````
158-
159-
Zipline also ships with a factory function for creating a data bundle out of a
160-
set of tickers from yahoo: :func:`~zipline.data.bundles.yahoo_equities`.
161-
:func:`~zipline.data.bundles.yahoo_equities` makes it easy to pre-download and
162-
cache the data for a set of equities from yahoo. The yahoo bundles include daily
163-
pricing data along with splits, cash dividends, and inferred asset metadata. To
164-
create a bundle from a set of equities, add the following to your
165-
``~/.zipline/extensions.py`` file:
166-
167-
.. code-block:: python
168-
169-
from zipline.data.bundles import register, yahoo_equities
170-
171-
# these are the tickers you would like data for
172-
equities = {
173-
'AAPL',
174-
'MSFT',
175-
'GOOG',
176-
}
177-
register(
178-
'my-yahoo-equities-bundle', # name this whatever you like
179-
yahoo_equities(equities),
180-
)
181-
182-
183-
This may now be used like:
184-
185-
.. code-block:: bash
186-
187-
$ zipline ingest -b my-yahoo-equities-bundle
188-
$ zipline run -f algo.py --bundle my-yahoo-equities-bundle
189-
190-
191-
More than one yahoo equities bundle may be registered as long as they use
192-
different names.
193-
194156
Writing a New Bundle
195157
~~~~~~~~~~~~~~~~~~~~
196158

@@ -200,7 +162,7 @@ zipline. To add a new bundle, one must implement an ``ingest`` function.
200162
The ``ingest`` function is responsible for loading the data into memory and
201163
passing it to a set of writer objects provided by zipline to convert the data to
202164
zipline's internal format. The ingest function may work by downloading data from
203-
a remote location like the ``quandl`` bundle or yahoo bundles or it may just
165+
a remote location like the ``quandl`` bundle or it may just
204166
load files that are already on the machine. The function is provided with
205167
writers that will write the data to the correct location transactionally. If an
206168
ingestion fails part way through the bundle will not be written in an incomplete

tests/data/bundles/test_yahoo.py

Lines changed: 0 additions & 206 deletions
This file was deleted.

tests/resources/rebuild_example_data

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import numpy as np
99
import pandas as pd
1010

1111
from zipline import examples
12-
from zipline.data.bundles import clean, ingest, register, yahoo_equities
12+
from zipline.data.bundles import clean, ingest
1313
from zipline.testing import test_resource_path, tmp_dir
1414
from zipline.utils.cache import dataframe_cache
1515

@@ -27,14 +27,6 @@ INPUT_DATA_SYMBOLS = (
2727
'AAPL',
2828
'MSFT',
2929
)
30-
TEST_BUNDLE_NAME = 'test'
31-
input_bundle = yahoo_equities(
32-
INPUT_DATA_SYMBOLS,
33-
INPUT_DATA_START_DATE,
34-
INPUT_DATA_END_DATE,
35-
)
36-
register(TEST_BUNDLE_NAME, input_bundle)
37-
3830

3931
banner = """
4032
Please verify that the new performance is more correct than the old
@@ -83,19 +75,6 @@ def changed_results(new, old):
8375
def eof(*args, **kwargs):
8476
raise EOFError()
8577

86-
87-
def rebuild_input_data(environ):
88-
ingest(TEST_BUNDLE_NAME, environ=environ, show_progress=True)
89-
clean(TEST_BUNDLE_NAME, keep_last=1, environ=environ)
90-
91-
92-
@click.command()
93-
@click.option(
94-
'--rebuild-input',
95-
is_flag=True,
96-
default=False,
97-
help="Should we rebuild the input data from Yahoo?",
98-
)
9978
@click.pass_context
10079
def main(ctx, rebuild_input):
10180
"""Rebuild the perf data for test_examples
@@ -109,8 +88,6 @@ def main(ctx, rebuild_input):
10988
# The environ here should be the same (modulo the tempdir location)
11089
# as we use in test_examples.py.
11190
environ = {'ZIPLINE_ROOT': d.getpath('example_data/root')}
112-
if rebuild_input:
113-
rebuild_input_data(environ)
11491

11592
new_perf_path = d.getpath(
11693
'example_data/new_perf/%s' % pd.__version__.replace('.', '-'),

zipline/algorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def _create_benchmark_source(self):
548548
else:
549549
benchmark_asset = None
550550
# get benchmark info from trading environment, which defaults to
551-
# downloading data from Yahoo.
551+
# downloading data from IEX Trading.
552552
benchmark_returns = self.trading_environment.benchmark_returns
553553
return BenchmarkSource(
554554
benchmark_asset=benchmark_asset,

zipline/data/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
from . import loader
22
from .loader import (
3-
load_from_yahoo,
4-
load_bars_from_yahoo,
53
load_prices_from_csv,
64
load_prices_from_csv_folder,
75
)
86

97

108
__all__ = [
11-
'load_bars_from_yahoo',
12-
'load_from_yahoo',
139
'load_prices_from_csv',
1410
'load_prices_from_csv_folder',
1511
'loader',

zipline/data/benchmarks.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,32 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
import json
16+
import pandas as pd
17+
import requests
1518

16-
from zipline.utils.calendars import get_calendar
17-
import pandas_datareader.data as web
1819

19-
20-
def get_benchmark_returns(symbol, start_date, end_date):
20+
def get_benchmark_returns(symbol):
2121
"""
22-
Get a Series of benchmark returns from Google finance.
22+
Get a Series of benchmark returns from IEX associated with `symbol`.
23+
Default is `SPY`.
2324
24-
Returns a Series with returns from (start_date, end_date].
25+
Parameters
26+
----------
27+
symbol : str
28+
Benchmark symbol for which we're getting the returns.
2529
26-
start_date is **not** included because we need the close from day N - 1 to
27-
compute the returns for day N.
30+
The data is provided by IEX (https://iextrading.com/), and we can
31+
get up to 5 years worth of data.
2832
"""
29-
df = web.DataReader(symbol, 'google', start_date, end_date)
30-
df.index = df.index.tz_localize('UTC')
33+
r = requests.get(
34+
'https://api.iextrading.com/1.0/stock/{}/chart/5y'.format(symbol)
35+
)
36+
data = json.loads(r.text)
3137

32-
calendar = get_calendar("NYSE")
33-
start_index = calendar.all_sessions.searchsorted(start_date)
34-
end_index = calendar.all_sessions.searchsorted(end_date)
38+
df = pd.DataFrame(data)
3539

36-
# fill price data for missing dates
37-
df = df["Close"].reindex(calendar.all_sessions[start_index:end_index],
38-
method='ffill')
40+
df.index = pd.DatetimeIndex(df['date'])
41+
df = df['close']
3942

40-
return df.pct_change(1).iloc[1:]
43+
return df.sort_index().tz_localize('UTC').pct_change(1).iloc[1:]

0 commit comments

Comments
 (0)