zman35 commited on
Commit
bd6630b
Β·
verified Β·
1 Parent(s): 9026711

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -22
app.py CHANGED
@@ -132,39 +132,76 @@ def equity_curve_plot(df, label="Equity Curve"):
132
  fig.update_layout(title=f"πŸ“ˆ {label}", xaxis_title="Week", yaxis_title="Balance ($)", height=400)
133
  return fig
134
 
135
- # === LINE GRAPH ===
136
- def line_graph_viewer_ui(metric="Final Balance"):
137
- # Generate data for the line graph based on the selected metric
138
  all_metrics = []
139
  for name, config in strategy_presets.items():
140
- _, summary = simulate_tp_strategy_full(
141
- config["starting_balance"], config["trades_min"], config["trades_max"], config["weeks"],
142
- config["tp1_prob"], config["tp2_prob"], config["tp1_r"], config["tp2_r"],
143
- config["base_risk_pct"], config["profit_target"], config["fatigue"], config["trump_vol"]
144
- )
145
- if metric in summary:
146
- all_metrics.append({
147
- "Strategy": name,
148
- metric: summary[metric]
149
- })
 
150
 
151
  df = pd.DataFrame(all_metrics)
152
 
153
- # Generate a line graph of the selected metric
154
- fig = px.line(
155
  df,
156
- x="Strategy",
157
- y=metric,
158
  color="Strategy",
159
- title=f"πŸ“Š Line Graph of {metric}",
160
- labels={metric: f"{metric}"}
 
 
 
161
  )
162
 
163
  fig.update_layout(
164
- xaxis_title="Strategy",
165
- yaxis_title=metric,
 
166
  height=500
167
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  return fig
169
 
170
  # === STRATEGY RUNNERS ===
@@ -204,6 +241,41 @@ def dual_manual_battle(
204
  fig.update_layout(title="βš”οΈ Manual Strategy Battle", xaxis_title="Week", yaxis_title="Balance")
205
  return df_summary, fig
206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  # === LAUNCH INTERFACE ===
208
  app = gr.TabbedInterface(
209
  interface_list=[
@@ -246,7 +318,7 @@ app = gr.TabbedInterface(
246
 
247
  # πŸ“Š Line Graph Viewer Tab
248
  gr.Interface(
249
- fn=line_graph_viewer_ui,
250
  inputs=gr.Dropdown(
251
  choices=["Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"],
252
  label="Select Metric"
 
132
  fig.update_layout(title=f"πŸ“ˆ {label}", xaxis_title="Week", yaxis_title="Balance ($)", height=400)
133
  return fig
134
 
135
+ def generate_histogram(metric="EdgeCast Score", runs=100):
 
 
136
  all_metrics = []
137
  for name, config in strategy_presets.items():
138
+ for _ in range(runs):
139
+ _, summary = simulate_tp_strategy_full(
140
+ config["starting_balance"], config["trades_min"], config["trades_max"], config["weeks"],
141
+ config["tp1_prob"], config["tp2_prob"], config["tp1_r"], config["tp2_r"],
142
+ config["base_risk_pct"], config["profit_target"], config["fatigue"], config["trump_vol"]
143
+ )
144
+ if metric in summary:
145
+ all_metrics.append({
146
+ "Strategy": name,
147
+ metric: summary[metric]
148
+ })
149
 
150
  df = pd.DataFrame(all_metrics)
151
 
152
+ fig = px.histogram(
 
153
  df,
154
+ x=metric,
 
155
  color="Strategy",
156
+ marginal="box",
157
+ opacity=0.75,
158
+ barmode="overlay",
159
+ nbins=30,
160
+ title=f"πŸ“Š Distribution of {metric} Across Strategies"
161
  )
162
 
163
  fig.update_layout(
164
+ xaxis_title=metric,
165
+ yaxis_title="Count",
166
+ bargap=0.1,
167
  height=500
168
  )
169
+
170
+ return fig
171
+
172
+
173
+ def histogram_viewer_ui(metric):
174
+ return generate_histogram(metric)
175
+
176
+ # === ANALYSIS TOOLS ===
177
+ def analytics_dashboard(rank_by="EdgeCast Score"):
178
+ results = []
179
+ for name, config in strategy_presets.items():
180
+ _, summary = simulate_tp_strategy_full(**{k: v for k, v in config.items() if k != "description"})
181
+ summary["Strategy"] = name
182
+ results.append(summary)
183
+ df = pd.DataFrame(results)
184
+ winner_vals = {
185
+ "Final Balance": df["Final Balance"].max(),
186
+ "Sharpe Ratio": df["Sharpe Ratio"].max(),
187
+ "EdgeCast Score": df["EdgeCast Score"].max(),
188
+ "Max Drawdown %": df["Max Drawdown %"].min()
189
+ }
190
+ df = df.sort_values(rank_by, ascending=(rank_by == "Max Drawdown %")).reset_index(drop=True)
191
+ df.insert(0, "πŸ… Rank", [f"#{i+1}" for i in df.index])
192
+ for col in winner_vals:
193
+ df[col] = df[col].apply(lambda x: f"{round(x,2)} πŸ†" if x == winner_vals[col] else f"{round(x,2)}")
194
+ return df[["πŸ… Rank", "Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]
195
+
196
+ def show_descriptions():
197
+ return pd.DataFrame([{"Strategy": name, "Description": cfg["description"]} for name, cfg in strategy_presets.items()])
198
+
199
+ def generate_risk_matrix():
200
+ names = list(strategy_presets.keys())
201
+ scores = {n: simulate_tp_strategy_full(**{k: v for k, v in cfg.items() if k != "description"})[1]["EdgeCast Score"] for n, cfg in strategy_presets.items()}
202
+ matrix = np.array([[abs(scores[a] - scores[b]) for b in names] for a in names])
203
+ fig = px.imshow(matrix, x=names, y=names, text_auto=".2f", color_continuous_scale="RdYlGn_r", labels={"color": "Ξ” Score"})
204
+ fig.update_layout(title="🧠 Risk Matrix (Score Ξ”)", height=600)
205
  return fig
206
 
207
  # === STRATEGY RUNNERS ===
 
241
  fig.update_layout(title="βš”οΈ Manual Strategy Battle", xaxis_title="Week", yaxis_title="Balance")
242
  return df_summary, fig
243
 
244
+ def get_manual_battle_interface():
245
+ return gr.Interface(
246
+ fn=dual_manual_battle,
247
+ inputs=[
248
+ # A Config
249
+ gr.Slider(100, 20000, 2500, label="A: Start Balance"),
250
+ gr.Slider(1, 10, 3, label="A: Trades Min"),
251
+ gr.Slider(1, 15, 7, label="A: Trades Max"),
252
+ gr.Slider(1, 52, 12, label="A: Weeks"),
253
+ gr.Slider(0, 1, 0.3, step=0.05, label="A: TP1 %"),
254
+ gr.Slider(0, 1, 0.3, step=0.05, label="A: TP2 %"),
255
+ gr.Slider(0.1, 5.0, 1.0, step=0.1, label="A: TP1 R"),
256
+ gr.Slider(0.1, 20.0, 2.0, step=0.1, label="A: TP2 R"),
257
+ gr.Slider(0.001, 0.05, 0.01, step=0.001, label="A: Risk %"),
258
+ gr.Slider(0, 100000, 0, step=500, label="A: Profit Target"),
259
+ gr.Slider(0, 1, 0.0, step=0.1, label="A: Fatigue"),
260
+ gr.Slider(0, 1, 0.0, step=0.1, label="A: Trump Volatility"),
261
+ # B Config
262
+ gr.Slider(100, 20000, 2500, label="B: Start Balance"),
263
+ gr.Slider(1, 10, 3, label="B: Trades Min"),
264
+ gr.Slider(1, 15, 7, label="B: Trades Max"),
265
+ gr.Slider(1, 52, 12, label="B: Weeks"),
266
+ gr.Slider(0, 1, 0.3, step=0.05, label="B: TP1 %"),
267
+ gr.Slider(0, 1, 0.3, step=0.05, label="B: TP2 %"),
268
+ gr.Slider(0.1, 5.0, 1.0, step=0.1, label="B: TP1 R"),
269
+ gr.Slider(0.1, 20.0, 2.0, step=0.1, label="B: TP2 R"),
270
+ gr.Slider(0.001, 0.05, 0.01, step=0.001, label="B: Risk %"),
271
+ gr.Slider(0, 100000, 0, step=500, label="B: Profit Target"),
272
+ gr.Slider(0, 1, 0.0, step=0.1, label="B: Fatigue"),
273
+ gr.Slider(0, 1, 0.0, step=0.1, label="B: Trump Volatility")
274
+ ],
275
+ outputs=["dataframe", gr.Plot()],
276
+ title="πŸ§ͺ Manual Strategy Battle"
277
+ )
278
+
279
  # === LAUNCH INTERFACE ===
280
  app = gr.TabbedInterface(
281
  interface_list=[
 
318
 
319
  # πŸ“Š Line Graph Viewer Tab
320
  gr.Interface(
321
+ fn=histogram_viewer_ui,
322
  inputs=gr.Dropdown(
323
  choices=["Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"],
324
  label="Select Metric"