zman35 commited on
Commit
b055962
Β·
verified Β·
1 Parent(s): 26f0a76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -63
app.py CHANGED
@@ -550,79 +550,49 @@ def generate_risk_matrix():
550
 
551
  # πŸ₯Š Battle Strategies (Preset vs Preset)
552
 
553
- def battle_strategies(style1, style2):
554
-
555
  if style1 == "None" or style2 == "None":
556
-
557
  return pd.DataFrame([{"⚠️ Error": "Please select two valid strategies."}]), go.Figure()
558
 
559
-
560
-
561
-
562
  if style1 == style2:
563
-
564
  return pd.DataFrame([{"⚠️ Error": "Please select two different strategies."}]), go.Figure()
565
 
566
-
567
-
568
 
569
  try:
 
 
570
 
571
- df1, s1 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style1].items() if k != "description"})
572
-
573
- df2, s2 = simulate_tp_strategy_full(**{k: v for k, v in strategy_presets[style2].items() if k != "description"})
574
-
575
-
576
-
577
-
578
- s1["Strategy"] = style1
579
-
580
- s2["Strategy"] = style2
581
-
582
-
583
-
584
-
585
- comparison_df = pd.DataFrame([s1, s2])
586
-
587
- comparison_df = comparison_df[["Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]
588
-
589
 
 
 
 
 
 
590
 
 
 
591
 
592
  for col in ["Final Balance", "Sharpe Ratio", "EdgeCast Score"]:
593
-
594
  best_val = comparison_df[col].astype(float).max()
595
-
596
- comparison_df[col] = [
597
-
598
- f"{val} πŸ†" if float(val) == best_val else val for val in comparison_df[col]
599
-
600
- ]
601
-
602
-
603
-
604
 
605
  fig = go.Figure()
606
-
607
  fig.add_trace(go.Scatter(x=df1["Week"], y=df1["End Balance"], name=style1))
608
-
609
  fig.add_trace(go.Scatter(x=df2["Week"], y=df2["End Balance"], name=style2))
610
-
611
  fig.update_layout(title=f"πŸ₯Š {style1} vs {style2}", xaxis_title="Week", yaxis_title="Balance")
612
 
613
-
614
-
615
-
616
  return comparison_df, fig
617
 
618
-
619
-
620
-
621
  except Exception as e:
622
-
623
  return pd.DataFrame([{"Error": str(e)}]), go.Figure()
624
 
625
-
626
 
627
  # πŸš€ App UI Launch
628
 
@@ -691,22 +661,19 @@ app = gr.TabbedInterface(
691
  # πŸ₯Š Battle Mode – Preset
692
 
693
  gr.Interface(
 
 
 
 
 
 
 
 
 
 
 
 
694
 
695
- fn=battle_strategies,
696
-
697
- inputs=[
698
-
699
- gr.Dropdown(choices=["None"] + list(strategy_presets.keys()), value="None", label="Strategy 1"),
700
-
701
- gr.Dropdown(choices=["None"] + list(strategy_presets.keys()), value="None", label="Strategy 2")
702
-
703
- ],
704
-
705
- outputs=["dataframe", gr.Plot()],
706
-
707
- title="πŸ₯Š Battle Mode"
708
-
709
- ),
710
 
711
 
712
 
 
550
 
551
  # πŸ₯Š Battle Strategies (Preset vs Preset)
552
 
553
+ def battle_strategies(style1, style2, enable_fatigue, fatigue_level, enable_trump, trump_vol_level):
 
554
  if style1 == "None" or style2 == "None":
 
555
  return pd.DataFrame([{"⚠️ Error": "Please select two valid strategies."}]), go.Figure()
556
 
 
 
 
557
  if style1 == style2:
 
558
  return pd.DataFrame([{"⚠️ Error": "Please select two different strategies."}]), go.Figure()
559
 
560
+ fatigue = fatigue_level if enable_fatigue else 0.0
561
+ trump_vol = trump_vol_level if enable_trump else 0.0
562
 
563
  try:
564
+ config1 = strategy_presets[style1].copy()
565
+ config2 = strategy_presets[style2].copy()
566
 
567
+ df1, s1 = simulate_tp_strategy_full(
568
+ config1["starting_balance"], config1["trades_min"], config1["trades_max"], config1["weeks"],
569
+ config1["tp1_prob"], config1["tp2_prob"], config1["tp1_r"], config1["tp2_r"],
570
+ config1["base_risk_pct"], config1["profit_target"], fatigue, trump_vol
571
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
572
 
573
+ df2, s2 = simulate_tp_strategy_full(
574
+ config2["starting_balance"], config2["trades_min"], config2["trades_max"], config2["weeks"],
575
+ config2["tp1_prob"], config2["tp2_prob"], config2["tp1_r"], config2["tp2_r"],
576
+ config2["base_risk_pct"], config2["profit_target"], fatigue, trump_vol
577
+ )
578
 
579
+ s1["Strategy"], s2["Strategy"] = style1, style2
580
+ comparison_df = pd.DataFrame([s1, s2])[["Strategy", "Final Balance", "Sharpe Ratio", "EdgeCast Score", "Max Drawdown %"]]
581
 
582
  for col in ["Final Balance", "Sharpe Ratio", "EdgeCast Score"]:
 
583
  best_val = comparison_df[col].astype(float).max()
584
+ comparison_df[col] = [f"{val} πŸ†" if float(val) == best_val else val for val in comparison_df[col]]
 
 
 
 
 
 
 
 
585
 
586
  fig = go.Figure()
 
587
  fig.add_trace(go.Scatter(x=df1["Week"], y=df1["End Balance"], name=style1))
 
588
  fig.add_trace(go.Scatter(x=df2["Week"], y=df2["End Balance"], name=style2))
 
589
  fig.update_layout(title=f"πŸ₯Š {style1} vs {style2}", xaxis_title="Week", yaxis_title="Balance")
590
 
 
 
 
591
  return comparison_df, fig
592
 
 
 
 
593
  except Exception as e:
 
594
  return pd.DataFrame([{"Error": str(e)}]), go.Figure()
595
 
 
596
 
597
  # πŸš€ App UI Launch
598
 
 
661
  # πŸ₯Š Battle Mode – Preset
662
 
663
  gr.Interface(
664
+ fn=battle_strategies,
665
+ inputs=[
666
+ gr.Dropdown(choices=["None"] + list(strategy_presets.keys()), value="None", label="Strategy 1"),
667
+ gr.Dropdown(choices=["None"] + list(strategy_presets.keys()), value="None", label="Strategy 2"),
668
+ gr.Checkbox(label="Enable Fatigue"),
669
+ gr.Slider(0, 1, 0.0, step=0.1, label="Fatigue Level"),
670
+ gr.Checkbox(label="Enable Trump Volatility"),
671
+ gr.Slider(0, 1, 0.0, step=0.1, label="Trump Volatility Index")
672
+ ],
673
+ outputs=["dataframe", gr.Plot()],
674
+ title="πŸ₯Š Battle Mode"
675
+ ),
676
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
677
 
678
 
679