From 2f7cd978524f36012a0ddfdf8af068cbe5ad0838 Mon Sep 17 00:00:00 2001 From: Victor Grau Serrat Date: Fri, 20 Oct 2017 15:37:04 -0600 Subject: [PATCH] DOC: WIP fix tutorial --- docs/source/beginner-tutorial.rst | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/source/beginner-tutorial.rst b/docs/source/beginner-tutorial.rst index a19374ee..6b68f7db 100644 --- a/docs/source/beginner-tutorial.rst +++ b/docs/source/beginner-tutorial.rst @@ -429,6 +429,10 @@ and allows us to plot the price of bitcoin. For example, we could easily examine now how our portfolio value changed over time compared to the bitcoin price. +.. code-block:: python + + %load_ext catalyst + .. code-block:: python %pylab inline @@ -484,7 +488,8 @@ a function we use in the ``handle_data()`` section: .. code-block:: python - %%catalyst --start 2016-1-1 --end 2017-9-30 -x bitfinex -o dma.pickle + %%catalyst --start 2016-4-1 --end 2017-9-30 -x bitfinex + from catalyst.api import order, record, symbol, order_target def initialize(context): @@ -492,16 +497,16 @@ a function we use in the ``handle_data()`` section: context.asset = symbol('btc_usd') def handle_data(context, data): - # Skip first 300 days to get full windows + # Skip first 150 days to get full windows context.i += 1 - if context.i < 300: + if context.i < 150: return # Compute averages # data.history() has to be called with the same params # from above and returns a pandas dataframe. - short_mavg = data.history(context.asset, 'price', bar_count=100, frequency="1d").mean() - long_mavg = data.history(context.asset, 'price', bar_count=300, frequency="1d").mean() + short_mavg = data.history(context.asset, 'price', bar_count=50, frequency="1d").mean() + long_mavg = data.history(context.asset, 'price', bar_count=150, frequency="1d").mean() # Trading logic if short_mavg > long_mavg: @@ -518,7 +523,7 @@ a function we use in the ``handle_data()`` section: def analyze(context, perf): import matplotlib.pyplot as plt - fig = plt.figure() + fig = plt.figure(figsize=(12,12)) ax1 = fig.add_subplot(211) perf.portfolio_value.plot(ax=ax1) ax1.set_ylabel('portfolio value in $')