Open kmeans27 opened 2 years ago
I have the same issue. I have the feeling the tutorial is not for the newest version of zipline 2.2.0. But it is just a guess.
so data[] got deprecated in 2.0 then it removed for 2.2.0 As said the doc is not updated. Here is a working version with 2.2.0:
from zipline import run_algorithm
import pandas as pd
import pandas_datareader.data as web
from zipline.assets import Equity
from zipline.api import symbol, order, record
def initialize(context):
context.i = 0
context.asset = symbol('AAPL')
def handle_data(context, data):
order(symbol('AAPL'), 1.0)
#record(AAPL=data[symbol('AAPL')].price)
record(data.current(symbol('AAPL'),"close"))
start = pd.Timestamp('2014')
end = pd.Timestamp('2018')
sp500 = web.DataReader('SP500', 'fred', start, end).SP500
benchmark_returns = sp500.pct_change()
result = run_algorithm(start=start.tz_localize('UTC'),
end=end.tz_localize('UTC'),
initialize=initialize,
handle_data=handle_data,
capital_base=100000,
benchmark_returns=benchmark_returns,
bundle='quandl',
data_frequency='daily')
Confirming that @mike576's fix:
record(data.current(symbol('AAPL'),"close"))
does work in a notebook cell.
The code in the tutorial for what to put in a notebook cell is incorrect.
record(AAPL=data[symbol('AAPL')].price)
The code in the section A simple example is the similar to @mike576's.
record(AAPL=data.current(symbol('AAPL'), 'price'))
I didn't read the tutorial carefully enough and should have compared the code in both sections.
Thanks @mike576 !
@.***邮箱联系我,谢谢!
Dear Zipline Maintainers,
Before I tell you about my issue, let me describe my environment:
Environment
name: ml4t channels:
When i try to run the basic zipline example from https://zipline.ml4trading.io/beginner-tutorial.html
%load_ext zipline
%%zipline --start 2016-1-1 --end 2018-1-1 -o buyapple_out.pickle --no-benchmark from zipline.api import symbol, order, record
def initialize(context): pass
def handle_data(context, data): order(symbol('AAPL'), 10) record(AAPL=data[symbol('AAPL')].price)
I get a TypeError: "zipline._protocol.BarData' object is not subscriptable" I set my api key & ingested the quandl data.
What am I missing out here?