Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Position object does not have amount property?

I am trying to sum up the value of all my short positions only. So.... I want to parse thru all open positions and if the number of shares opened is negative (a short position) then I was to add that position's value to a variable. Here is a sample of the loop

    for pos in context.portfolio.positions:  
#        print(str(pos.sid) )  
        if pos.amount<0: #short position  
            context.totalShorts += (pos.amount * pos.price)  

and I'm getting this error

AttributeError: 'Security' object has no attribute 'amount'
USER ALGORITHM:40, in handle_data
if pos.amount<0: #short position

1 response

So I guess this works

    for sym in data.keys():  
        if context.portfolio.positions[sym].amount < 0:  
            context.totalShorts += (context.portfolio.positions[sym].amount * data[sym].price)