diff --git a/docs/contributing.rst b/docs/contributing.rst new file mode 100644 index 00000000..d60d5af0 --- /dev/null +++ b/docs/contributing.rst @@ -0,0 +1,40 @@ +*************************** +Contributing to the project +*************************** + +Style Guide +=========== + +To ensure that changes and patches are focused on behavior changes, +the zipline codebase adheres to PEP-8, +``_. + +The maintainers check the code using the flake8 script, +``_, which is included in the +requirements_dev.txt. + +Before submitting patches or pull requests, please ensure that your +changes pass + +:: + + flake8 --ignore=E124,E125,E126 zipline tests + +Discussion and Help +=================== + +Discussion of the project is held at the Google Group, +``_, +``_. + +Source +====== + +The source for Zipline is hosted at +``_. + +Contact +======= + +For other questions, please contact ``_. + diff --git a/docs/index.rst b/docs/index.rst index 8195b494..9151c79c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -5,9 +5,9 @@ .. module:: zipline -******************************************* -Zipline: The Open Source Backtesting Engine -******************************************* +**************************************************** +Zipline: Financial Backtester for Trading Algorithms +**************************************************** Python is quickly becoming the glue language which holds together data science and related fields like quantitative finance. Zipline is a new, BSD-licensed @@ -22,10 +22,27 @@ Python eco-system. Furthermore, statistic and machine learning libraries like matplotlib, scipy, statsmodels, and sklearn support development, analysis and visualization of state-of-the-art trading systems. -Zipline is currently used in production as the backtesting engine powering -``_, a free, community-centered platform that allows -development and real-time backtesting of trading algorithms in the web browser. -Zipline was released at PyData NYC'12. +Zipline is currently used in production as the backtesting engine +powering `quantopian.com `_ -- a free, community-centered +platform that allows development and real-time backtesting of trading +algorithms in the web browser. + +Features +======== + +* Ease of use: Zipline tries to get out of your way so that you can focus on + algorithm development. See below for a code example. + +* Zipline comes "batteries included" as many common statistics like moving + average and linear regression can be readily accessed from within a + user-written algorithm. + +* Input of historical data and output of performance statistics is based on + Pandas DataFrames to integrate nicely into the existing Python eco-system. + +* Statistic and machine learning libraries like matplotlib, scipy, statsmodels, + and sklearn support development, analysis and visualization of + state-of-the-art trading systems. Contents ======== @@ -35,11 +52,12 @@ Contents manifesto.rst installation.rst + quickstart.rst + contributing.rst overview.rst modules.rst extensions.rst - Indices and tables ================== diff --git a/docs/quickstart.rst b/docs/quickstart.rst new file mode 100644 index 00000000..01e77c55 --- /dev/null +++ b/docs/quickstart.rst @@ -0,0 +1,55 @@ +********** +Quickstart +********** + +Dual-Moving Average Example +=========================== + +The following code implements a simple dual moving average algorithm +and tests it on data extracted from yahoo finance. + +.. code:: python + + from zipline.algorithm import TradingAlgorithm + from zipline.transforms import MovingAverage + from zipline.utils.factory import load_from_yahoo + + class DualMovingAverage(TradingAlgorithm): + """Dual Moving Average algorithm. + """ + def initialize(self, short_window=200, long_window=400): + # Add 2 mavg transforms, one with a long window, one + # with a short window. + self.add_transform(MovingAverage, 'short_mavg', ['price'], + market_aware=True, + days=short_window) + + self.add_transform(MovingAverage, 'long_mavg', ['price'], + market_aware=True, + days=long_window) + + # To keep track of whether we invested in the stock or not + self.invested = False + + self.short_mavg = [] + self.long_mavg = [] + + + def handle_data(self, data): + if (data['AAPL'].short_mavg['price'] > data['AAPL'].long_mavg['price']) and not self.invested: + self.order('AAPL', 100) + self.invested = True + elif (data['AAPL'].short_mavg['price'] < data['AAPL'].long_mavg['price']) and self.invested: + self.order('AAPL', -100) + self.invested = False + + # Save mavgs for later analysis. + self.short_mavg.append(data['AAPL'].short_mavg['price']) + self.long_mavg.append(data['AAPL'].long_mavg['price']) + + data = load_from_yahoo() + dma = DualMovingAverage() + results = dma.run(data) + +You can find other examples in the zipline/examples directory. +