zman35 commited on
Commit
1049c61
Β·
verified Β·
1 Parent(s): 2419d33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -151,40 +151,38 @@ def run_manual_sim(starting_balance, trades_min, trades_max, weeks,
151
  # πŸ₯Š Battle Tab
152
  def battle_strategies(style1, style2):
153
  if style1 == "None" or style2 == "None":
154
- # Display error in a friendly way if user hasn't selected both
155
- return pd.DataFrame([{"⚠️ Error": "Please select two valid strategies before submitting."}]), go.Figure()
156
 
157
  if style1 == style2:
158
- return pd.DataFrame([{"⚠️ Error": "Please select two different strategies to compare."}]), go.Figure()
159
 
160
  try:
161
- # Run simulations for both
162
  df1, s1 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style1].items() if k != "description"})
163
  df2, s2 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style2].items() if k != "description"})
164
 
165
  s1["Strategy"] = style1
166
  s2["Strategy"] = style2
167
 
168
- df_compare = pd.DataFrame([s1, s2])
169
- df_compare = df_compare[["Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]
170
 
171
- # Highlight winner
172
- def highlight_winner(col):
173
- is_best = df_compare[col] == df_compare[col].max()
174
- return ['background-color: #d4edda; font-weight: bold' if val else '' for val in is_best]
 
 
175
 
176
- styled_df = df_compare.style.apply(highlight_winner, subset=["Final Balance", "Sharpe Ratio", "EdgeCast Score"])
177
-
178
- # Plot chart
179
  fig = go.Figure()
180
  fig.add_trace(go.Scatter(x=df1["Week"], y=df1["End Balance"], name=style1))
181
  fig.add_trace(go.Scatter(x=df2["Week"], y=df2["End Balance"], name=style2))
182
- fig.update_layout(title=f"πŸ₯Š {style1} vs {style2} – Equity Curve", xaxis_title="Week", yaxis_title="Balance")
183
 
184
- return styled_df, fig
185
 
186
  except Exception as e:
187
- return pd.DataFrame([{"⚠️ Unexpected Error": str(e)}]), go.Figure()
188
 
189
 
190
  # πŸ“Š Leaderboard Tab
 
151
  # πŸ₯Š Battle Tab
152
  def battle_strategies(style1, style2):
153
  if style1 == "None" or style2 == "None":
154
+ return pd.DataFrame([{"⚠️ Error": "Please select two valid strategies."}]), go.Figure()
 
155
 
156
  if style1 == style2:
157
+ return pd.DataFrame([{"⚠️ Error": "Please select two different strategies."}]), go.Figure()
158
 
159
  try:
 
160
  df1, s1 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style1].items() if k != "description"})
161
  df2, s2 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style2].items() if k != "description"})
162
 
163
  s1["Strategy"] = style1
164
  s2["Strategy"] = style2
165
 
166
+ comparison_df = pd.DataFrame([s1, s2])
167
+ comparison_df = comparison_df[["Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]
168
 
169
+ # Add πŸ† for each best column
170
+ for col in ["Final Balance", "Sharpe Ratio", "EdgeCast Score"]:
171
+ best_val = comparison_df[col].max()
172
+ comparison_df[col] = [
173
+ f"{val} πŸ†" if val == best_val else f"{val}" for val in comparison_df[col]
174
+ ]
175
 
176
+ # Chart both curves
 
 
177
  fig = go.Figure()
178
  fig.add_trace(go.Scatter(x=df1["Week"], y=df1["End Balance"], name=style1))
179
  fig.add_trace(go.Scatter(x=df2["Week"], y=df2["End Balance"], name=style2))
180
+ fig.update_layout(title=f"πŸ₯Š {style1} vs {style2}", xaxis_title="Week", yaxis_title="Balance")
181
 
182
+ return comparison_df, fig
183
 
184
  except Exception as e:
185
+ return pd.DataFrame([{"Error": str(e)}]), go.Figure()
186
 
187
 
188
  # πŸ“Š Leaderboard Tab