I'm attempting to run an algorithm to take 11 stocks and rebalance them. I'm looking to do a comparison of a weekly, monthly, quarterly, and annual rebalance. It looks like the only dropdown option is daily on the backtest. Is there a way to do this programatically. Here is the code I'm using from one of the sample algorithms. I'm pretty new to coding so I'm not sure where to start.
def initialize(context):
set_symbol_lookup_date('2005-01-01')
context.stocks = symbols('VHT', 'VDE', 'VDC', 'VOX', 'VAW', 'VNQ', 'VGT', 'VIS', 'VCR', 'VPU', 'VFH')
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], .11)
order_target_percent(context.stocks[1], .11)
order_target_percent(context.stocks[2], .11)
order_target_percent(context.stocks[3], .11)
order_target_percent(context.stocks[4], .11)
order_target_percent(context.stocks[5], .11)
order_target_percent(context.stocks[6], .11)
order_target_percent(context.stocks[7], .11)
order_target_percent(context.stocks[8], .11)
order_target_percent(context.stocks[9], .11)
order_target_percent(context.stocks[10], .11)
# Plot portfolio allocations
pv = float(context.portfolio.portfolio_value)
portfolio_allocations = []
for stock in context.stocks:
pos = context.portfolio.positions[stock]
portfolio_allocations.append(
pos.last_sale_price * pos.amount / pv * 100
)