I have an algorithm that rebalances monthly, and only trades monthly. Yet my leverage during the month creeps up (sometimes going from 1 to 4) despite not having made any trades. Is it something to do with shorting? Here’s my order logic.
#Find Weights, avoiding a divide by zero
try:
weight = context.lev / (len(hold_list) + len(short_list))
except:
weight = 0.0
#Place the orders
for stock in data:
if stock in hold_list: #Long
order_target_percent(stock, +weight)
elif stock in short_list: #Short
order_target_percent(stock, -weight)
else: #Nothing
order_target_percent(stock, 0.0)