Hi,
I found some differnces between running this simple code on Zipline on my MacBook and Quantopian.
The difference between the Benchmark and the strategie is quite significant on my Zipline installation.
I do not understand why this should not be exact matching lines. basically they are on Quantopian.
Do you get the same issue, or is it just my installation?
ThankX
import zipline
from zipline.api import (set_max_leverage, set_slippage, set_commission, order_target_percent,
symbol, schedule_function, date_rules, time_rules, set_benchmark)
from datetime import datetime
from zipline.finance.commission import PerDollar, PerShare
from zipline.finance.slippage import VolumeShareSlippage
intial_portfolio = 100000
def initialize(context):
set_benchmark(symbol('AAPL'))
set_commission(PerDollar(cost=0.000))
set_slippage(VolumeShareSlippage(volume_limit=1, price_impact=0))
schedule_function(rebalance,
date_rules.every_day(),
time_rules.market_open())
def rebalance(context, data):
order_target_percent(symbol('AAPL'),1)
# Set start and end
start = datetime(2014, 1, 1, 8, 15, 12, 0, pytz.UTC)
end = datetime(2019, 12, 31, 8, 15, 12, 0, pytz.UTC)
# Fire off backtest
perf = zipline.run_algorithm(
start=start, # Set start
end=end, # Set end
initialize=initialize, # Define startup function
capital_base=intial_portfolio, # Set initial capital
data_frequency = 'daily', # Set data frequency
bundle='sec_master_q' ) # Select bundle
print("Ready to analyze result.")
returns, positions, transactions = pf.utils.extract_rets_pos_txn_from_zipline(perf)
benchmark_period_return = perf['benchmark_period_return']
# Convert benchmark returns to daily returns
daily_benchmark_returns = (1 + benchmark_period_return) / (1 + benchmark_period_return.shift()) - 1
pf.create_returns_tear_sheet(returns, benchmark_rets=daily_benchmark_returns)