Files
catalyst/tests/resources/yahoo_samples/rebuild_samples
T
Joe Jevnik 59c8e371a2 ENH: Updates the cli, data bundles and extensions.
Adds the data bundle concept which makes it easy for users to register
loading functions to build out minute and daily data along with an
assets db and adjustments db. By default we have provided a `quandl`
bundle which pulls from the public domain WIKI dataset. Users may
register new bundles by decorating an ingest function with
`zipline.data.bundles.register(<name>)`. This also provides a
`yahoo_equities` function for creating an ingestion function that will
load a static set of assets from yahoo.

The cli is now structured as a couple of subcommands and has been
changed to `python -m zipline`. The old behavior of `run_algo.py` has
been moved to the `run` subcommand. This is almost entirely the same
except that it now takes the name of the data bundle to use, defaulting
to `quandl`.

The next subcommand is `ingest` which takes the name of
a data bundle to ingest. This will run the loading machinery and write
the data to a specified location that `run` can find.

There is also a `clean` subcommand which deletes the data that was
written with `ingest`.

Extensions have also been added to zipline. This is an experimental
feature where users can provide an extra set of python files to run at
the start of the process. These can be used to configure aspects of
zipline. Right now the only thing that is supported in an extension file
is the registration of a new data bundle.
2016-05-03 18:38:24 -04:00

80 lines
1.9 KiB
Python

#!/usr/bin/env python
"""
Script for rebuilding the samples for the Yahoo tests.
"""
from textwrap import dedent
import numpy as np
import pandas as pd
from zipline.testing import test_resource_path, write_compressed
from zipline.utils.tradingcalendar import trading_days
def zipfile_path(symbol, ext):
return test_resource_path('yahoo_samples', symbol + ext + '.gz')
def pricing_for_sid(sid):
modifier = {
'Low': 0,
'Open': 1,
'Close': 2,
'High': 3,
'Volume': 0,
}
def column(name):
return np.arange(252) + 1 + sid * 10000 + modifier[name] * 1000
return pd.DataFrame(
data={
'Date': trading_days[
(trading_days >= pd.Timestamp('2014')) &
(trading_days < pd.Timestamp('2015'))
],
'Open': column('Open'),
'High': column('High'),
'Low': column('Low'),
'Close': column('Close'),
'Volume': column('Volume'),
'Adj Close': 0,
},
columns=[
'Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close',
],
).to_csv(index=False, date_format='%Y-%m-%d').encode('ascii')
def adjustments_for_sid(sid):
"""This is not exactly a csv... thanks yahoo.
"""
return dedent(
"""\
Date,Dividends
DIVIDEND, 20140403,0.{p1}00000
SPLIT, 20140703,{p2}:1
DIVIDEND, 20141002,0.{p2}00000
STARTDATE, 20140102
ENDDATE, 20141231
TOTALSIZE, 2
""".format(p1=sid + 1, p2=sid + 2),
).encode('ascii')
def main():
symbols = 'AAPL', 'IBM', 'MSFT'
for sid, symbol in enumerate(symbols):
write_compressed(
zipfile_path(symbol, '.csv'),
pricing_for_sid(sid),
)
write_compressed(
zipfile_path(symbol, '.adjustments'),
adjustments_for_sid(sid),
)
if __name__ == '__main__':
main()