File size: 534 Bytes
4f8d205
88832b4
 
 
4f8d205
88832b4
 
 
 
 
4f8d205
 
1
2
3
4
5
6
7
8
9
10
11
12
def trim_portfolio(portfolio, performance_type, own_type):
    working_portfolio = portfolio.sort_values(by=performance_type, ascending = False).reset_index(drop=True)
    rows_to_drop = []
    curr_own_type_max = working_portfolio.loc(0, own_type)

    for i in range(1, len(working_portfolio)):
        if working_portfolio.loc[i, own_type] > curr_own_type_max:
            rows_to_drop.append(i)
        else:
            curr_own_type_max = working_portfolio.drop(rows_to_drop).reset_index(drop=True)

    return working_portfolio