From eaa98802036e1a5f437263d49a8e5fb38c0809d4 Mon Sep 17 00:00:00 2001 From: Ben McCann Date: Fri, 7 Jun 2013 10:46:39 -0700 Subject: [PATCH] DOC: Reference example in quickstart to keep it up-to-date. Fix the quickstart docs by including the example so that it's always up-to-date. --- docs/quickstart.rst | 47 +++------------------------------------------ 1 file changed, 3 insertions(+), 44 deletions(-) diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 3f2cafb3..6f1d99c3 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -8,48 +8,7 @@ Dual-Moving Average Example The following code implements a simple dual moving average algorithm and tests it on data extracted from yahoo finance. -.. code-block:: 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. +.. include:: ../zipline/examples/dual_moving_average.py + :literal: +You can find other examples in `the zipline/examples directory `_.