Trebor1009 commited on
Commit
0bbbdc1
Β·
verified Β·
1 Parent(s): 07b610c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +21 -44
src/streamlit_app.py CHANGED
@@ -721,10 +721,10 @@ def render_sniper_dashboard(ticker, result):
721
  ax1.grid(True, alpha=0.1)
722
  if stats:
723
  stats_text = (
724
- f"Historical Matches: {stats['count']}\\n"
725
- f"Avg Change 1D: {stats['avg_1d']:+.2f}%\\n"
726
- f"Avg Change 5D: {stats['avg_5d']:+.2f}%\\n"
727
- f"Avg Change 3M: {stats['avg_3m']:+.2f}%\\n"
728
  f"3M Win Rate: {stats['win_3m']:.1f}% (n={stats['count']})"
729
  )
730
  ax1.text(0.98, 0.05, stats_text, transform=ax1.transAxes, va="bottom", ha="right",
@@ -791,11 +791,11 @@ def render_sniper_tab():
791
  "forward returns and win rate."
792
  )
793
  st.warning(
794
- "⚠️ Two things worth keeping in mind:\\n\\n"
795
  "1. **Small samples** β€” many qualifying setups have only 10-30 historical matches. An '80% win rate' "
796
- "on 10 matches has a much wider true range than the headline number suggests.\\n\\n"
797
  "2. **Full-universe scans test thousands of tickers at once.** With that many tests, some will "
798
- "clear an 80%+ bar by chance alone. A hit is a reason to look closer, not a standalone signal.\\n\\n"
799
  "The dashed blue line ('best-match analog') is one single closest-matching historical window, "
800
  "shown for context β€” not a statistical price target."
801
  )
@@ -871,7 +871,7 @@ def render_sniper_tab():
871
  st.subheader("Full universe scan")
872
  st.caption(
873
  "Scans your curated ticker list for setups meeting the full criteria. "
874
- "First run can take several minutes β€” results are cached for 12 hours.\\n\\n"
875
  f"{'βœ… Hits will be auto-saved to your signal log.' if _log_configured() else '⚠️ Signal log storage not configured β€” hits will NOT be saved.'}"
876
  )
877
  if st.button("πŸ” Run Full Universe Scan", key="sn_scan_btn"):
@@ -1220,32 +1220,17 @@ def render_rotation_map():
1220
  "the daily RRG turn has started yet."
1221
  )
1222
 
1223
- """
1224
- combined_scanner.py β€” Tab 6: RRG + Bottom Scanner Combined Signal
1225
-
1226
- Backtest findings (2,266 tickers, 2016–2026, ~4.9M ticker-days):
1227
-
1228
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
1229
- β”‚ Signal β”‚ n β”‚ 63D win β”‚ 63D avg β”‚ xs t(63D)β”‚ CAGR β”‚ Sharpe β”‚
1230
- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
1231
- β”‚ EW B&H benchmark β”‚ β€” β”‚ β€” β”‚ β€” β”‚ β€” β”‚ 31.8% β”‚ 0.79 β”‚
1232
- β”‚ RRG only (Lag|Weak + 2d turn) β”‚ 46,528 β”‚ 54.5% β”‚ +3.1% β”‚ -12.1 β”‚ 20.3% β”‚ 0.65 β”‚
1233
- β”‚ Bottom Scanner only β”‚ 30,527 β”‚ 55.1% β”‚ +3.3% β”‚ -10.2 β”‚ 14.0% β”‚ 0.51 β”‚
1234
- β”‚ COMBINED (all-cap) β”‚ 15,617 β”‚ 55.1% β”‚ +4.0% β”‚ -5.2 β”‚ 3.8% β”‚ 0.23 β”‚
1235
- β”‚ COMBINED (large-cap) β”‚ 4,841 β”‚ 60.5% β”‚ +5.8% β”‚ +0.3 βœ“ β”‚ 8.1% β”‚ 0.37 β”‚
1236
- β”‚ BS + Weakening only (large-cap) β”‚ 228 β”‚ 79.6% β”‚+14.8% β”‚ -1.2 β”‚ 5.1% β”‚ 0.55 β”‚
1237
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1238
-
1239
- Key insight: the COMBINED large-cap signal is the only configuration with a (marginally)
1240
- positive cross-sectional t-stat (+0.32 at 63D), meaning it's the closest thing to
1241
- genuine alpha vs peers rather than just market beta. "BS + Weakening only" gets closest
1242
- to Gemini's 75% XL-ETF finding (79.6% win rate on 228 trades, CI 73.9–84.4%).
1243
-
1244
- Drop-in usage:
1245
- with tab6:
1246
- from combined_scanner import render_combined_scanner
1247
- render_combined_scanner()
1248
- """
1249
  def _rrg(price_series: pd.Series, benchmark: pd.Series, window: int) -> pd.DataFrame:
1250
  """
1251
  Compute RS-Ratio and RS-Momentum centred at 100.
@@ -1706,16 +1691,7 @@ The real use is as a *filter on top of an existing watchlist*, not a standalone
1706
  st.markdown("---")
1707
  st.subheader("Full universe scan")
1708
 
1709
- try:
1710
- from huggingface_hub import hf_hub_download
1711
- local = hf_hub_download(
1712
- repo_id="Trebor1009/clean-premarket-data", repo_type="dataset",
1713
- filename="clean_premarket_data.csv", token=HF_TOKEN,
1714
- )
1715
- universe = sorted(pd.read_csv(local, usecols=["Ticker"])["Ticker"].dropna().unique())
1716
- except Exception as e:
1717
- universe = []
1718
- st.warning(f"Could not load universe: {e}")
1719
 
1720
  st.caption(
1721
  f"Universe: {len(universe)} tickers. Each ticker fetches 5y of daily data β€” "
@@ -1804,6 +1780,7 @@ the equal-weight benchmark (31.8%) because active holding periods are sparse.
1804
  Use as a filter, not a standalone system.
1805
  """)
1806
 
 
1807
  # =========================================================
1808
  # MAIN LAYOUT
1809
  # =========================================================
 
721
  ax1.grid(True, alpha=0.1)
722
  if stats:
723
  stats_text = (
724
+ f"Historical Matches: {stats['count']}\n"
725
+ f"Avg Change 1D: {stats['avg_1d']:+.2f}%\n"
726
+ f"Avg Change 5D: {stats['avg_5d']:+.2f}%\n"
727
+ f"Avg Change 3M: {stats['avg_3m']:+.2f}%\n"
728
  f"3M Win Rate: {stats['win_3m']:.1f}% (n={stats['count']})"
729
  )
730
  ax1.text(0.98, 0.05, stats_text, transform=ax1.transAxes, va="bottom", ha="right",
 
791
  "forward returns and win rate."
792
  )
793
  st.warning(
794
+ "⚠️ Two things worth keeping in mind:\n\n"
795
  "1. **Small samples** β€” many qualifying setups have only 10-30 historical matches. An '80% win rate' "
796
+ "on 10 matches has a much wider true range than the headline number suggests.\n\n"
797
  "2. **Full-universe scans test thousands of tickers at once.** With that many tests, some will "
798
+ "clear an 80%+ bar by chance alone. A hit is a reason to look closer, not a standalone signal.\n\n"
799
  "The dashed blue line ('best-match analog') is one single closest-matching historical window, "
800
  "shown for context β€” not a statistical price target."
801
  )
 
871
  st.subheader("Full universe scan")
872
  st.caption(
873
  "Scans your curated ticker list for setups meeting the full criteria. "
874
+ "First run can take several minutes β€” results are cached for 12 hours.\n\n"
875
  f"{'βœ… Hits will be auto-saved to your signal log.' if _log_configured() else '⚠️ Signal log storage not configured β€” hits will NOT be saved.'}"
876
  )
877
  if st.button("πŸ” Run Full Universe Scan", key="sn_scan_btn"):
 
1220
  "the daily RRG turn has started yet."
1221
  )
1222
 
1223
+
1224
+
1225
+ # =========================================================
1226
+ # TAB 6: COMBINED SCANNER (RRG + Bottom Scanner)
1227
+ # =========================================================
1228
+
1229
+ # Quality / liquidity constants (applied as-of signal date, no look-ahead)
1230
+ PRICE_FLOOR = 5.0 # min stock price
1231
+ MIN_DVOL = 1_000_000 # min 20-day avg dollar volume
1232
+ DEDUP_DAYS = 63 # cooldown before same ticker can re-flag
1233
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1234
  def _rrg(price_series: pd.Series, benchmark: pd.Series, window: int) -> pd.DataFrame:
1235
  """
1236
  Compute RS-Ratio and RS-Momentum centred at 100.
 
1691
  st.markdown("---")
1692
  st.subheader("Full universe scan")
1693
 
1694
+ universe = get_clean_premarket_universe()
 
 
 
 
 
 
 
 
 
1695
 
1696
  st.caption(
1697
  f"Universe: {len(universe)} tickers. Each ticker fetches 5y of daily data β€” "
 
1780
  Use as a filter, not a standalone system.
1781
  """)
1782
 
1783
+
1784
  # =========================================================
1785
  # MAIN LAYOUT
1786
  # =========================================================