James McCool commited on
Commit
607dd10
·
1 Parent(s): 6ba45c0

Enhance portfolio trimming functionality in app.py and trim_portfolio.py: add performance and own thresholds for trimming criteria, improving data filtering capabilities and allowing for more precise portfolio management.

Browse files
Files changed (2) hide show
  1. app.py +5 -2
  2. global_func/trim_portfolio.py +8 -2
app.py CHANGED
@@ -912,7 +912,10 @@ with tab2:
912
  with st.form(key='trim_form'):
913
  performance_type = st.selectbox("Select Sorting variable", ['median', 'Finish_percentile'])
914
  own_type = st.selectbox("Select trimming variable", ['Own', 'Geomean', 'Weighted Own'])
915
-
 
 
 
916
  submitted = st.form_submit_button("Trim")
917
  if submitted:
918
  st.write('initiated')
@@ -946,7 +949,7 @@ with tab2:
946
  )
947
  st.session_state['portfolio'] = st.session_state['portfolio'][lock_mask]
948
 
949
- st.session_state['portfolio'] = trim_portfolio(st.session_state['portfolio'], performance_type, own_type)
950
  st.session_state['portfolio'] = st.session_state['portfolio'].sort_values(by='median', ascending=False)
951
 
952
  with col2:
 
912
  with st.form(key='trim_form'):
913
  performance_type = st.selectbox("Select Sorting variable", ['median', 'Finish_percentile'])
914
  own_type = st.selectbox("Select trimming variable", ['Own', 'Geomean', 'Weighted Own'])
915
+ performance_threshold_high = st.number_input("Select performance threshold (will only trim if sorting variable is lower than this)", value=st.session_state['portfolio'][performance_type].max(), min_value=0, step=1)
916
+ performance_threshold_low = st.number_input("Select performance threshold (will only trim if sorting variable is higher than this)", value=0, min_value=0, step=1)
917
+ own_threshold_high = st.number_input("Select own threshold (will only trim if trimming variable is lower than this)", value=st.session_state['portfolio'][own_type].max(), min_value=0, step=1)
918
+ own_threshold_low = st.number_input("Select own threshold (will only trim if trimming variable is higher than this)", value=0, min_value=0, step=1)
919
  submitted = st.form_submit_button("Trim")
920
  if submitted:
921
  st.write('initiated')
 
949
  )
950
  st.session_state['portfolio'] = st.session_state['portfolio'][lock_mask]
951
 
952
+ st.session_state['portfolio'] = trim_portfolio(st.session_state['portfolio'], performance_type, own_type, performance_threshold_high, performance_threshold_low, own_threshold_high, own_threshold_low)
953
  st.session_state['portfolio'] = st.session_state['portfolio'].sort_values(by='median', ascending=False)
954
 
955
  with col2:
global_func/trim_portfolio.py CHANGED
@@ -1,4 +1,6 @@
1
- def trim_portfolio(portfolio, performance_type, own_type):
 
 
2
  if performance_type == 'Finish_percentile':
3
  working_portfolio = portfolio.sort_values(by=performance_type, ascending = True).reset_index(drop=True)
4
  else:
@@ -7,7 +9,11 @@ def trim_portfolio(portfolio, performance_type, own_type):
7
  curr_own_type_max = working_portfolio.loc[0, own_type]
8
 
9
  for i in range(1, len(working_portfolio)):
10
- if working_portfolio.loc[i, own_type] > curr_own_type_max:
 
 
 
 
11
  rows_to_drop.append(i)
12
  else:
13
  curr_own_type_max = working_portfolio.loc[i, own_type]
 
1
+ import pandas as pd
2
+
3
+ def trim_portfolio(portfolio: pd.DataFrame, performance_type: str, own_type: str, performance_threshold_high: int, performance_threshold_low: int, own_threshold_high: int, own_threshold_low: int):
4
  if performance_type == 'Finish_percentile':
5
  working_portfolio = portfolio.sort_values(by=performance_type, ascending = True).reset_index(drop=True)
6
  else:
 
9
  curr_own_type_max = working_portfolio.loc[0, own_type]
10
 
11
  for i in range(1, len(working_portfolio)):
12
+ if working_portfolio.loc[i, own_type] > curr_own_type_max and \
13
+ working_portfolio.loc[i, performance_type] > performance_threshold_low and \
14
+ working_portfolio.loc[i, performance_type] <= performance_threshold_high and \
15
+ working_portfolio.loc[i, own_type] > own_threshold_low and \
16
+ working_portfolio.loc[i, own_type] <= own_threshold_high:
17
  rows_to_drop.append(i)
18
  else:
19
  curr_own_type_max = working_portfolio.loc[i, own_type]