Hi,
I am trying to create a loop that quantifies the market value of each position at the start of the trading day. For some reason, my loop is not working and I can't figure out why. I would appreciate any help understanding why the loop is not working correctly. See below
def before_trading_start(context, data):
LV = SV = 0
for security in context.portfolio.positions:
current_price = data.current(security , 'price')
shares = security.amount
if shares > 0:
LV += shares*current_price
if shares < 0:
SV += shares*current_price
print LV