Spaces:
Sleeping
Sleeping
Update app.py
Browse files149 unmodified lines150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192149 unmodified lines# π₯ Battle Tabdef battle_strategies(style1, style2):# Handle unselected or duplicate strategiesif style1 == "None" or style2 == "None":return pd.DataFrame([{"Error": "β οΈ Please select two valid strategies."}]), go.Figure()if style1 == style2:return pd.DataFrame([{"Error": "β οΈ Select two *different* strategies to compare."}]), go.Figure()# Simulate both strategiesdf1, s1 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style1].items() if k != "description"})df2, s2 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style2].items() if k != "description"})# Add labelss1["Strategy"] = style1s2["Strategy"] = style2# Build comparison DataFramedf_compare = pd.DataFrame([s1, s2])df_compare = df_compare[["Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]# Highlight best values in each metricdef highlight_winner(col):return ['background-color: #d4edda; font-weight: bold' if val else '' for val in df_compare[col] == df_compare[col].max()]styled = df_compare.style.apply(highlight_winner, subset=["Final Balance", "Sharpe Ratio", "EdgeCast Score"])# Plot equity curvesfig = go.Figure()fig.add_trace(go.Scatter(x=df1["Week"], y=df1["End Balance"], name=style1))fig.add_trace(go.Scatter(x=df2["Week"], y=df2["End Balance"], name=style2))fig.update_layout(title=f"π₯ {style1} vs {style2}", xaxis_title="Week", yaxis_title="Balance")return styled, figexcept Exception as e:df_fallback = pd.DataFrame([{"Error": f"π¨ Internal error occurred: {str(e)}"}])return df_fallback, go.Figure()# π Leaderboard Tab149 unmodified lines150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189149 unmodified lines# π₯ Battle Tabdef battle_strategies(style1, style2):if style1 == "None" or style2 == "None" or style1 == style2:return (pd.DataFrame([{"Error": "Please select two *different* strategies."}]),go.Figure())try:df1, s1 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style1].items() if k != "description"})df2, s2 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style2].items() if k != "description"})s1["Strategy"] = style1s2["Strategy"] = style2df_compare = pd.DataFrame([s1, s2])df_compare = df_compare[["Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]# Highlight winnersdef highlight_winner(col):is_best = df_compare[col] == df_compare[col].max()return ['background-color: #d4edda; font-weight: bold' if val else '' for val in is_best]styled = df_compare.style.apply(highlight_winner, subset=["Final Balance", "Sharpe Ratio", "EdgeCast Score"])fig = go.Figure()fig.add_trace(go.Scatter(x=df1["Week"], y=df1["End Balance"], name=style1))fig.add_trace(go.Scatter(x=df2["Week"], y=df2["End Balance"], name=style2))fig.update_layout(title=f"π₯ {style1} vs {style2} β Battle Equity Curves", xaxis_title="Week", yaxis_title="Balance")return styled, figexcept Exception as e:return (pd.DataFrame([{"Error": f"β οΈ Something went wrong: {str(e)}"}]),go.Figure())# π Leaderboard Tab
app.py+26-29