"weights" is an array containing the weights of each stock in "context.reqd_data "(both arrays are of equal length) , "context.prev_weights" is yet another array which stores the weights of previous day . I am firstly executing the orders for the stocks which have reduced weight today so that it frees up cash to avoid leveraging. Is this the right approach to do it ? Also can I use the following loops to execute orders (maybe I can't since I am getting some errors)?
for x in range(0,len(weights)):
if abs(weights[x]) < abs(context.prev_weights[x]):
order_target_percent(context.reqd_data[x],weights[x])
for x in range(0,len(weights)):
if abs(weights[x]) > abs(context.prev_weights[x]):
order_target_percent(context.reqd_data[x],weights[x])
for x in range(0,len(weights)):
if weights[x] != weights[x]:
order_target_percent(context.reqd_data[x],0)
Runtime exception: IndexError: list index out of range
I get this error at the start of each loop.