Skip to content

Commit

Permalink
Merge b2640da into 47b5f50
Browse files Browse the repository at this point in the history
  • Loading branch information
richafrank committed Sep 3, 2020
2 parents 47b5f50 + b2640da commit c36526a
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 69 deletions.
20 changes: 9 additions & 11 deletions docs/source/beginner-tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Quantopian docs <https://www.quantopian.com/help#api-toplevel>`__.
My First Algorithm
~~~~~~~~~~~~~~~~~~

Lets take a look at a very simple algorithm from the ``examples``
Let's take a look at a very simple algorithm from the ``examples``
directory, ``buyapple.py``:

.. code-block:: python
Expand Down Expand Up @@ -101,15 +101,15 @@ interfaces: A command-line interface, ``IPython Notebook`` magic, and

Ingesting Data
^^^^^^^^^^^^^^
If you haven't ingested the data, you'll need a `Quandl <https://docs.quandl.com/docs#section-authentication>`__ API key to
ingest the default bundle. Then run:
If you haven't ingested the data, then run:

.. code-block:: bash
$ QUANDL_API_KEY=<yourkey> zipline ingest [-b <bundle>]
$ zipline ingest [-b <bundle>]
where ``<bundle>`` is the name of the bundle to ingest, defaulting to
``quandl``.
``quantopian-quandl``.


you can check out the :ref:`ingesting data <ingesting-data>` section for
more detail.
Expand Down Expand Up @@ -186,13 +186,11 @@ supply the command line args all the time (see the .conf files in the examples
directory).

Thus, to execute our algorithm from above and save the results to
``buyapple_out.pickle`` we would call ``zipline run`` as follows:

.. code-block:: python
``buyapple_out.pickle``, we call ``zipline run`` as follows:

zipline run -f ../../zipline/examples/buyapple.py --start 2016-1-1 --end 2018-1-1 -o buyapple_out.pickle
--no-benchmark
.. code-block:: bash
zipline run -f ../zipline/examples/buyapple.py --start 2016-1-1 --end 2018-1-1 -o buyapple_out.pickle --no-benchmark
.. parsed-literal::
Expand All @@ -217,7 +215,7 @@ slippage model that ``zipline`` uses, see the `Quantopian
docs <https://www.quantopian.com/help#ide-slippage>`__ for more
information).

Lets take a quick look at the performance ``DataFrame``. For this, we
Let's take a quick look at the performance ``DataFrame``. For this, we
use ``pandas`` from inside the IPython Notebook and print the first ten
rows. Note that ``zipline`` makes heavy usage of ``pandas``, especially
for data input and outputting so it's worth spending some time to learn
Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@

# General information about the project.
project = u'Zipline'
copyright = u'2016, Quantopian Inc.'
copyright = u'2020, Quantopian Inc.'

# The full version, including alpha/beta/rc tags, but excluding the commit hash
release = version.split('+', 1)[0]
version = release = version.split('+', 1)[0]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down Expand Up @@ -72,7 +72,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['.static']
html_static_path = []

# If false, no index is generated.
html_use_index = True
Expand Down
2 changes: 2 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. title:: Zipline

.. include:: ../../README.rst

.. toctree::
Expand Down
2 changes: 1 addition & 1 deletion docs/source/risk-and-perf-metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ helpful to skip these computations to speed up the debugging cycle. To disable
the calculation and reporting of all metrics, users may select the built-in
metrics set ``none``. For example:

.. code-block:: python
.. code-block:: bash
$ zipline run algorithm.py -s 2014-01-01 -e 2014-02-01 --metrics-set none
Expand Down
2 changes: 1 addition & 1 deletion docs/source/whatsnew/1.2.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Build
- Update conda tooling and remove Python 3.4 builds (:issue:`2009`)
- Upgrade empyrical to 0.3.3 (:issue:`2014`)
- Upgrade empyrical to 0.3.4 (:issue:`2098`)
- Upgrade empyrical to 0.4.2 (:issue:`2125)
- Upgrade empyrical to 0.4.2 (:issue:`2125`)

Documentation
~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions docs/source/whatsnew/1.3.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ There are two primary ways to configure a custom blotter:
An example usage of **(2)** might look like this:

.. code-block:: python
:caption: ~/.zipline/extension.py
:name: ~/.zipline/extension.py

from zipline.extensions import register
Expand Down
7 changes: 3 additions & 4 deletions docs/source/whatsnew/1.4.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This meant that simulations required an internet connection and stable APIs for

We removed the dependency on treasury curves, since they weren't actually being used anymore. And we replaced the implicit downloading of benchmark returns with explicit options:

.. code-block:: bash
.. code-block:: none

--benchmark-file The csv file that contains the benchmark
returns (date, returns columns)
Expand All @@ -36,8 +36,7 @@ New Built In Factors
````````````````````

- :class:`~zipline.pipeline.factors.PercentChange`: Calculates the percent change over the given ``window_length``. Note: Percent change is calculated as ``(new - old) / abs(old)``. (:issue:`2506`)
- :class:`~zipline.pipeline.factors.PeerCount`: Gives the number of occurrences of each distinct
category in a classifier. (:issue:`2509`)
- :class:`~zipline.pipeline.factors.PeerCount`: Gives the number of occurrences of each distinct category in a classifier. (:issue:`2509`)
- :class:`~zipline.pipeline.mixins.ConstantMixin`: A mixin for creating a Pipeline term with a constant value. (:issue:`2697`)
- :meth:`~zipline.pipeline.filters.Filter.if_else`: Allows users to create expressions that conditionally draw from the outputs of one of two terms. (:issue:`2697`)
- :meth:`~zipline.pipeline.term.ComputableTerm.fillna`: Allows users to fill missing data with either a constant value, or values from another term. (:issue:`2697`)
Expand Down Expand Up @@ -102,7 +101,7 @@ In the context of Pipeline, the domain specifies the set of assets and a corresp

For example, the following pipeline returns the latest close price and volume for all Canadian equities, every day.

.. code-block:: Python
.. code-block:: python

pipe = Pipeline(
columns={
Expand Down
1 change: 1 addition & 0 deletions etc/requirements_docs.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Sphinx>=1.3.2
numpydoc>=0.5.0
sphinx-autobuild>=0.6.0
sphinx-rtd-theme
42 changes: 9 additions & 33 deletions etc/requirements_locked.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,104 +2,80 @@
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --no-index --output-file=etc/requirements_locked.txt etc/requirements.in etc/requirements_blaze.in etc/requirements_build.in etc/requirements_dev.in etc/requirements_docs.in etc/requirements_talib.in
# pip-compile --no-emit-index-url --output-file=etc/requirements_locked.txt etc/requirements.in etc/requirements_blaze.in etc/requirements_build.in etc/requirements_dev.in etc/requirements_talib.in
#
-e git+git://github.com/quantopian/blaze.git@f26375a6708eab85b7acc7869d6c518df2f974eb#egg=blaze # via -r etc/requirements_blaze.in
-e git+git://github.com/quantopian/datashape.git@cae16a85406ca4302ff1f985b74a3809be0a83a1#egg=datashape # via -r etc/requirements_blaze.in, odo
-e git+git://github.com/quantopian/odo.git@ba84238eb8dbcac4784ae7ebf62988d7e163c283#egg=odo # via -r etc/requirements_blaze.in, blaze
alabaster==0.7.12 # via sphinx
alembic==0.7.7 # via -r etc/requirements.in
argh==0.26.2 # via sphinx-autobuild, watchdog
babel==2.6.0 # via sphinx
backports-abc==0.5 # via tornado
bcolz==1.2.1 # via -r etc/requirements.in
bottleneck==1.0.0 # via -r etc/requirements.in
certifi==2018.8.24 # via requests
chardet==3.0.4 # via requests
click==7.0.0 # via -r etc/requirements.in, flask, pip-tools
cloudpickle==0.2.1 # via dask
configparser==3.5.0 # via flake8
contextlib2==0.4.0 ; python_version < "3.0" # via -r etc/requirements.in, blaze
cookies==2.2.1 # via responses
coverage==4.0.3 # via -r etc/requirements_dev.in
cycler==0.10.0 # via matplotlib
cython==0.25.2 # via -r etc/requirements_build.in
cytoolz==0.8.2 # via -r etc/requirements_blaze.in
dask[dataframe]==0.13.0 # via -r etc/requirements_blaze.in, blaze, odo
decorator==4.0.0 # via networkx
docutils==0.14 # via sphinx
empyrical==0.5.3 # via -r etc/requirements.in
enum34==1.1.6 # via flake8
flake8==3.6.0 # via -r etc/requirements_dev.in
flask-cors==2.1.3 # via blaze
flask==1.1.1 # via blaze, flask-cors
funcsigs==1.0.2 # via mock, python-interface
futures==3.2.0 # via tornado
h5py==2.7.1 # via -r etc/requirements.in
idna==2.7 # via requests
intervaltree==2.1.0 # via -r etc/requirements.in
iso3166==0.9 # via -r etc/requirements.in
iso4217==1.6.20180829 # via -r etc/requirements.in
itsdangerous==0.24 # via flask
jinja2==2.10.1 # via flask, sphinx
livereload==2.6.0 # via sphinx-autobuild
jinja2==2.10.1 # via flask
locket==0.2.0 # via partd
logbook==0.12.5 # via -r etc/requirements.in
lru-dict==1.1.4 # via -r etc/requirements.in, trading-calendars
mako==1.0.1 # via alembic
markupsafe==0.23 # via jinja2, mako
matplotlib==1.5.3 # via -r etc/requirements_dev.in
mccabe==0.6.0 # via flake8
mock==2.0.0 # via -r etc/requirements_dev.in, responses
mock==2.0.0 # via -r etc/requirements_dev.in
multipledispatch==0.6.0 # via -r etc/requirements.in, datashape, odo
networkx==1.9.1 # via -r etc/requirements.in, odo
nose-ignore-docstring==0.2 # via -r etc/requirements_dev.in
nose-parameterized==0.5.0 # via -r etc/requirements_dev.in
nose-timer==0.5.0 # via -r etc/requirements_dev.in
nose==1.3.7 # via -r etc/requirements_dev.in, nose-timer
numexpr==2.6.1 # via -r etc/requirements.in, tables
numpy==1.11.3 # via -r etc/requirements.in, -r etc/requirements_build.in, bcolz, bottleneck, dask, datashape, empyrical, h5py, matplotlib, numexpr, odo, pandas, patsy, scipy, tables, trading-calendars
numpydoc==0.5.0 # via -r etc/requirements_docs.in
numpy==1.11.3 # via -r etc/requirements.in, -r etc/requirements_build.in, bcolz, bottleneck, dask, datashape, empyrical, h5py, matplotlib, numexpr, odo, pandas, patsy, scipy, statsmodels, tables, trading-calendars
pandas-datareader==0.2.1 # via -r etc/requirements.in, empyrical
pandas==0.18.1 # via -r etc/requirements.in, dask, empyrical, odo, pandas-datareader, trading-calendars
pandas==0.18.1 # via -r etc/requirements.in, dask, empyrical, odo, pandas-datareader, statsmodels, trading-calendars
partd==0.3.7 # via dask
pathtools==0.1.2 # via sphinx-autobuild, watchdog
patsy==0.4.0 # via -r etc/requirements.in
patsy==0.4.0 # via -r etc/requirements.in, statsmodels
pbr==4.3.0 # via mock
pip-tools==5.3.1 # via -r etc/requirements_dev.in
port-for==0.3.1 # via sphinx-autobuild
psutil==5.6.7 # via blaze
pycodestyle==2.4.0 # via flake8
pyflakes==2.0.0 # via flake8
pygments==2.2.0 # via sphinx
pyparsing==2.0.3 # via matplotlib
python-dateutil==2.4.2 # via datashape, matplotlib, pandas
python-interface==1.5.3 # via -r etc/requirements.in
pytz==2018.5 # via -r etc/requirements.in, babel, matplotlib, pandas, trading-calendars
pyyaml==3.13 # via sphinx-autobuild, watchdog
pytz==2018.5 # via -r etc/requirements.in, matplotlib, pandas, trading-calendars
requests-file==1.4.1 # via pandas-datareader
requests==2.20.1 # via -r etc/requirements.in, pandas-datareader, requests-file, responses
responses==0.9.0 # via -r etc/requirements_dev.in
scipy==0.17.1 # via -r etc/requirements.in, empyrical
singledispatch==3.4.0.3 # via tornado
six==1.11.0 # via -r etc/requirements.in, cycler, flask-cors, h5py, livereload, mock, multipledispatch, patsy, pip-tools, python-dateutil, python-interface, requests-file, responses, sphinx, tables
snowballstemmer==1.2.1 # via sphinx
scipy==0.17.1 # via -r etc/requirements.in, empyrical, statsmodels
six==1.11.0 # via -r etc/requirements.in, cycler, flask-cors, h5py, mock, multipledispatch, patsy, pip-tools, python-dateutil, python-interface, requests-file, responses, tables
sortedcontainers==2.1.0 # via intervaltree
sphinx-autobuild==0.6.0 # via -r etc/requirements_docs.in
sphinx-rtd-theme==0.4.2 # via sphinx
sphinx==1.3.2 # via -r etc/requirements_docs.in, sphinx-rtd-theme
sqlalchemy==1.3.11 # via -r etc/requirements.in, alembic, blaze
statsmodels==0.6.1 # via -r etc/requirements.in
ta-lib==0.4.9 # via -r etc/requirements_talib.in
tables==3.4.3 # via -r etc/requirements.in
termcolor==1.1.0 # via nose-timer
testfixtures==6.10.1 # via -r etc/requirements_dev.in
toolz==0.8.2 # via -r etc/requirements.in, blaze, cytoolz, dask, odo, partd, trading-calendars
tornado==5.1.1 # via livereload, sphinx-autobuild
trading-calendars==1.11.2 # via -r etc/requirements.in
typing==3.6.2 # via python-interface
urllib3==1.24.3 # via requests
watchdog==0.9.0 # via sphinx-autobuild
werkzeug==0.16.0 # via flask

# The following packages are considered to be unsafe in a requirements file:
Expand Down
5 changes: 3 additions & 2 deletions etc/requirements_py36_locked.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --no-index --output-file=etc/requirements_py36_locked.txt etc/requirements.in etc/requirements_blaze.in etc/requirements_build.in etc/requirements_dev.in etc/requirements_docs.in etc/requirements_talib.in
# pip-compile --no-emit-index-url --output-file=etc/requirements_py36_locked.txt etc/requirements.in etc/requirements_blaze.in etc/requirements_build.in etc/requirements_dev.in etc/requirements_docs.in etc/requirements_talib.in
#
-e git+git://github.com/quantopian/blaze.git@f26375a6708eab85b7acc7869d6c518df2f974eb#egg=blaze # via -r etc/requirements_blaze.in
-e git+git://github.com/quantopian/datashape.git@cae16a85406ca4302ff1f985b74a3809be0a83a1#egg=datashape # via -r etc/requirements_blaze.in, odo
Expand Down Expand Up @@ -83,7 +83,8 @@ six==1.15.0 # via -r etc/requirements.in, cycler, flask-cors, h5py
snowballstemmer==2.0.0 # via sphinx
sortedcontainers==2.2.2 # via intervaltree
sphinx-autobuild==0.7.1 # via -r etc/requirements_docs.in
sphinx==3.1.2 # via -r etc/requirements_docs.in, numpydoc
sphinx-rtd-theme==0.5.0 # via -r etc/requirements_docs.in
sphinx==3.1.2 # via -r etc/requirements_docs.in, numpydoc, sphinx-rtd-theme
sphinxcontrib-applehelp==1.0.2 # via sphinx
sphinxcontrib-devhelp==1.0.2 # via sphinx
sphinxcontrib-htmlhelp==1.0.3 # via sphinx
Expand Down
18 changes: 7 additions & 11 deletions zipline/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def _(*args, **kwargs):
return d


DEFAULT_BUNDLE = 'quantopian-quandl'


@main.command()
@click.option(
'-f',
Expand Down Expand Up @@ -151,7 +154,7 @@ def _(*args, **kwargs):
@click.option(
'-b',
'--bundle',
default='quantopian-quandl',
default=DEFAULT_BUNDLE,
metavar='BUNDLE-NAME',
show_default=True,
help='The data bundle to use for the simulation.',
Expand Down Expand Up @@ -293,7 +296,7 @@ def run(ctx,
benchmark_file=benchmark_file,
)

perf = _run(
return _run(
initialize=None,
handle_data=None,
before_trading_start=None,
Expand All @@ -317,13 +320,6 @@ def run(ctx,
benchmark_spec=benchmark_spec,
)

if output == '-':
click.echo(str(perf))
elif output != os.devnull: # make the zipline magic not write any data
perf.to_pickle(output)

return perf


def zipline_magic(line, cell=None):
"""The zipline IPython cell magic.
Expand Down Expand Up @@ -362,7 +358,7 @@ def zipline_magic(line, cell=None):
@click.option(
'-b',
'--bundle',
default='quandl',
default=DEFAULT_BUNDLE,
metavar='BUNDLE-NAME',
show_default=True,
help='The data bundle to ingest.',
Expand Down Expand Up @@ -394,7 +390,7 @@ def ingest(bundle, assets_version, show_progress):
@click.option(
'-b',
'--bundle',
default='quandl',
default=DEFAULT_BUNDLE,
metavar='BUNDLE-NAME',
show_default=True,
help='The data bundle to clean.',
Expand Down
2 changes: 1 addition & 1 deletion zipline/assets/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ def lookup_symbol(self,
----------
symbol : str
The ticker symbol to resolve.
as_of_date : datetime or None
as_of_date : datetime.datetime or None
Look up the last owner of this symbol as of this datetime.
If ``as_of_date`` is None, then this can only resolve the equity
if exactly one equity has ever owned the ticker.
Expand Down
8 changes: 6 additions & 2 deletions zipline/data/bundles/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ class BadClean(click.ClickException, ValueError):
"""
def __init__(self, before, after, keep_last):
super(BadClean, self).__init__(
'Cannot pass a combination of `before` and `after` with'
'`keep_last`. Got: before=%r, after=%r, keep_n=%r\n' % (
'Cannot pass a combination of `before` and `after` with '
'`keep_last`. Must pass one. '
'Got: before=%r, after=%r, keep_last=%r\n' % (
before,
after,
keep_last,
Expand Down Expand Up @@ -578,6 +579,9 @@ def clean(name,
if e.errno != errno.ENOENT:
raise
raise UnknownBundle(name)

if before is after is keep_last is None:
raise BadClean(before, after, keep_last)
if ((before is not None or after is not None) and
keep_last is not None):
raise BadClean(before, after, keep_last)
Expand Down

0 comments on commit c36526a

Please sign in to comment.