Back to Community
Find biggest position in your portfolio
def find_biggest_position(positions):  
    biggest_position = {'stock':'','size':-1}  
    for stock in positions.keys():  
        psn = positions[stock]  
        if 'Position' not in str(type(psn))  
            continue  
        if psn.cost_basis == 0 or psn.amount == 0:  
            continue  
        psn_size = psn.last_sale_price * psn.amount  
        if psn_size > biggest_position['size']:  
            biggest_position['size'] = psn_size  
            biggest_position['stock'] = psn.sid  
    return biggest_position