Code Monkey home page Code Monkey logo

Comments (4)

mike576 avatar mike576 commented on June 21, 2024 2

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')

from zipline.

russtoku avatar russtoku commented on June 21, 2024 1

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 !

from zipline.

mike576 avatar mike576 commented on June 21, 2024

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.

from zipline.

andycwang avatar andycwang commented on June 21, 2024

from zipline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.