Ok brilliant thanks. I'm trying to develop a 'buy and hold' strategy that only trades when new fundamental data comes out, which I would have thought to be at reporting seasons.
Nb. 'longs' are filtered by fundamental factors.
So, I tried the below;
def my_rebalance(context,data):
long_secs = context.output[context.output ['longs']].index
long_weights = 1.00 / len(long_secs)
for security in long_secs:
if data.can_trade(security) and security not in context.portfolio.positions:
order_target_percent(security, long_weights)
for security in context.portfolio.positions:
if data.can_trade(security) and security not in long_secs:
order_target_percent(security, 0)
I would have thought that it would buy based on fundamental factors and only sell when the fundamentals change and it falls out of the long_secs list. (There should be no weekly adjusting weights of current portfolio as I've said 'not in context.portfolio.positions').
But this still trades significant volume each week. Why is it not simply buying and holding?