zman35 commited on
Commit
c3a54e9
Β·
verified Β·
1 Parent(s): 564529d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
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
- # πŸ§ͺ Optional: add plain-text winner tag
167
- winner = df_compare.loc[df_compare["EdgeCast Score"].idxmax(), "Strategy"]
168
- df_compare["πŸ† Winner"] = df_compare["Strategy"].apply(lambda x: "βœ…" if x == winner else "")
 
 
 
169
 
170
- # πŸ“ˆ Plot Equity Curve
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 df_compare, fig
 
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