def initialize(context):
context.stocks = [sid(1419),sid(12652)]
def handle_data(context, data):
# This will order as many shares as needed to
# achieve the desired portfolio allocation.
# In our case, we end up with 20% allocation for
# one stock and 80% allocation for the other stock.
order_target_percent(context.stocks[0], .2)
order_target_percent(context.stocks[1], .8)
# Plot portfolio allocations
pv = float(context.portfolio.portfolio_value)
#print pv
portfolio_allocations = []
for stock in context.stocks:
pos = context.portfolio.positions[stock]
#print pos
portfolio_allocations.append(
pos.last_sale_price * pos.amount / pv * 100
)
record(perc_stock_0=portfolio_allocations[0],
perc_stock_1=portfolio_allocations[1])
I am a little confused about how quantopian runs the backtest. At first I thought it runs to check every minute data.But in the example above, how the portfolio is adjusted? By every minute or on a daily basis?
In the transaction details buy and sell are based on daily basis. (two transactions everyday).If this is right,does that mean quantopian choose close price to adjust the portfolio?