pip install zipline
python
import pandas as pd
from zipline import run_algorithm
from zipline.api import order, record, symbol
python
def initialize(context):
context.assets = [symbol('AAPL'), symbol('GOOG'), symbol('FB')]
def handle_data(context, data):
for asset in context.assets:
record(AAPL=data[symbol('AAPL')].price,
GOOG=data[symbol('GOOG')].price,
FB=data[symbol('FB')].price)
python
start_date = pd.Timestamp('2016-01-01', tz='utc')
end_date = pd.Timestamp('2017-01-01', tz='utc')
result = run_algorithm(start=start_date,
end=end_date,
initialize=initialize,
handle_data=handle_data,
capital_base=10000)
result.portfolio_value.plot()