James McCool commited on
Commit
1c0e798
·
1 Parent(s): efb1867

Add 'Reduce Volatility' preset option in app.py and implement reduce_volatility_preset function. This update enhances user options for lineup management by allowing users to manage volatility in their selections, improving overall portfolio strategy.

Browse files
Files changed (2) hide show
  1. app.py +4 -1
  2. global_func/reduce_volatility_preset.py +30 -0
app.py CHANGED
@@ -24,6 +24,7 @@ from global_func.small_field_preset import small_field_preset
24
  from global_func.large_field_preset import large_field_preset
25
  from global_func.hedging_preset import hedging_preset
26
  from global_func.volatility_preset import volatility_preset
 
27
 
28
  freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Win%': '{:.2%}'}
29
  stacking_sports = ['MLB', 'NHL', 'NFL']
@@ -1112,7 +1113,7 @@ with tab2:
1112
  with st.expander('Presets'):
1113
  st.info("Still heavily in testing here, I'll announce when they are ready for use.")
1114
  with st.form(key='Small Field Preset'):
1115
- preset_choice = st.selectbox("Preset", options=['Small Field (Heavy Own)', 'Large Field (Manage Diversity)', 'Hedge Chalk (Manage Leverage)', 'Volatility (Heavy Lineup Edge)'], index=0)
1116
  lineup_target = st.number_input("Lineups to produce", value=150, min_value=1, step=1)
1117
  submitted = st.form_submit_button("Submit")
1118
  if submitted:
@@ -1124,6 +1125,8 @@ with tab2:
1124
  parsed_frame = volatility_preset(st.session_state['working_frame'], lineup_target, excluded_cols)
1125
  elif preset_choice == 'Hedge Chalk (Manage Leverage)':
1126
  parsed_frame = hedging_preset(st.session_state['working_frame'], lineup_target, st.session_state['projections_df'])
 
 
1127
  st.session_state['working_frame'] = parsed_frame.reset_index(drop=True)
1128
  st.session_state['export_merge'] = st.session_state['working_frame'].copy()
1129
 
 
24
  from global_func.large_field_preset import large_field_preset
25
  from global_func.hedging_preset import hedging_preset
26
  from global_func.volatility_preset import volatility_preset
27
+ from global_func.reduce_volatility_preset import reduce_volatility_preset
28
 
29
  freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Win%': '{:.2%}'}
30
  stacking_sports = ['MLB', 'NHL', 'NFL']
 
1113
  with st.expander('Presets'):
1114
  st.info("Still heavily in testing here, I'll announce when they are ready for use.")
1115
  with st.form(key='Small Field Preset'):
1116
+ preset_choice = st.selectbox("Preset", options=['Small Field (Heavy Own)', 'Large Field (Manage Diversity)', 'Hedge Chalk (Manage Leverage)', 'Volatility (Heavy Lineup Edge)', 'Reduce Volatility (Manage Own)'], index=0)
1117
  lineup_target = st.number_input("Lineups to produce", value=150, min_value=1, step=1)
1118
  submitted = st.form_submit_button("Submit")
1119
  if submitted:
 
1125
  parsed_frame = volatility_preset(st.session_state['working_frame'], lineup_target, excluded_cols)
1126
  elif preset_choice == 'Hedge Chalk (Manage Leverage)':
1127
  parsed_frame = hedging_preset(st.session_state['working_frame'], lineup_target, st.session_state['projections_df'])
1128
+ elif preset_choice == 'Reduce Volatility (Manage Own)':
1129
+ parsed_frame = reduce_volatility_preset(st.session_state['working_frame'], lineup_target, excluded_cols)
1130
  st.session_state['working_frame'] = parsed_frame.reset_index(drop=True)
1131
  st.session_state['export_merge'] = st.session_state['working_frame'].copy()
1132
 
global_func/reduce_volatility_preset.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+
4
+ def volatility_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
5
+ excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Diversity']
6
+ player_columns = [col for col in portfolio.columns if col not in excluded_cols]
7
+
8
+ for slack_var in range(1, 20):
9
+ concat_portfolio = pd.DataFrame(columns=portfolio.columns)
10
+
11
+ for team in portfolio['Stack'].unique():
12
+ rows_to_drop = []
13
+ working_portfolio = portfolio.copy()
14
+ working_portfolio = working_portfolio[working_portfolio['Stack'] == team].sort_values(by='Weighted Own', ascending = False)
15
+ working_portfolio = working_portfolio.reset_index(drop=True)
16
+ curr_own_type_max = working_portfolio.loc[0, 'Diversity'] + (slack_var / 20 * working_portfolio.loc[0, 'Diversity'])
17
+
18
+ for i in range(1, len(working_portfolio)):
19
+ if working_portfolio.loc[i, 'Diversity'] < curr_own_type_max:
20
+ rows_to_drop.append(i)
21
+ else:
22
+ curr_own_type_max = working_portfolio.loc[i, 'Diversity'] + (slack_var / 20 * working_portfolio.loc[i, 'Diversity'])
23
+
24
+ working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
25
+ concat_portfolio = pd.concat([concat_portfolio, working_portfolio])
26
+
27
+ if len(concat_portfolio) >= lineup_target:
28
+ return concat_portfolio.sort_values(by='Weighted Own', ascending=False).head(lineup_target)
29
+
30
+ return concat_portfolio.sort_values(by='Weighted Own', ascending=False)