Ok I got it to run using the code below in spyder using quantopian- quandl data bundle from 2016-05-24 - also runs from command line.
FYI, tried to verify the result with Quantopian online but got a 10% difference in cumulative return. But had a better result using the old yahoo data download method, where the difference was about 1%.
import zipline
from zipline.api import order, record, symbol, set_slippage, slippage, set_commission, commission
def initialize(context):
context.asset = 'AAPL'
set_slippage(slippage.FixedSlippage(spread=0.0))
set_commission(commission.PerShare(cost=0.0075, min_trade_cost=1.0))
pass
def handle_data(context, data):
order(symbol(context.asset), int(50000/data.current(symbol(context.asset), "price")))
record(AAPL=data.current(symbol(context.asset), "price"))
# Note: this function can be removed if running
def analyze(context=None, results=None):
import matplotlib.pyplot as plt
# Plot the portfolio and asset data.
ax1 = plt.subplot(211)
results.algorithm_period_return.plot(ax=ax1)
ax1.set_ylabel('Cumulative Return (%)')
ax2 = plt.subplot(212, sharex=ax1)
results.AAPL.plot(ax=ax2)
ax2.set_ylabel('AAPL price (USD)')
# Show the plot.
plt.gcf().set_size_inches(18, 8)
plt.show()