Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 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 |
-
_
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
| 150 |
|
| 151 |
df = pd.DataFrame(all_metrics)
|
| 152 |
|
| 153 |
-
|
| 154 |
-
fig = px.line(
|
| 155 |
df,
|
| 156 |
-
x=
|
| 157 |
-
y=metric,
|
| 158 |
color="Strategy",
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
| 161 |
)
|
| 162 |
|
| 163 |
fig.update_layout(
|
| 164 |
-
xaxis_title=
|
| 165 |
-
yaxis_title=
|
|
|
|
| 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=
|
| 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"
|