James McCool commited on
Commit
91ab4fb
·
1 Parent(s): 039bb05

Enhance trimming variable options in app.py and update portfolio trimming logic in trim_portfolio.py to accommodate 'Similarity Score'. This change allows for more flexible data handling and improves the trimming process based on the selected variable.

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. global_func/trim_portfolio.py +16 -8
app.py CHANGED
@@ -1079,7 +1079,7 @@ with tab2:
1079
  with perf_var:
1080
  performance_type = st.selectbox("Sorting variable", ['median', 'Finish_percentile'], key='sort_var')
1081
  with own_var:
1082
- own_type = st.selectbox("Trimming variable", ['Own', 'Geomean', 'Weighted Own'], key='trim_var')
1083
 
1084
  trim_slack_var = st.number_input("Trim slack (percentile addition to trimming variable ceiling)", value=0.0, min_value=0.0, max_value=1.0, step=0.1, key='trim_slack')
1085
 
 
1079
  with perf_var:
1080
  performance_type = st.selectbox("Sorting variable", ['median', 'Finish_percentile'], key='sort_var')
1081
  with own_var:
1082
+ own_type = st.selectbox("Trimming variable", ['Own', 'Geomean', 'Weighted Own', 'Similarity Score'], key='trim_var')
1083
 
1084
  trim_slack_var = st.number_input("Trim slack (percentile addition to trimming variable ceiling)", value=0.0, min_value=0.0, max_value=1.0, step=0.1, key='trim_slack')
1085
 
global_func/trim_portfolio.py CHANGED
@@ -9,14 +9,22 @@ def trim_portfolio(portfolio: pd.DataFrame, trim_slack: float, performance_type:
9
  curr_own_type_max = working_portfolio.loc[0, own_type] + (trim_slack * 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] + (trim_slack * working_portfolio.loc[i, own_type])
20
-
 
 
 
 
 
21
  working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
22
  return working_portfolio
 
9
  curr_own_type_max = working_portfolio.loc[0, own_type] + (trim_slack * working_portfolio.loc[0, own_type])
10
 
11
  for i in range(1, len(working_portfolio)):
12
+ if own_type == 'Similarity Score':
13
+ if working_portfolio.loc[i, own_type] > curr_own_type_max and \
14
+ working_portfolio.loc[i, performance_type] > performance_threshold_low and \
15
+ working_portfolio.loc[i, performance_type] <= performance_threshold_high and \
16
+ working_portfolio.loc[i, own_type] > own_threshold_low and \
17
+ working_portfolio.loc[i, own_type] <= own_threshold_high:
18
+ rows_to_drop.append(i)
19
+ else:
20
+ curr_own_type_max = working_portfolio.loc[i, own_type] + (trim_slack * working_portfolio.loc[i, own_type])
21
  else:
22
+ if working_portfolio.loc[i, own_type] > curr_own_type_max and \
23
+ working_portfolio.loc[i, performance_type] > performance_threshold_low and \
24
+ working_portfolio.loc[i, performance_type] <= performance_threshold_high and \
25
+ working_portfolio.loc[i, own_type] > own_threshold_low and \
26
+ working_portfolio.loc[i, own_type] <= own_threshold_high:
27
+ rows_to_drop.append(i)
28
+
29
  working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
30
  return working_portfolio