Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -150,30 +150,38 @@ def run_manual_sim(starting_balance, trades_min, trades_max, weeks,
|
|
| 150 |
|
| 151 |
# π₯ Battle Tab
|
| 152 |
def battle_strategies(style1, style2):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
if style1 == style2:
|
| 154 |
-
return pd.DataFrame([{
|
| 155 |
-
"Error": "Select two different strategies for Battle Mode."
|
| 156 |
-
}]), go.Figure()
|
| 157 |
|
|
|
|
| 158 |
df1, s1 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style1].items() if k != "description"})
|
| 159 |
df2, s2 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style2].items() if k != "description"})
|
| 160 |
|
|
|
|
| 161 |
s1["Strategy"] = style1
|
| 162 |
s2["Strategy"] = style2
|
| 163 |
df_compare = pd.DataFrame([s1, s2])
|
| 164 |
df_compare = df_compare[["Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]
|
| 165 |
|
| 166 |
-
#
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
-
# π
|
| 171 |
fig = go.Figure()
|
| 172 |
fig.add_trace(go.Scatter(x=df1["Week"], y=df1["End Balance"], name=style1))
|
| 173 |
fig.add_trace(go.Scatter(x=df2["Week"], y=df2["End Balance"], name=style2))
|
| 174 |
fig.update_layout(title=f"π₯ {style1} vs {style2} β Battle Equity Curves", xaxis_title="Week", yaxis_title="Balance")
|
| 175 |
|
| 176 |
-
return
|
|
|
|
| 177 |
|
| 178 |
|
| 179 |
# π Leaderboard Tab
|
|
|
|
| 150 |
|
| 151 |
# π₯ Battle Tab
|
| 152 |
def battle_strategies(style1, style2):
|
| 153 |
+
# π§ Defensive logic for dropdown edge cases
|
| 154 |
+
if not style1 or not style2:
|
| 155 |
+
return pd.DataFrame([{"Error": "β οΈ Please select both strategies before submitting."}]), go.Figure()
|
| 156 |
+
|
| 157 |
if style1 == style2:
|
| 158 |
+
return pd.DataFrame([{"Error": "β Choose two different strategies to compare."}]), go.Figure()
|
|
|
|
|
|
|
| 159 |
|
| 160 |
+
# π Run both simulations
|
| 161 |
df1, s1 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style1].items() if k != "description"})
|
| 162 |
df2, s2 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style2].items() if k != "description"})
|
| 163 |
|
| 164 |
+
# π
Structure results
|
| 165 |
s1["Strategy"] = style1
|
| 166 |
s2["Strategy"] = style2
|
| 167 |
df_compare = pd.DataFrame([s1, s2])
|
| 168 |
df_compare = df_compare[["Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]
|
| 169 |
|
| 170 |
+
# β
Bold winners in each metric
|
| 171 |
+
def highlight_winner(col):
|
| 172 |
+
is_best = df_compare[col] == df_compare[col].max()
|
| 173 |
+
return ['background-color: #d4edda; font-weight: bold' if val else '' for val in is_best]
|
| 174 |
+
|
| 175 |
+
styled = df_compare.style.apply(highlight_winner, subset=["Final Balance", "Sharpe Ratio", "EdgeCast Score"])
|
| 176 |
|
| 177 |
+
# π Chart
|
| 178 |
fig = go.Figure()
|
| 179 |
fig.add_trace(go.Scatter(x=df1["Week"], y=df1["End Balance"], name=style1))
|
| 180 |
fig.add_trace(go.Scatter(x=df2["Week"], y=df2["End Balance"], name=style2))
|
| 181 |
fig.update_layout(title=f"π₯ {style1} vs {style2} β Battle Equity Curves", xaxis_title="Week", yaxis_title="Balance")
|
| 182 |
|
| 183 |
+
return styled, fig
|
| 184 |
+
|
| 185 |
|
| 186 |
|
| 187 |
# π Leaderboard Tab
|