Skip to content

Commit

Permalink
DOC: updating docs (#208)
Browse files Browse the repository at this point in the history
    Update installation instructions
    Address some sphinx errors
    Update badges
  • Loading branch information
stefan-jansen authored Jul 17, 2023
1 parent e3f6118 commit 206888c
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 75 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

# Backtest your Trading Strategies

| Version Info | [![Python](https://img.shields.io/pypi/pyversions/zipline-reloaded.svg?cacheSeconds=2592000)](https://pypi.python.org/pypi/zipline-reloaded) [![Anaconda-Server Badge](https://anaconda.org/ml4t/zipline-reloaded/badges/platforms.svg)](https://anaconda.org/ml4t/zipline-reloaded) [![Release](https://img.shields.io/pypi/v/zipline-reloaded.svg?cacheSeconds=2592000)](https://pypi.org/project/zipline-reloaded/) [![Anaconda-Server Badge](https://anaconda.org/ml4t/zipline-reloaded/badges/version.svg)](https://anaconda.org/ml4t/zipline-reloaded) |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Test** **Status** | [![CI Tests](https://github.com/stefan-jansen/zipline-reloaded/actions/workflows/ci_tests_full.yml/badge.svg)](https://github.com/stefan-jansen/zipline-reloaded/actions/workflows/unit_tests.yml) [![PyPI](https://github.com/stefan-jansen/zipline-reloaded/actions/workflows/build_wheels.yml/badge.svg)](https://github.com/stefan-jansen/zipline-reloaded/actions/workflows/build_wheels.yml) [![Anaconda](https://github.com/stefan-jansen/zipline-reloaded/actions/workflows/conda_package.yml/badge.svg)](https://github.com/stefan-jansen/zipline-reloaded/actions/workflows/conda_package.yml) [![codecov](https://codecov.io/gh/stefan-jansen/zipline-reloaded/branch/main/graph/badge.svg)](https://codecov.io/gh/stefan-jansen/zipline-reloaded) |
| **Community** | [![Discourse](https://img.shields.io/discourse/topics?server=https%3A%2F%2Fexchange.ml4trading.io%2F)](https://exchange.ml4trading.io) [![ML4T](https://img.shields.io/badge/Powered%20by-ML4Trading-blue)](https://ml4trading.io) [![Twitter](https://img.shields.io/twitter/follow/ml4trading.svg?style=social)](https://twitter.com/ml4trading) |
| Version Info | [![Python](https://img.shields.io/pypi/pyversions/zipline-reloaded.svg?cacheSeconds=2592000)](https://pypi.python.org/pypi/zipline-reloaded) [![Anaconda-Server Badge](https://anaconda.org/ml4t/zipline-reloaded/badges/platforms.svg)](https://anaconda.org/ml4t/zipline-reloaded) ![PyPI](https://img.shields.io/pypi/v/zipline-reloaded) [![Anaconda-Server Badge](https://anaconda.org/conda-forge/zipline-reloaded/badges/version.svg)](https://anaconda.org/conda-forge/zipline-reloaded) |
| ------------------- | ---------- |
| **Test** **Status** | [![CI Tests](https://github.com/stefan-jansen/zipline-reloaded/actions/workflows/ci_tests_full.yml/badge.svg)](https://github.com/stefan-jansen/zipline-reloaded/actions/workflows/unit_tests.yml) [![PyPI](https://github.com/stefan-jansen/zipline-reloaded/actions/workflows/build_wheels.yml/badge.svg)](https://github.com/stefan-jansen/zipline-reloaded/actions/workflows/build_wheels.yml) [![codecov](https://codecov.io/gh/stefan-jansen/zipline-reloaded/branch/main/graph/badge.svg)](https://codecov.io/gh/stefan-jansen/zipline-reloaded) |
| **Community** | [![Discourse](https://img.shields.io/discourse/topics?server=https%3A%2F%2Fexchange.ml4trading.io%2F)](https://exchange.ml4trading.io) [![ML4T](https://img.shields.io/badge/Powered%20by-ML4Trading-blue)](https://ml4trading.io) [![Twitter](https://img.shields.io/twitter/follow/ml4trading.svg?style=social)](https://twitter.com/ml4trading) |

Zipline is a Pythonic event-driven system for backtesting, developed and used as the backtesting and live-trading engine by [crowd-sourced investment fund Quantopian](https://www.bizjournals.com/boston/news/2020/11/10/quantopian-shuts-down-cofounders-head-elsewhere.html). Since it closed late 2020, the domain that had hosted these docs expired. The library is used extensively in the book [Machine Larning for Algorithmic Trading](https://ml4trading.io)
by [Stefan Jansen](https://www.linkedin.com/in/applied-ai/) who is trying to keep the library up to date and available to his readers and the wider Python algotrading community.

- [Join our Community!](https://exchange.ml4trading.io)
- [Documentation](https://zipline.ml4trading.io)

Expand Down
2 changes: 1 addition & 1 deletion docs/source/api-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ Data Loaders
There are several loaders to feed data to a :class:`~zipline.pipeline.Pipeline` that need to implement the interface
defined by the :class:`~zipline.pipeline.loaders.base.PipelineLoader`.

.. autoclass:: zipline.pipeline.loaders.based.PipelineLoader
.. autoclass:: zipline.pipeline.loaders.base.PipelineLoader
:members: __init__, load_adjusted_array, currency_aware
:member-order: bysource

Expand Down
9 changes: 4 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
]

extlinks = {
"issue": ("https://github.com/stefan-jansen/zipline/issues/%s", "#"),
"commit": ("https://github.com/stefan-jansen/zipline/commit/%s", ""),
"issue": ("https://github.com/stefan-jansen/zipline/issues/%s", "%s"),
"commit": ("https://github.com/stefan-jansen/zipline/commit/%s", "%s"),
}

numpydoc_show_class_members = False
Expand Down Expand Up @@ -59,7 +59,7 @@
html_theme_path = []
else:
html_theme = "pydata_sphinx_theme"
html_theme_path = pydata_sphinx_theme.get_html_theme_path()
# html_theme_path = pydata_sphinx_theme.get_html_theme_path()

# The name of the Pygments (syntax highlighting) style to use.
highlight_language = "python"
Expand All @@ -79,7 +79,6 @@
"google_analytics_id": "UA-74956955-3",
}


# 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'.
Expand All @@ -98,7 +97,7 @@
htmlhelp_basename = "ziplinedoc"

intersphinx_mapping = {
"https://docs.python.org/dev/": None,
"python": ("https://docs.python.org/3/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/reference/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
Expand Down
1 change: 1 addition & 0 deletions docs/source/development-guidelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ First, you'll need to clone Zipline by running:
Then check out to a new branch where you can make your changes:

.. code-block:: bash
$ cd zipline-reloaded
$ git checkout -b some-short-descriptive-name
Expand Down
19 changes: 4 additions & 15 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ that runs on Windows, macOS, and Linux. In case you are installing `zipline-relo
encounter [conflict errors](https://github.com/conda/conda/issues/9707), consider using
[mamba](https://github.com/mamba-org/mamba) instead.

Zipline runs on Python 3.8, 3.9 and 3.10. To install and use different Python versions in parallel as well as create
Zipline runs on Python 3.8, 3.9, 3.10 and 3.11. To install and use different Python versions in parallel as well as create
a virtual environment, you may want to use `pyenv <https://github.com/pyenv/pyenv>`_.

Installing with ``pip``
Expand Down Expand Up @@ -144,21 +144,10 @@ dependencies.
For instructions on how to install ``conda``, see the `Conda Installation
Documentation <https://conda.io/projects/conda/en/latest/user-guide/install/index.html>`_.

Unfortunately, as of April 2021, ``conda`` produces numerous false
positive [conflict errors](https://github.com/conda/conda/issues/9707)
while working to identify dependencies. Should this be your experience, consider
[mamba](https://github.com/mamba-org/mamba) instead, which works much faster and
reliably in most cases.
Once ``conda`` has been set up you can install Zipline from the ``conda-forge`` channel.

Once ``conda`` has been set up you can install Zipline from the ``ml4t`` channel.
You'll also need to activate the `conda-forge` and `ranaroussi` channels to source various dependencies.
You can do so either by adding them to your
`.condarc <https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html>`_
configuration file, or as command line flags:
See [here](https://github.com/conda-forge/zipline-reloaded-feedstock) for the latest installation details.

.. code-block:: bash
conda install -c ml4t -c conda-forge -c ranaroussi zipline-reloaded

.. _managing-conda-environments:

Expand All @@ -174,7 +163,7 @@ Assuming ``conda`` has been set up, you can create a ``conda`` environment:

.. code-block:: bash
$ conda create -n env_zipline python=3.8
$ conda create -n env_zipline python=3.10
Now you have set up an isolated environment called ``env_zipline``, a sandbox-like
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ docs = [
'numpydoc >=0.5.0',
'sphinx-autobuild >=0.6.0',
'pydata-sphinx-theme',
'sphinx-markdown-tables',
'sphinx_markdown_tables',
'm2r2'

]
Expand Down
14 changes: 8 additions & 6 deletions src/zipline/_protocol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ cdef class BarData:
})

cdef bool _is_stale_for_asset(self, asset, dt, adjusted_dt, data_portal):
session_label = dt.normalize() # FIXME
session_label = dt.normalize() # FIXME

if not asset.is_alive_for_session(session_label):
return False
Expand Down Expand Up @@ -580,11 +580,13 @@ cdef class BarData:
:class:`pd.DatetimeIndex`, and its columns will be ``assets``.
- If multiple assets and multiple fields are requested, the returned
value is a :class:`pd.DataFrame` with a pd.MultiIndex containing pairs of
:class:`pd.DatetimeIndex`, and ``assets``, while the columns while contain the field(s).
It has shape``(bar_count * len(assets), len(fields))``. The names of the pd.MultiIndex are
- ``date`` if frequency == '1d'`` or ``date_time`` if frequency == '1m``, and
- ``asset``
value is a :class:`pd.DataFrame` with a pd.MultiIndex containing
pairs of :class:`pd.DatetimeIndex`, and ``assets``, while the columns
while contain the field(s). It has shape ``(bar_count * len(assets),
len(fields))``. The names of the pd.MultiIndex are
- ``date`` if frequency == '1d'`` or ``date_time`` if frequency == '1m``, and
- ``asset``
If the current simulation time is not a valid market time, we use the last market close instead.
"""
Expand Down
46 changes: 24 additions & 22 deletions src/zipline/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,28 +717,30 @@ def get_environment(self, field="platform"):
Parameters
----------
field : {'platform', 'arena', 'data_frequency',
'start', 'end', 'capital_base', 'platform', '*'}
The field to query. The options have the following meanings:
arena : str
The arena from the simulation parameters. This will normally
be ``'backtest'`` but some systems may use this distinguish
live trading from backtesting.
data_frequency : {'daily', 'minute'}
data_frequency tells the algorithm if it is running with
daily data or minute data.
start : datetime
The start date for the simulation.
end : datetime
The end date for the simulation.
capital_base : float
The starting capital for the simulation.
platform : str
The platform that the code is running on. By default this
will be the string 'zipline'. This can allow algorithms to
know if they are running on the Quantopian platform instead.
* : dict[str -> any]
Returns all of the fields in a dictionary.
field : {'platform', 'arena', 'data_frequency', 'start', 'end',
'capital_base', 'platform', '*'}
The field to query. The options have the following meanings:
- arena : str
The arena from the simulation parameters. This will normally
be ``'backtest'`` but some systems may use this distinguish
live trading from backtesting.
- data_frequency : {'daily', 'minute'}
data_frequency tells the algorithm if it is running with
daily data or minute data.
- start : datetime
The start date for the simulation.
- end : datetime
The end date for the simulation.
- capital_base : float
The starting capital for the simulation.
-platform : str
The platform that the code is running on. By default, this
will be the string 'zipline'. This can allow algorithms to
know if they are running on the Quantopian platform instead.
- * : dict[str -> any]
Returns all the fields in a dictionary.
Returns
-------
Expand Down
14 changes: 7 additions & 7 deletions src/zipline/finance/blotter/blotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def order(self, asset, amount, style, order_id=None):
Notes
-----
amount > 0 :: Buy/Cover
amount < 0 :: Sell/Short
Market order: order(asset, amount)
Limit order: order(asset, amount, style=LimitOrder(limit_price))
Stop order: order(asset, amount, style=StopOrder(stop_price))
StopLimit order: order(asset, amount, style=StopLimitOrder(limit_price,
stop_price))
amount > 0 : Buy/Cover
amount < 0 : Sell/Short
Market order : order(asset, amount)
Limit order : order(asset, amount, style=LimitOrder(limit_price))
Stop order : order(asset, amount, style=StopOrder(stop_price))
StopLimit order : order(asset, amount,
style=StopLimitOrder(limit_price, stop_price))
"""

raise NotImplementedError("order")
Expand Down
2 changes: 1 addition & 1 deletion src/zipline/finance/blotter/simulation_blotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def order(self, asset, amount, style, order_id=None):
Limit order: order(asset, amount, style=LimitOrder(limit_price))
Stop order: order(asset, amount, style=StopOrder(stop_price))
StopLimit order: order(asset, amount, style=StopLimitOrder(limit_price,
stop_price))
stop_price))
"""
# something could be done with amount to further divide
# between buy by share count OR buy shares up to a dollar amount
Expand Down
6 changes: 2 additions & 4 deletions src/zipline/pipeline/loaders/earnings_estimates.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,13 @@ class EarningsEstimatesLoader(implements(PipelineLoader)):
Parameters
----------
estimates : pd.DataFrame
The raw estimates data.
``estimates`` must contain at least 5 columns:
The raw estimates data; must contain at least 5 columns:
sid : int64
The asset id associated with each estimate.
event_date : datetime64[ns]
The date on which the event that the estimate is for will/has
occurred..
occurred.
timestamp : datetime64[ns]
The datetime where we learned about the estimate.
Expand Down Expand Up @@ -1266,7 +1265,6 @@ def _collect_adjustments(
post_adjustments,
requested_split_adjusted_columns,
):

pre_adjustments_dict = self.collect_pre_split_asof_date_adjustments(
split_adjusted_asof_idx,
sid_idx,
Expand Down
16 changes: 8 additions & 8 deletions src/zipline/pipeline/loaders/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ def format_adjustments(self, dates, assets):
Returns a dict of the form:
{
# Integer index into `dates` for the date on which we should
# apply the list of adjustments.
1 : [
Float64Multiply(first_row=2, last_row=4, col=3, value=0.5),
Float64Overwrite(first_row=3, last_row=5, col=1, value=2.0),
...
],
...
# Integer index into `dates` for the date on which we should
# apply the list of adjustments.
1 : [
Float64Multiply(first_row=2, last_row=4, col=3, value=0.5),
Float64Overwrite(first_row=3, last_row=5, col=1, value=2.0),
...
],
...
}
"""
make_adjustment = partial(make_adjustment_from_labels, dates, assets)
Expand Down

0 comments on commit 206888c

Please sign in to comment.