daeeeee commited on
Commit
bebd19b
·
1 Parent(s): fb03e07

feat(ui): Auto-tune tab

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py CHANGED
@@ -405,6 +405,22 @@ def run_backtest(symbol, interval, start_date, end_date,
405
  out_table["hit_rate_running"] = (out_table["hit_rate_running"] * 100.0).round(2)
406
  return fig, summary, out_table
407
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
  # ----- UI -----
409
  with gr.Blocks(title="Kronos Forecast Dashboard", theme=gr.themes.Soft()) as demo:
410
  gr.Markdown("# 📈 Kronos Financial Forecast Dashboard\nZero-shot OHLCV forecasting powered by [Kronos](https://github.com/shiyu-coder/Kronos) + FMP market data.")
@@ -540,6 +556,40 @@ with gr.Blocks(title="Kronos Forecast Dashboard", theme=gr.themes.Soft()) as dem
540
  concurrency_id="predictor", concurrency_limit=1,
541
  )
542
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
 
544
  demo.queue(default_concurrency_limit=10, max_size=32)
545
 
 
405
  out_table["hit_rate_running"] = (out_table["hit_rate_running"] * 100.0).round(2)
406
  return fig, summary, out_table
407
 
408
+ def run_autotune_ui(symbol, interval, start_date, end_date,
409
+ lookback, pred_len, stride, sample_count, max_anchors):
410
+ def _predict(**kwargs):
411
+ with PREDICT_LOCK:
412
+ return predictor.predict(**kwargs)
413
+ try:
414
+ return autotune.run_autotune(
415
+ predict_fn=_predict, fetch_fn=fetch_fmp, db_path=DB_PATH,
416
+ symbol=symbol, interval=interval,
417
+ start_date=start_date, end_date=end_date,
418
+ lookback=lookback, pred_len=pred_len, stride=stride,
419
+ sample_count=sample_count, max_anchors=max_anchors,
420
+ )
421
+ except (ValueError, RuntimeError) as e:
422
+ raise gr.Error(str(e))
423
+
424
  # ----- UI -----
425
  with gr.Blocks(title="Kronos Forecast Dashboard", theme=gr.themes.Soft()) as demo:
426
  gr.Markdown("# 📈 Kronos Financial Forecast Dashboard\nZero-shot OHLCV forecasting powered by [Kronos](https://github.com/shiyu-coder/Kronos) + FMP market data.")
 
556
  concurrency_id="predictor", concurrency_limit=1,
557
  )
558
 
559
+ # ---- Auto-tune tab ----
560
+ with gr.Tab("Auto-tune"):
561
+ gr.Markdown(
562
+ "Search Kronos sampling knobs (T, top_p) on a 3×3 grid, score each "
563
+ "cell with a walk-forward backtest, and persist the best "
564
+ "(T, top_p) per (symbol, interval). The Forecast tab can then "
565
+ "pre-fill those defaults via the 🎯 checkbox."
566
+ )
567
+ with gr.Row():
568
+ with gr.Column(scale=1):
569
+ at_symbol = gr.Textbox("SPY", label="Symbol")
570
+ at_interval = gr.Dropdown(["1min","5min","15min","30min","1hour","4hour"],
571
+ value="5min", label="Interval")
572
+ at_start = gr.Textbox("", label="Start (YYYY-MM-DD HH:MM, blank=earliest)")
573
+ at_end = gr.Textbox("", label="End (YYYY-MM-DD HH:MM, blank=latest)")
574
+ at_lookback = gr.Slider(100, 400, 200, step=1, label="Lookback bars")
575
+ at_predlen = gr.Slider(5, 120, 30, step=1, label="Forecast horizon (pred_len)")
576
+ at_stride = gr.Slider(1, 120, 30, step=1, label="Stride")
577
+ at_samples = gr.Slider(1, 5, 1, step=1, label="MC samples per step")
578
+ at_max = gr.Slider(3, 30, 5, step=1,
579
+ label="Max anchors per cell (caps work; 9 cells × this)")
580
+ at_btn = gr.Button("🎯 Run auto-tune", variant="primary")
581
+ with gr.Column(scale=3):
582
+ at_chart = gr.Plot(label="Heatmap: P&L % over (T, top_p)")
583
+ at_summary = gr.Dataframe(label="Best parameters", interactive=False)
584
+ at_table = gr.Dataframe(label="Per-cell results", interactive=False)
585
+ at_btn.click(
586
+ run_autotune_ui,
587
+ inputs=[at_symbol, at_interval, at_start, at_end,
588
+ at_lookback, at_predlen, at_stride, at_samples, at_max],
589
+ outputs=[at_chart, at_summary, at_table],
590
+ concurrency_id="predictor", concurrency_limit=1,
591
+ )
592
+
593
 
594
  demo.queue(default_concurrency_limit=10, max_size=32)
595