James McCool commited on
Commit
72d1643
·
1 Parent(s): 5637f7e

fixing exposure management

Browse files
Files changed (2) hide show
  1. app.py +12 -4
  2. global_func/exposure_spread.py +8 -4
app.py CHANGED
@@ -1342,6 +1342,7 @@ if selected_tab == 'Manage Portfolio':
1342
  min_dupes = st.number_input("Min acceptable dupes?", value=0, min_value=0, max_value=1000, step=1)
1343
  min_finish_percentile = st.number_input("Min acceptable finish percentile?", value=0.00, min_value=0.00, max_value=1.00, step=.001)
1344
  min_lineup_edge = st.number_input("Min acceptable Lineup Edge?", value=-1.00, min_value=-1.00, max_value=1.00, step=.001)
 
1345
  with macro_max_col:
1346
  max_salary = st.number_input("Max acceptable salary?", value=salary_max, min_value=0, max_value=salary_max, step=100)
1347
  max_proj = st.number_input("Max acceptable projection?", value=1500.0, min_value=0.0, max_value=1500.0, step=1.0)
@@ -1349,6 +1350,7 @@ if selected_tab == 'Manage Portfolio':
1349
  max_dupes = st.number_input("Max acceptable dupes?", value=1000, min_value=1, max_value=1000, step=1)
1350
  max_finish_percentile = st.number_input("Max acceptable finish percentile?", value=1.00, min_value=0.00, max_value=1.00, step=.001)
1351
  max_lineup_edge = st.number_input("Max acceptable Lineup Edge?", value=1.00, min_value=-1.00, max_value=1.00, step=.001)
 
1352
 
1353
  if sport_var in stacking_sports:
1354
  stack_include_toggle = st.selectbox("Include specific stacks?", options=['All Stacks', 'Specific Stacks'], index=0)
@@ -1380,7 +1382,9 @@ if selected_tab == 'Manage Portfolio':
1380
  (st.session_state['working_frame']['Finish_percentile'] >= min_finish_percentile) &
1381
  (st.session_state['working_frame']['Finish_percentile'] <= max_finish_percentile) &
1382
  (st.session_state['working_frame']['Lineup Edge'] >= min_lineup_edge) &
1383
- (st.session_state['working_frame']['Lineup Edge'] <= max_lineup_edge)
 
 
1384
  )
1385
 
1386
 
@@ -1410,7 +1414,9 @@ if selected_tab == 'Manage Portfolio':
1410
  (st.session_state['export_base']['Finish_percentile'] >= min_finish_percentile) &
1411
  (st.session_state['export_base']['Finish_percentile'] <= max_finish_percentile) &
1412
  (st.session_state['export_base']['Lineup Edge'] >= min_lineup_edge) &
1413
- (st.session_state['export_base']['Lineup Edge'] <= max_lineup_edge)
 
 
1414
  )
1415
 
1416
  if 'Stack' in st.session_state['export_base'].columns:
@@ -2027,6 +2033,8 @@ if selected_tab == 'Manage Portfolio':
2027
  with st.form(key='Exposures'):
2028
  exposure_player = st.selectbox("Player", options=sorted(list(set(st.session_state['projections_df']['player_names'].unique()))), key='exposure_player')
2029
  exposure_target = st.number_input("Target Exposure", value=.50, min_value=0.0, max_value=1.0, step=0.01)
 
 
2030
  if 'Stack' in st.session_state['working_frame'].columns:
2031
  ignore_stacks = st.multiselect("Ignore Specific Stacks?", options=sorted(list(set(st.session_state['projections_df']['team'].unique()))), default=[])
2032
  else:
@@ -2045,7 +2053,7 @@ if selected_tab == 'Manage Portfolio':
2045
  st.session_state['settings_base'] = False
2046
  # Prepare DataFrame for exposure_spread to avoid categorical issues
2047
  working_frame_prepared = prepare_dataframe_for_exposure_spread(st.session_state['working_frame'], st.session_state['player_columns'])
2048
- parsed_frame = exposure_spread(working_frame_prepared, st.session_state['exposure_player'], exposure_target, ignore_stacks, remove_teams_exposure, specific_replacements, specific_columns, st.session_state['projections_df'], sport_var, type_var, salary_max, stacking_sports)
2049
 
2050
  # Use consolidated calculation function
2051
  parsed_frame = calculate_lineup_metrics(
@@ -2082,7 +2090,7 @@ if selected_tab == 'Manage Portfolio':
2082
  st.session_state['settings_base'] = False
2083
  # Prepare DataFrame for exposure_spread to avoid categorical issues
2084
  export_base_prepared = prepare_dataframe_for_exposure_spread(st.session_state['export_base'], st.session_state['player_columns'])
2085
- parsed_frame = exposure_spread(export_base_prepared, st.session_state['exposure_player'], exposure_target, ignore_stacks, remove_teams_exposure, specific_replacements, specific_columns, st.session_state['projections_df'], sport_var, type_var, salary_max, stacking_sports)
2086
 
2087
  # Use consolidated calculation function for export
2088
  parsed_frame = calculate_lineup_metrics(
 
1342
  min_dupes = st.number_input("Min acceptable dupes?", value=0, min_value=0, max_value=1000, step=1)
1343
  min_finish_percentile = st.number_input("Min acceptable finish percentile?", value=0.00, min_value=0.00, max_value=1.00, step=.001)
1344
  min_lineup_edge = st.number_input("Min acceptable Lineup Edge?", value=-1.00, min_value=-1.00, max_value=1.00, step=.001)
1345
+ min_weighted_own = st.number_input("Min acceptable Weighted Own?", value=0.0, min_value=0.0, max_value=500.0, step=1.0)
1346
  with macro_max_col:
1347
  max_salary = st.number_input("Max acceptable salary?", value=salary_max, min_value=0, max_value=salary_max, step=100)
1348
  max_proj = st.number_input("Max acceptable projection?", value=1500.0, min_value=0.0, max_value=1500.0, step=1.0)
 
1350
  max_dupes = st.number_input("Max acceptable dupes?", value=1000, min_value=1, max_value=1000, step=1)
1351
  max_finish_percentile = st.number_input("Max acceptable finish percentile?", value=1.00, min_value=0.00, max_value=1.00, step=.001)
1352
  max_lineup_edge = st.number_input("Max acceptable Lineup Edge?", value=1.00, min_value=-1.00, max_value=1.00, step=.001)
1353
+ max_weighted_own = st.number_input("Max acceptable Weighted Own?", value=500.0, min_value=0.0, max_value=500.0, step=1.0)
1354
 
1355
  if sport_var in stacking_sports:
1356
  stack_include_toggle = st.selectbox("Include specific stacks?", options=['All Stacks', 'Specific Stacks'], index=0)
 
1382
  (st.session_state['working_frame']['Finish_percentile'] >= min_finish_percentile) &
1383
  (st.session_state['working_frame']['Finish_percentile'] <= max_finish_percentile) &
1384
  (st.session_state['working_frame']['Lineup Edge'] >= min_lineup_edge) &
1385
+ (st.session_state['working_frame']['Lineup Edge'] <= max_lineup_edge) &
1386
+ (st.session_state['working_frame']['Weighted Own'] >= min_weighted_own) &
1387
+ (st.session_state['working_frame']['Weighted Own'] <= max_weighted_own)
1388
  )
1389
 
1390
 
 
1414
  (st.session_state['export_base']['Finish_percentile'] >= min_finish_percentile) &
1415
  (st.session_state['export_base']['Finish_percentile'] <= max_finish_percentile) &
1416
  (st.session_state['export_base']['Lineup Edge'] >= min_lineup_edge) &
1417
+ (st.session_state['export_base']['Lineup Edge'] <= max_lineup_edge) &
1418
+ (st.session_state['export_base']['Weighted Own'] >= min_weighted_own) &
1419
+ (st.session_state['export_base']['Weighted Own'] <= max_weighted_own)
1420
  )
1421
 
1422
  if 'Stack' in st.session_state['export_base'].columns:
 
2033
  with st.form(key='Exposures'):
2034
  exposure_player = st.selectbox("Player", options=sorted(list(set(st.session_state['projections_df']['player_names'].unique()))), key='exposure_player')
2035
  exposure_target = st.number_input("Target Exposure", value=.50, min_value=0.0, max_value=1.0, step=0.01)
2036
+ comp_salary_below = st.number_input("Comp Salary Below", value=0, min_value=-1000, max_value=0, step=100)
2037
+ comp_salary_above = st.number_input("Comp Salary Above", value=0, min_value=0, max_value=1000, step=100)
2038
  if 'Stack' in st.session_state['working_frame'].columns:
2039
  ignore_stacks = st.multiselect("Ignore Specific Stacks?", options=sorted(list(set(st.session_state['projections_df']['team'].unique()))), default=[])
2040
  else:
 
2053
  st.session_state['settings_base'] = False
2054
  # Prepare DataFrame for exposure_spread to avoid categorical issues
2055
  working_frame_prepared = prepare_dataframe_for_exposure_spread(st.session_state['working_frame'], st.session_state['player_columns'])
2056
+ parsed_frame = exposure_spread(working_frame_prepared, st.session_state['exposure_player'], exposure_target, comp_salary_below, comp_salary_above, ignore_stacks, remove_teams_exposure, specific_replacements, specific_columns, st.session_state['projections_df'], sport_var, type_var, salary_max, stacking_sports)
2057
 
2058
  # Use consolidated calculation function
2059
  parsed_frame = calculate_lineup_metrics(
 
2090
  st.session_state['settings_base'] = False
2091
  # Prepare DataFrame for exposure_spread to avoid categorical issues
2092
  export_base_prepared = prepare_dataframe_for_exposure_spread(st.session_state['export_base'], st.session_state['player_columns'])
2093
+ parsed_frame = exposure_spread(export_base_prepared, st.session_state['exposure_player'], exposure_target, comp_salary_below, comp_salary_above, ignore_stacks, remove_teams_exposure, specific_replacements, specific_columns, st.session_state['projections_df'], sport_var, type_var, salary_max, stacking_sports)
2094
 
2095
  # Use consolidated calculation function for export
2096
  parsed_frame = calculate_lineup_metrics(
global_func/exposure_spread.py CHANGED
@@ -148,20 +148,22 @@ def check_position_eligibility(sport, column_name, player_positions):
148
  # Default fallback - assume exact position match
149
  return column_name in player_positions
150
 
151
- def exposure_spread(working_frame, exposure_player, exposure_target, ignore_stacks, remove_teams, specific_replacements, specific_columns, projections_df, sport_var, type_var, salary_max, stacking_sports):
152
  comparable_players = projections_df[projections_df['player_names'] == exposure_player]
153
 
154
  comparable_players = comparable_players.reset_index(drop=True)
155
  comp_salary_high = comparable_players['salary'][0]
156
  if type_var == 'Showdown':
157
- comp_salary_low = comparable_players['salary'][0] - 1000
 
158
  else:
159
- comp_salary_low = comparable_players['salary'][0] - 500
 
160
  comp_projection_high = comparable_players['median'][0]
161
  if type_var == 'Showdown':
162
  comp_projection_low = comparable_players['median'][0] - (comparable_players['median'][0] * .5)
163
  else:
164
- comp_projection_low = comparable_players['median'][0] - (comparable_players['median'][0] * .75)
165
  # players can be eligible at multiple positions, so we need to find all the positions the player is eligible at
166
  # the position column can have positions designated as 1B/OF which means they are eligible at 1B and OF
167
  comp_player_position = comparable_players['position'].tolist()
@@ -226,6 +228,8 @@ def exposure_spread(working_frame, exposure_player, exposure_target, ignore_stac
226
  # key concept here is if they have a lineups to remove above 0 it means that we are trying to replace them with comparable players
227
  # if the lineups to remove is below zero it means we want to find comparable players and replace them with the exposure player
228
  if lineups_to_remove > 0:
 
 
229
  for row in random_row_indices_insert:
230
  if change_counter < math.ceil(lineups_to_remove):
231
  if specific_replacements != []:
 
148
  # Default fallback - assume exact position match
149
  return column_name in player_positions
150
 
151
+ def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary_below, comp_salary_above, ignore_stacks, remove_teams, specific_replacements, specific_columns, projections_df, sport_var, type_var, salary_max, stacking_sports):
152
  comparable_players = projections_df[projections_df['player_names'] == exposure_player]
153
 
154
  comparable_players = comparable_players.reset_index(drop=True)
155
  comp_salary_high = comparable_players['salary'][0]
156
  if type_var == 'Showdown':
157
+ comp_salary_low = comparable_players['salary'][0] + comp_salary_below
158
+ comp_salary_high = comparable_players['salary'][0] + comp_salary_above
159
  else:
160
+ comp_salary_low = comparable_players['salary'][0] + comp_salary_below
161
+ comp_salary_high = comparable_players['salary'][0] + comp_salary_above
162
  comp_projection_high = comparable_players['median'][0]
163
  if type_var == 'Showdown':
164
  comp_projection_low = comparable_players['median'][0] - (comparable_players['median'][0] * .5)
165
  else:
166
+ comp_projection_low = comparable_players['median'][0] - (comparable_players['median'][0] * .5)
167
  # players can be eligible at multiple positions, so we need to find all the positions the player is eligible at
168
  # the position column can have positions designated as 1B/OF which means they are eligible at 1B and OF
169
  comp_player_position = comparable_players['position'].tolist()
 
228
  # key concept here is if they have a lineups to remove above 0 it means that we are trying to replace them with comparable players
229
  # if the lineups to remove is below zero it means we want to find comparable players and replace them with the exposure player
230
  if lineups_to_remove > 0:
231
+ print(f"Lineups to remove: {lineups_to_remove}")
232
+ print(f"Current Counter: {change_counter}")
233
  for row in random_row_indices_insert:
234
  if change_counter < math.ceil(lineups_to_remove):
235
  if specific_replacements != []: