Manual (advanced) example doesn't work in Cantopy

62 views
Skip to first unread message

Volodymyr Vovchack

unread,
May 20, 2015, 11:00:15 AM5/20/15
to zip...@googlegroups.com
I tried to run example from Zipline beginner tutorial (under Manual (advanced) topic) in Cantopy and it produced NameError: global name 'order' is not defined.

before that I run code labeled "My first algorithm" through cmd line, though i had to save it in some folder on PC. That run was successful.


Manual (advanced):
import
pytz
 
from datetime import datetime

from zipline.algorithm import TradingAlgorithm

from zipline.utils.factory import load_bars_from_yahoo
 

# Load data manually from Yahoo! finance

start
= datetime(2000, 1, 1, 0, 0, 0, 0, pytz.utc)

end = datetime(2012, 1, 1, 0, 0, 0, 0, pytz.utc)

data
= load_bars_from_yahoo(stocks=['AAPL'], start=start,  end=end)

# Define algorithm

def initialize(context):

 
pass

def handle_data(context, data):

 order
(symbol('AAPL'), 10)

 record
(AAPL=data[symbol('AAPL')].price)

# Create algorithm object passing in initialize and

# handle_data functions

algo_obj
= TradingAlgorithm(initialize=initialize,

 handle_data
=handle_data)

# Run algorithm

perf_manual
= algo_obj.run(data)


Mark Francis

unread,
Jul 6, 2015, 8:09:02 AM7/6/15
to zip...@googlegroups.com
Try adding "from zipline.api import order_target, record, history, symbol, add_history, order" to your imports at the top. That usually covers all the things I use.
Reply all
Reply to author
Forward
0 new messages