DFS_Portfolio_Manager / global_func /trim_portfolio.py
James McCool
Enhance portfolio filtering and trimming options in app.py: introduce expandable sections for filter and trimming options, update portfolio trimming logic to support geomean calculations, and improve export functionality with stack count adjustments.
25fcef5
raw
history blame
767 Bytes
def trim_portfolio(portfolio, performance_type, own_type):
if performance_type == 'Finish_percentile':
working_portfolio = portfolio.sort_values(by=performance_type, ascending = True).reset_index(drop=True)
else:
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.loc[i, own_type]
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
return working_portfolio