James McCool
commited on
Commit
·
22483d5
1
Parent(s):
9387594
Refactor handling of working portfolio in distribute_preset function to ensure proper checks for empty portfolios and maintain accurate filtering logic. This change improves robustness and clarity in the portfolio processing flow.
Browse files
global_func/distribute_preset.py
CHANGED
@@ -22,16 +22,19 @@ def distribute_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols:
|
|
22 |
print(finish_threshold)
|
23 |
print(lower_threshold)
|
24 |
print(working_portfolio[['Finish_percentile', 'Weighted Own']].sort_values(by='Finish_percentile', ascending=True).head(10))
|
25 |
-
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
if len(concat_portfolio) >= lineup_target:
|
37 |
return concat_portfolio.sort_values(by='Finish_percentile', ascending=True).head(lineup_target)
|
|
|
22 |
print(finish_threshold)
|
23 |
print(lower_threshold)
|
24 |
print(working_portfolio[['Finish_percentile', 'Weighted Own']].sort_values(by='Finish_percentile', ascending=True).head(10))
|
25 |
+
if len(working_portfolio) == 0:
|
26 |
+
continue
|
27 |
+
elif len(working_portfolio) >= 1:
|
28 |
+
curr_own_type_max = working_portfolio.loc[0, 'Weighted Own'] + (slack_var / 20 * working_portfolio.loc[0, 'Weighted Own'])
|
29 |
|
30 |
+
for i in range(1, len(working_portfolio)):
|
31 |
+
if working_portfolio.loc[i, 'Weighted Own'] > curr_own_type_max:
|
32 |
+
rows_to_drop.append(i)
|
33 |
+
else:
|
34 |
+
curr_own_type_max = working_portfolio.loc[i, 'Weighted Own'] + (slack_var / 20 * working_portfolio.loc[i, 'Weighted Own'])
|
35 |
+
|
36 |
+
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
|
37 |
+
concat_portfolio = pd.concat([concat_portfolio, working_portfolio])
|
38 |
|
39 |
if len(concat_portfolio) >= lineup_target:
|
40 |
return concat_portfolio.sort_values(by='Finish_percentile', ascending=True).head(lineup_target)
|