Spaces:
Running
Running
James McCool
commited on
Commit
·
aebd6f1
1
Parent(s):
83e4ee0
Add distribution type selection for ROO simulations in NBA functions
Browse files- app.py +7 -6
- function_hold/NBA_functions.py +54 -6
app.py
CHANGED
@@ -84,6 +84,7 @@ with tab2:
|
|
84 |
|
85 |
with st.sidebar:
|
86 |
site_var_sb = st.selectbox("Select Site", ["Draftkings", "Fanduel"])
|
|
|
87 |
floor_var_sb = st.number_input("Floor (low end multiplier)", min_value=0.00, max_value=.50, value=.25, step=.01)
|
88 |
ceiling_var_sb = st.number_input("Ceiling (high end multiplier)", min_value=1.50, max_value=3.00, value=2.00, step=.01)
|
89 |
std_var_sb = st.number_input("Standard Deviation (variance within distribution)", min_value=1.00, max_value=5.00, value=4.00, step=.01)
|
@@ -92,19 +93,19 @@ with tab2:
|
|
92 |
if st.button('Build ROO'):
|
93 |
if sport_var == "NBA":
|
94 |
if site_var_sb == "Draftkings":
|
95 |
-
disp_file = DK_NBA_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb)
|
96 |
elif site_var_sb == "Fanduel":
|
97 |
-
disp_file = FD_NBA_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb)
|
98 |
elif sport_var == "NFL":
|
99 |
if site_var_sb == "Draftkings":
|
100 |
-
disp_file = DK_NFL_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb)
|
101 |
elif site_var_sb == "Fanduel":
|
102 |
-
disp_file = FD_NFL_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb)
|
103 |
elif sport_var == "MLB":
|
104 |
if site_var_sb == "Draftkings":
|
105 |
-
disp_file = DK_MLB_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb)
|
106 |
elif site_var_sb == "Fanduel":
|
107 |
-
disp_file = FD_MLB_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb)
|
108 |
|
109 |
if disp_file is not None:
|
110 |
st.dataframe(disp_file.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
|
|
84 |
|
85 |
with st.sidebar:
|
86 |
site_var_sb = st.selectbox("Select Site", ["Draftkings", "Fanduel"])
|
87 |
+
distribution_type_sb = st.selectbox("Select Distribution Type", ['normal', 'poisson', 'bimodal'])
|
88 |
floor_var_sb = st.number_input("Floor (low end multiplier)", min_value=0.00, max_value=.50, value=.25, step=.01)
|
89 |
ceiling_var_sb = st.number_input("Ceiling (high end multiplier)", min_value=1.50, max_value=3.00, value=2.00, step=.01)
|
90 |
std_var_sb = st.number_input("Standard Deviation (variance within distribution)", min_value=1.00, max_value=5.00, value=4.00, step=.01)
|
|
|
93 |
if st.button('Build ROO'):
|
94 |
if sport_var == "NBA":
|
95 |
if site_var_sb == "Draftkings":
|
96 |
+
disp_file = DK_NBA_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb)
|
97 |
elif site_var_sb == "Fanduel":
|
98 |
+
disp_file = FD_NBA_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb)
|
99 |
elif sport_var == "NFL":
|
100 |
if site_var_sb == "Draftkings":
|
101 |
+
disp_file = DK_NFL_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb)
|
102 |
elif site_var_sb == "Fanduel":
|
103 |
+
disp_file = FD_NFL_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb)
|
104 |
elif sport_var == "MLB":
|
105 |
if site_var_sb == "Draftkings":
|
106 |
+
disp_file = DK_MLB_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb)
|
107 |
elif site_var_sb == "Fanduel":
|
108 |
+
disp_file = FD_MLB_ROO_Build(projections, floor_var_sb, ceiling_var_sb, std_var_sb, distribution_type_sb)
|
109 |
|
110 |
if disp_file is not None:
|
111 |
st.dataframe(disp_file.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
function_hold/NBA_functions.py
CHANGED
@@ -7,7 +7,7 @@ from pandas import concat as pd_concat
|
|
7 |
from pandas import merge as pd_merge
|
8 |
from pandas import DataFrame
|
9 |
|
10 |
-
def DK_NBA_ROO_Build(projections_file, floor_var, ceiling_var, std_var):
|
11 |
total_sims = 1000
|
12 |
|
13 |
projects_raw = projections_file.copy()
|
@@ -144,7 +144,22 @@ def DK_NBA_ROO_Build(projections_file, floor_var, ceiling_var, std_var):
|
|
144 |
|
145 |
try:
|
146 |
for x in range(0, total_sims):
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
sim_array[:, x] = result_gpu
|
149 |
add_array = sim_array
|
150 |
|
@@ -153,7 +168,16 @@ def DK_NBA_ROO_Build(projections_file, floor_var, ceiling_var, std_var):
|
|
153 |
check_file = pd_concat([overall_file, df2], axis=1)
|
154 |
except:
|
155 |
for x in range(0,total_sims):
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
check_file = overall_file.copy()
|
158 |
|
159 |
overall_file=check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
@@ -207,7 +231,7 @@ def DK_NBA_ROO_Build(projections_file, floor_var, ceiling_var, std_var):
|
|
207 |
|
208 |
return final_Proj.copy()
|
209 |
|
210 |
-
def FD_NBA_ROO_Build(projections_file, floor_var, ceiling_var, std_var):
|
211 |
total_sims = 1000
|
212 |
|
213 |
projects_raw = projections_file.copy()
|
@@ -343,7 +367,22 @@ def FD_NBA_ROO_Build(projections_file, floor_var, ceiling_var, std_var):
|
|
343 |
|
344 |
try:
|
345 |
for x in range(0, total_sims):
|
346 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
sim_array[:, x] = result_gpu
|
348 |
add_array = sim_array
|
349 |
|
@@ -352,7 +391,16 @@ def FD_NBA_ROO_Build(projections_file, floor_var, ceiling_var, std_var):
|
|
352 |
check_file = pd_concat([overall_file, df2], axis=1)
|
353 |
except:
|
354 |
for x in range(0,total_sims):
|
355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
check_file = overall_file.copy()
|
357 |
|
358 |
overall_file=check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
|
|
7 |
from pandas import merge as pd_merge
|
8 |
from pandas import DataFrame
|
9 |
|
10 |
+
def DK_NBA_ROO_Build(projections_file, floor_var, ceiling_var, std_var, distribution_type):
|
11 |
total_sims = 1000
|
12 |
|
13 |
projects_raw = projections_file.copy()
|
|
|
144 |
|
145 |
try:
|
146 |
for x in range(0, total_sims):
|
147 |
+
if distribution_type == 'normal':
|
148 |
+
# Normal distribution (existing logic)
|
149 |
+
result_gpu = np_random.normal(overall_median_gpu, overall_std_gpu)
|
150 |
+
elif distribution_type == 'poisson':
|
151 |
+
# Poisson distribution - using median as lambda
|
152 |
+
result_gpu = np_random.poisson(overall_median_gpu)
|
153 |
+
elif distribution_type == 'bimodal':
|
154 |
+
# Bimodal distribution - mixture of two normal distributions
|
155 |
+
# First peak centered at 80% of median, second at 120% of median
|
156 |
+
if np_random.random() < 0.5:
|
157 |
+
result_gpu = np_random.normal(overall_median_gpu * 0.8, overall_std_gpu)
|
158 |
+
else:
|
159 |
+
result_gpu = np_random.normal(overall_median_gpu * 1.2, overall_std_gpu)
|
160 |
+
else:
|
161 |
+
raise ValueError("Invalid distribution type. Must be 'normal', 'poisson', or 'bimodal'")
|
162 |
+
|
163 |
sim_array[:, x] = result_gpu
|
164 |
add_array = sim_array
|
165 |
|
|
|
168 |
check_file = pd_concat([overall_file, df2], axis=1)
|
169 |
except:
|
170 |
for x in range(0,total_sims):
|
171 |
+
if distribution_type == 'normal':
|
172 |
+
overall_file[x] = np_random.normal(overall_file['Median'], overall_file['STD'])
|
173 |
+
elif distribution_type == 'poisson':
|
174 |
+
overall_file[x] = np_random.poisson(overall_file['Median'])
|
175 |
+
elif distribution_type == 'bimodal':
|
176 |
+
# Bimodal distribution fallback
|
177 |
+
if np_random.random() < 0.5:
|
178 |
+
overall_file[x] = np_random.normal(overall_file['Median'] * 0.8, overall_file['STD'])
|
179 |
+
else:
|
180 |
+
overall_file[x] = np_random.normal(overall_file['Median'] * 1.2, overall_file['STD'])
|
181 |
check_file = overall_file.copy()
|
182 |
|
183 |
overall_file=check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
|
|
231 |
|
232 |
return final_Proj.copy()
|
233 |
|
234 |
+
def FD_NBA_ROO_Build(projections_file, floor_var, ceiling_var, std_var, distribution_type):
|
235 |
total_sims = 1000
|
236 |
|
237 |
projects_raw = projections_file.copy()
|
|
|
367 |
|
368 |
try:
|
369 |
for x in range(0, total_sims):
|
370 |
+
if distribution_type == 'normal':
|
371 |
+
# Normal distribution (existing logic)
|
372 |
+
result_gpu = np_random.normal(overall_median_gpu, overall_std_gpu)
|
373 |
+
elif distribution_type == 'poisson':
|
374 |
+
# Poisson distribution - using median as lambda
|
375 |
+
result_gpu = np_random.poisson(overall_median_gpu)
|
376 |
+
elif distribution_type == 'bimodal':
|
377 |
+
# Bimodal distribution - mixture of two normal distributions
|
378 |
+
# First peak centered at 80% of median, second at 120% of median
|
379 |
+
if np_random.random() < 0.5:
|
380 |
+
result_gpu = np_random.normal(overall_median_gpu * 0.8, overall_std_gpu)
|
381 |
+
else:
|
382 |
+
result_gpu = np_random.normal(overall_median_gpu * 1.2, overall_std_gpu)
|
383 |
+
else:
|
384 |
+
raise ValueError("Invalid distribution type. Must be 'normal', 'poisson', or 'bimodal'")
|
385 |
+
|
386 |
sim_array[:, x] = result_gpu
|
387 |
add_array = sim_array
|
388 |
|
|
|
391 |
check_file = pd_concat([overall_file, df2], axis=1)
|
392 |
except:
|
393 |
for x in range(0,total_sims):
|
394 |
+
if distribution_type == 'normal':
|
395 |
+
overall_file[x] = np_random.normal(overall_file['Median'], overall_file['STD'])
|
396 |
+
elif distribution_type == 'poisson':
|
397 |
+
overall_file[x] = np_random.poisson(overall_file['Median'])
|
398 |
+
elif distribution_type == 'bimodal':
|
399 |
+
# Bimodal distribution fallback
|
400 |
+
if np_random.random() < 0.5:
|
401 |
+
overall_file[x] = np_random.normal(overall_file['Median'] * 0.8, overall_file['STD'])
|
402 |
+
else:
|
403 |
+
overall_file[x] = np_random.normal(overall_file['Median'] * 1.2, overall_file['STD'])
|
404 |
check_file = overall_file.copy()
|
405 |
|
406 |
overall_file=check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|