File size: 18,409 Bytes
1cd7f0a
f249395
5c5cf08
f249395
7aba869
f249395
7aba869
f249395
51327ec
f249395
aa9279e
7aba869
f249395
 
 
1cd7f0a
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
 
f249395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14b8549
3155582
f249395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3155582
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
 
 
 
36f047e
f249395
 
 
 
 
 
 
36f047e
f249395
 
 
 
 
14b8549
3155582
f249395
 
 
 
 
 
 
 
 
 
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
 
14b8549
f249395
 
 
 
 
 
 
 
 
 
 
 
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
 
f249395
 
 
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
 
f249395
 
 
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
 
f249395
 
 
 
 
36f047e
f249395
36f047e
f249395
36f047e
f249395
 
 
36f047e
 
f249395
 
 
36f047e
f249395
36f047e
f249395
 
 
 
 
36f047e
f249395
 
 
 
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
36f047e
f249395
 
 
36f047e
f249395
36f047e
f249395
36f047e
 
f249395
 
14b8549
f249395
14b8549
f249395
 
 
 
 
14b8549
3155582
f249395
 
 
1444325
f249395
e7780f0
14b8549
e7780f0
 
f249395
14b8549
 
 
e7780f0
14b8549
f249395
14b8549
3155582
f249395
 
 
14b8549
f249395
14b8549
f249395
14b8549
3155582
f249395
 
 
 
 
 
 
 
 
 
 
 
 
14b8549
f249395
14b8549
f249395
14b8549
f249395
14b8549
f249395
14b8549
f249395
14b8549
f249395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14b8549
f249395
 
 
 
 
 
 
 
 
 
 
 
 
 
14b8549
f249395
14b8549
f249395
14b8549
f249395
14b8549
f249395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14b8549
3155582
f249395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a204cfd
 
 
 
f249395
 
 
 
 
 
a204cfd
 
 
 
f249395
 
a204cfd
 
f249395
b055962
 
 
a204cfd
b055962
f249395
b055962
 
 
a204cfd
b055962
f249395
b055962
a204cfd
f249395
 
a204cfd
 
f249395
 
 
 
 
 
a204cfd
f249395
 
 
 
 
a204cfd
f249395
 
14b8549
f249395
14b8549
3155582
f249395
 
26f0a76
 
e7780f0
 
 
 
 
 
 
 
 
26f0a76
f249395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a204cfd
b055962
 
a204cfd
 
 
 
 
 
 
 
 
 
 
b055962
 
 
 
f249395
 
 
 
9a85080
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f249395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3155582
cdfd163
f249395
 
 
aa9279e
f249395
b2fc8cf
 
f249395
 
 
b2fc8cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
import os

import gradio as gr

import pandas as pd

import numpy as np

import plotly.graph_objs as go

import plotly.express as px




os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"

try:

    gr.analytics_enabled = False

except:

    pass




# πŸ” Strategy Presets

strategy_presets = {

    "Aggressive Prop Trader": {

        "starting_balance": 2500, "trades_min": 5, "trades_max": 10, "weeks": 12,

        "tp1_prob": 0.25, "tp2_prob": 0.4, "tp1_r": 1.2, "tp2_r": 2.4,

        "base_risk_pct": 0.015, "profit_target": None,

        "fatigue": 0.0, "trump_vol": 0.0,

        "description": "High-frequency, high-risk with strong upside potential."

    },

    "Conservative Swing Trader": {

        "starting_balance": 2500, "trades_min": 2, "trades_max": 5, "weeks": 12,

        "tp1_prob": 0.35, "tp2_prob": 0.25, "tp1_r": 0.9, "tp2_r": 1.8,

        "base_risk_pct": 0.01, "profit_target": None,

        "fatigue": 0.0, "trump_vol": 0.0,

        "description": "Lower frequency, prioritizes preservation and steady returns."

    },

    "Momentum Scalper": {

        "starting_balance": 2500, "trades_min": 4, "trades_max": 8, "weeks": 12,

        "tp1_prob": 0.3, "tp2_prob": 0.35, "tp1_r": 1.0, "tp2_r": 2.2,

        "base_risk_pct": 0.012, "profit_target": None,

        "fatigue": 0.0, "trump_vol": 0.0,

        "description": "Intraday momentum strategy for fast-paced trading windows."

    },

    "Swing Sniper": {

        "starting_balance": 2500, "trades_min": 2, "trades_max": 4, "weeks": 12,

        "tp1_prob": 0.2, "tp2_prob": 0.5, "tp1_r": 1.1, "tp2_r": 3.0,

        "base_risk_pct": 0.008, "profit_target": None,

        "fatigue": 0.0, "trump_vol": 0.0,

        "description": "Selective entries with high RR setups. Less frequent."

    },

    "Intraday Prop Mode": {

        "starting_balance": 2500, "trades_min": 3, "trades_max": 7, "weeks": 12,

        "tp1_prob": 0.3, "tp2_prob": 0.3, "tp1_r": 1.0, "tp2_r": 2.0,

        "base_risk_pct": 0.02, "profit_target": None,

        "fatigue": 0.0, "trump_vol": 0.0,

        "description": "Intraday consistency with a balanced reward profile."

    }

}

def get_scaled_risk_pct(balance, base_risk_pct):

    if balance < 5000:

        return base_risk_pct

    elif balance < 10000:

        return base_risk_pct * 0.75

    elif balance < 20000:

        return base_risk_pct * 0.5

    else:

        return base_risk_pct * 0.25




def simulate_tp_strategy_full(starting_balance, trades_min, trades_max, weeks,

                              tp1_prob, tp2_prob, tp1_r, tp2_r, base_risk_pct,

                              profit_target=None, fatigue=0.0, trump_vol=0.0):

    if tp1_prob + tp2_prob >= 1.0:

        return pd.DataFrame(), {"Error": "Invalid probability config. TP1 + TP2 must be < 1.0"}




    sl_prob = 1.0 - tp1_prob - tp2_prob

    balance = starting_balance

    peak = balance

    drawdown = 0

    tp1_hits = tp2_hits = sl_hits = 0

    max_win_streak = max_loss_streak = 0

    cur_win_streak = cur_loss_streak = 0

    log = []




    fatigue_multiplier = 1.0 - fatigue * 0.4  # Reduce reward at high fatigue

    trump_vol_factor = np.random.normal(1.0, 0.2 * trump_vol)  # Adds chaos




    for week in range(1, weeks + 1):

        if profit_target and balance >= profit_target: break

        week_start = balance

        num_trades = np.random.randint(trades_min, trades_max + 1)

        for _ in range(num_trades):

            risk_pct = get_scaled_risk_pct(balance, base_risk_pct)

            risk_amount = balance * risk_pct * np.random.uniform(0.9, 1.1)  # Risk % w/ some variability

            risk_amount *= trump_vol_factor  # 🟠 Vol boost




            # Fatigue loss streak logic

            if fatigue > 0.6 and cur_loss_streak >= 3 and np.random.rand() < fatigue * 0.25:

                outcome = "SL"

            else:

                outcome = np.random.choice(["TP1", "TP2", "SL"], p=[tp1_prob, tp2_prob, sl_prob])




            if outcome == "TP1":

                balance += risk_amount * tp1_r * fatigue_multiplier

                tp1_hits += 1

                cur_win_streak += 1

                cur_loss_streak = 0

            elif outcome == "TP2":

                balance += risk_amount * tp2_r * fatigue_multiplier

                tp2_hits += 1

                cur_win_streak += 1

                cur_loss_streak = 0

            else:

                balance -= risk_amount

                sl_hits += 1

                cur_loss_streak += 1

                cur_win_streak = 0




            max_win_streak = max(max_win_streak, cur_win_streak)

            max_loss_streak = max(max_loss_streak, cur_loss_streak)

            peak = max(peak, balance)

            drawdown = max(drawdown, (peak - balance) / peak * 100)




        weekly_return = (balance - week_start) / week_start * 100

        log.append({

            "Week": week, "Start Balance": round(week_start, 2),

            "End Balance": round(balance, 2),

            "Weekly Return (%)": round(weekly_return, 2)

        })




    df = pd.DataFrame(log)

    returns = df["End Balance"].pct_change().dropna()

    volatility = returns.std() * np.sqrt(52)

    sharpe_ratio = returns.mean() / returns.std() * np.sqrt(52) if returns.std() > 0 else 0

    score = balance / (1 + drawdown)




    summary = {

        "Final Balance": round(balance, 2),

        "TP1 Hits": tp1_hits,

        "TP2 Hits": tp2_hits,

        "SL Hits": sl_hits,

        "Max Drawdown %": round(drawdown, 2),

        "Max Win Streak": max_win_streak,

        "Max Loss Streak": max_loss_streak,

        "Sharpe Ratio": round(sharpe_ratio, 2),

        "EdgeCast Score": round(score, 2)

    }

    return df, summary

# πŸ“ˆ Plot

def equity_curve_plot(df, label="Equity Curve"):

    fig = go.Figure()

    fig.add_trace(go.Scatter(x=df["Week"], y=df["End Balance"], mode='lines+markers', name=label))

    fig.update_layout(title=f'πŸ“ˆ {label}', xaxis_title='Week', yaxis_title='Balance ($)', height=400)

    return fig




# 🎯 Preset Tab

def run_preset_strategy_with_toggle(style, enable_fatigue, fatigue, enable_trump, trump_vol):
    config = strategy_presets[style]
    applied_fatigue = fatigue if enable_fatigue else 0.0
    applied_trump = trump_vol if enable_trump else 0.0

    df, summary = simulate_tp_strategy_full(
        config["starting_balance"], config["trades_min"], config["trades_max"], config["weeks"],
        config["tp1_prob"], config["tp2_prob"], config["tp1_r"], config["tp2_r"],
        config["base_risk_pct"], config["profit_target"], applied_fatigue, applied_trump
    )

    return df, summary, equity_curve_plot(df, style), config["description"]


# πŸ› οΈ Manual Tab

def run_manual_sim(starting_balance, trades_min, trades_max, weeks,

                   tp1_prob, tp2_prob, tp1_r, tp2_r, base_risk_pct, profit_target,

                   fatigue, trump_vol):

    df, summary = simulate_tp_strategy_full(starting_balance, trades_min, trades_max, weeks,

                                            tp1_prob, tp2_prob, tp1_r, tp2_r, base_risk_pct,

                                            profit_target, fatigue, trump_vol)

    chart = equity_curve_plot(df, "Manual Config")

    return df, summary, chart


# βš”οΈ Manual Battle Mode (Dual Sim)

def dual_manual_battle(

    sb1, tmin1, tmax1, w1, tp1a, tp2a, r1a, r2a, risk1, pt1, fat1, trump1,

    sb2, tmin2, tmax2, w2, tp1b, tp2b, r1b, r2b, risk2, pt2, fat2, trump2

):

    df1, s1 = simulate_tp_strategy_full(sb1, tmin1, tmax1, w1, tp1a, tp2a, r1a, r2a, risk1, pt1, fat1, trump1)

    df2, s2 = simulate_tp_strategy_full(sb2, tmin2, tmax2, w2, tp1b, tp2b, r1b, r2b, risk2, pt2, fat2, trump2)




    s1["Strategy"] = "Manual A"

    s2["Strategy"] = "Manual B"




    comparison_df = pd.DataFrame([s1, s2])

    comparison_df = comparison_df[["Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]




    # πŸ† Winners

    for col in ["Final Balance", "Sharpe Ratio", "EdgeCast Score"]:

        best_val = comparison_df[col].astype(float).max()

        comparison_df[col] = [

            f"{val} πŸ†" if float(val) == best_val else f"{val}" for val in comparison_df[col]

        ]




    # Chart

    fig = go.Figure()

    fig.add_trace(go.Scatter(x=df1["Week"], y=df1["End Balance"], name="Manual A"))

    fig.add_trace(go.Scatter(x=df2["Week"], y=df2["End Balance"], name="Manual B"))

    fig.update_layout(title="βš”οΈ Manual Strategy Battle", xaxis_title="Week", yaxis_title="Balance")




    return comparison_df, fig

# πŸ“Š Leaderboard Tab

def analytics_dashboard(rank_by="EdgeCast Score"):

    results = []

    for name, config in strategy_presets.items():

        _, summary = simulate_tp_strategy_full(**{k: v for k, v in config.items() if k != "description"})

        summary["Strategy"] = name

        results.append(summary)




    df = pd.DataFrame(results)




    # Get numeric winners before formatting

    winner_vals = {

        "Final Balance": df["Final Balance"].max(),

        "Sharpe Ratio": df["Sharpe Ratio"].max(),

        "EdgeCast Score": df["EdgeCast Score"].max(),

        "Max Drawdown %": df["Max Drawdown %"].min()

    }




    # Sort leaderboard by selected metric

    ascending = rank_by == "Max Drawdown %"

    df = df.sort_values(rank_by, ascending=ascending).reset_index(drop=True)




    # Rank column

    df.insert(0, "πŸ… Rank", [f"#{i+1}" for i in df.index])




    # πŸ† Emoji highlights

    for col in winner_vals:

        df[col] = df[col].apply(lambda x: f"{round(x, 2)} πŸ†" if x == winner_vals[col] else f"{round(x, 2)}")




    return df[["πŸ… Rank", "Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]







# πŸ“˜ Description Tab

def show_descriptions():

    return pd.DataFrame([

        {"Strategy": name, "Description": config["description"]}

        for name, config in strategy_presets.items()

    ])







# πŸ”¬ Risk Matrix Heatmap

def generate_risk_matrix():

    names = list(strategy_presets.keys())

    scores = {

        name: simulate_tp_strategy_full(**{k: v for k, v in cfg.items() if k != "description"})[1]["EdgeCast Score"]

        for name, cfg in strategy_presets.items()

    }

    matrix = np.zeros((len(names), len(names)))

    for i, a in enumerate(names):

        for j, b in enumerate(names):

            matrix[i, j] = abs(scores[a] - scores[b])




    fig = px.imshow(

        matrix,

        x=names,

        y=names,

        text_auto=".2f",

        color_continuous_scale="RdYlGn_r",

        labels={"color": "Score Ξ”"},

        title="🧠 Risk Matrix (Ξ” Score Heatmap)"

    )

    fig.update_traces(

        hovertemplate="<b>%{y}</b> vs <b>%{x}</b><br>Ξ” Score: %{z:.2f}<extra></extra>"

    )

    return fig







# πŸ₯Š Battle Strategies (Preset vs Preset)

def battle_strategies(
    style1, enable_fatigue1, fatigue1, enable_trump1, trump1,
    style2, enable_fatigue2, fatigue2, enable_trump2, trump2
):
    if style1 == "None" or style2 == "None":
        return pd.DataFrame([{"⚠️ Error": "Please select two valid strategies."}]), go.Figure()

    if style1 == style2:
        return pd.DataFrame([{"⚠️ Error": "Please select two different strategies."}]), go.Figure()

    fatigue_a = fatigue1 if enable_fatigue1 else 0.0
    trump_a = trump1 if enable_trump1 else 0.0
    fatigue_b = fatigue2 if enable_fatigue2 else 0.0
    trump_b = trump2 if enable_trump2 else 0.0

    try:
        config1 = strategy_presets[style1]
        config2 = strategy_presets[style2]

        df1, s1 = simulate_tp_strategy_full(
            config1["starting_balance"], config1["trades_min"], config1["trades_max"], config1["weeks"],
            config1["tp1_prob"], config1["tp2_prob"], config1["tp1_r"], config1["tp2_r"],
            config1["base_risk_pct"], config1["profit_target"], fatigue_a, trump_a
        )

        df2, s2 = simulate_tp_strategy_full(
            config2["starting_balance"], config2["trades_min"], config2["trades_max"], config2["weeks"],
            config2["tp1_prob"], config2["tp2_prob"], config2["tp1_r"], config2["tp2_r"],
            config2["base_risk_pct"], config2["profit_target"], fatigue_b, trump_b
        )

        s1["Strategy"], s2["Strategy"] = style1, style2
        df_compare = pd.DataFrame([s1, s2])[["Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]

        for col in ["Final Balance", "Sharpe Ratio", "EdgeCast Score"]:
            best_val = df_compare[col].astype(float).max()
            df_compare[col] = [f"{val} πŸ†" if float(val) == best_val else val for val in df_compare[col]]

        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}", xaxis_title="Week", yaxis_title="Balance")

        return df_compare, fig

    except Exception as e:
        return pd.DataFrame([{"Error": str(e)}]), go.Figure()



# πŸš€ App UI Launch

app = gr.TabbedInterface(

    interface_list=[

        # 🎯 Preset Mode

    gr.Interface(
        fn=run_preset_strategy_with_toggle,
    inputs=[
        gr.Dropdown(choices=list(strategy_presets.keys()), label="Select Strategy"),
        gr.Checkbox(label="Enable Fatigue"), 
        gr.Slider(0, 1, 0.0, step=0.1, label="Fatigue Level"),
        gr.Checkbox(label="Enable Trump Volatility"),
        gr.Slider(0, 1, 0.0, step=0.1, label="Trump Volatility Index")
    ],
    outputs=["dataframe", "json", gr.Plot(), "text"],
    title="🎯 Preset Mode"
),

        # πŸ› οΈ Manual Config

        gr.Interface(

            fn=run_manual_sim,

            inputs=[

                gr.Slider(100, 20000, 2500, label="Start Balance"),

                gr.Slider(1, 10, 3, label="Trades Min"),

                gr.Slider(1, 15, 7, label="Trades Max"),

                gr.Slider(1, 52, 12, label="Weeks"),

                gr.Slider(0, 1, 0.3, step=0.05, label="TP1 %"),

                gr.Slider(0, 1, 0.3, step=0.05, label="TP2 %"),

                gr.Slider(0.1, 5.0, 1.0, step=0.1, label="TP1 R"),

                gr.Slider(0.1, 20.0, 2.0, step=0.1, label="TP2 R"),

                gr.Slider(0.001, 0.05, 0.01, step=0.001, label="Risk %"),

                gr.Slider(0, 100000, 0, step=500, label="Profit Target πŸ’°"),

                gr.Slider(0, 1, 0.0, step=0.1, label="Fatigue Level"),

                gr.Slider(0, 1, 0.0, step=0.1, label="Trump Volatility Index")

            ],

            outputs=["dataframe", "json", gr.Plot()],

            title="πŸ› οΈ Manual Config"

        ),




        # πŸ₯Š Battle Mode – Preset

       gr.Interface(
    fn=battle_strategies,
    inputs=[
        gr.Dropdown(choices=["None"] + list(strategy_presets.keys()), value="None", label="Strategy A"),
        gr.Checkbox(label="Enable Fatigue for A"),
        gr.Slider(0, 1, 0.0, step=0.1, label="Fatigue Level A"),
        gr.Checkbox(label="Enable Trump Volatility for A"),
        gr.Slider(0, 1, 0.0, step=0.1, label="Trump Volatility A"),

        gr.Dropdown(choices=["None"] + list(strategy_presets.keys()), value="None", label="Strategy B"),
        gr.Checkbox(label="Enable Fatigue for B"),
        gr.Slider(0, 1, 0.0, step=0.1, label="Fatigue Level B"),
        gr.Checkbox(label="Enable Trump Volatility for B"),
        gr.Slider(0, 1, 0.0, step=0.1, label="Trump Volatility B"),
    ],
    outputs=["dataframe", gr.Plot()],
    title="πŸ₯Š Battle Mode"
),


        # πŸ§ͺ Manual Battle Mode

        # πŸ§ͺ Manual Battle Mode (Slider Version)
gr.Interface(
    fn=dual_manual_battle,
    inputs=[
        # Config A
        gr.Slider(100, 20000, 2500, label="A: Start Balance"),
        gr.Slider(1, 10, 3, label="A: Trades Min"),
        gr.Slider(1, 15, 7, label="A: Trades Max"),
        gr.Slider(1, 52, 12, label="A: Weeks"),
        gr.Slider(0, 1, 0.3, step=0.05, label="A: TP1 %"),
        gr.Slider(0, 1, 0.3, step=0.05, label="A: TP2 %"),
        gr.Slider(0.1, 5.0, 1.0, step=0.1, label="A: TP1 R"),
        gr.Slider(0.1, 20.0, 2.0, step=0.1, label="A: TP2 R"),
        gr.Slider(0.001, 0.05, 0.01, step=0.001, label="A: Risk %"),
        gr.Slider(0, 100000, 0, step=500, label="A: Profit Target"),
        gr.Slider(0, 1, 0.0, step=0.1, label="A: Fatigue"),
        gr.Slider(0, 1, 0.0, step=0.1, label="A: Trump Volatility"),
        # Config B
        gr.Slider(100, 20000, 2500, label="B: Start Balance"),
        gr.Slider(1, 10, 3, label="B: Trades Min"),
        gr.Slider(1, 15, 7, label="B: Trades Max"),
        gr.Slider(1, 52, 12, label="B: Weeks"),
        gr.Slider(0, 1, 0.3, step=0.05, label="B: TP1 %"),
        gr.Slider(0, 1, 0.3, step=0.05, label="B: TP2 %"),
        gr.Slider(0.1, 5.0, 1.0, step=0.1, label="B: TP1 R"),
        gr.Slider(0.1, 20.0, 2.0, step=0.1, label="B: TP2 R"),
        gr.Slider(0.001, 0.05, 0.01, step=0.001, label="B: Risk %"),
        gr.Slider(0, 100000, 0, step=500, label="B: Profit Target"),
        gr.Slider(0, 1, 0.0, step=0.1, label="B: Fatigue"),
        gr.Slider(0, 1, 0.0, step=0.1, label="B: Trump Volatility")
    ],
    outputs=["dataframe", gr.Plot()],
    title="πŸ§ͺ Manual Battle Mode"
),

        # πŸ“Š Analytics Leaderboard

        gr.Interface(

            fn=analytics_dashboard,

            inputs=gr.Dropdown(

                choices=["EdgeCast Score", "Final Balance", "Sharpe Ratio", "Max Drawdown %"],

                value="EdgeCast Score",

                label="Sort leaderboard by:"

            ),

            outputs="dataframe",

            title="πŸ“Š Analytics Leaderboard"

        ),




        # πŸ“˜ Strategy Descriptions

        gr.Interface(

            fn=show_descriptions,

            inputs=[], outputs="dataframe",

            title="πŸ“˜ Strategy Descriptions"

        ),




        # πŸ”¬ Risk Matrix Heatmap

        gr.Interface(

            fn=generate_risk_matrix,

            inputs=[], outputs=gr.Plot(),

            title="πŸ”¬ Risk Matrix"

        )

    ],

    tab_names=["Preset", "Manual", "Battle", "Manual Battle", "Analytics", "Descriptions", "Risk Matrix"],

    title="EdgeCast – Strategy Simulation Suite"

)




app.launch()