Spaces:
Sleeping
Sleeping
Commit ·
ff1f955
1
Parent(s): 95e30ef
Day 10 - added frontend(has bugs)
Browse files- dashboard/__init__.py +0 -0
- dashboard/app.py +81 -0
- dashboard/assets/theme.css +116 -0
- dashboard/components/__init__.py +0 -0
- dashboard/components/sidebar.py +38 -0
- dashboard/pages/__init__.py +0 -0
- dashboard/pages/anomalies.py +211 -0
- dashboard/pages/forecasts.py +170 -0
- dashboard/pages/overview.py +212 -0
- dashboard/pages/portfolio.py +192 -0
- dashboard/pages/sentiment.py +201 -0
- ml/portfolio_optimizer.py +1 -1
- pyproject.toml +2 -0
- uv.lock +76 -0
dashboard/__init__.py
ADDED
|
File without changes
|
dashboard/app.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Phase 6 Dashboard — app.py
|
| 3 |
+
Entry point. Creates Dash app, dark theme, registers pages, configures routing.
|
| 4 |
+
Run: python dashboard/app.py → http://localhost:8050
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import dash
|
| 8 |
+
from dash import Dash, html, dcc, Input, Output, callback
|
| 9 |
+
import dash_bootstrap_components as dbc
|
| 10 |
+
import datetime
|
| 11 |
+
|
| 12 |
+
app = Dash(
|
| 13 |
+
__name__,
|
| 14 |
+
use_pages=True,
|
| 15 |
+
external_stylesheets=[
|
| 16 |
+
dbc.themes.CYBORG,
|
| 17 |
+
dbc.icons.BOOTSTRAP,
|
| 18 |
+
"https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Syne:wght@400;700;800&display=swap",
|
| 19 |
+
],
|
| 20 |
+
suppress_callback_exceptions=True,
|
| 21 |
+
meta_tags=[{"name": "viewport", "content": "width=device-width, initial-scale=1"}],
|
| 22 |
+
)
|
| 23 |
+
app.title = "FinDash · Phase 6"
|
| 24 |
+
server = app.server # expose for gunicorn
|
| 25 |
+
|
| 26 |
+
# ── Navigation items ──────────────────────────────────────────────────────────
|
| 27 |
+
NAV_ITEMS = [
|
| 28 |
+
{"label": "Market Overview", "href": "/overview", "icon": "bi-grid-3x3-gap-fill"},
|
| 29 |
+
{"label": "Anomaly Detector", "href": "/anomalies", "icon": "bi-exclamation-triangle-fill"},
|
| 30 |
+
{"label": "Price Forecasts", "href": "/forecasts", "icon": "bi-graph-up-arrow"},
|
| 31 |
+
{"label": "Portfolio Optimiser", "href": "/portfolio", "icon": "bi-pie-chart-fill"},
|
| 32 |
+
{"label": "Sentiment Analysis", "href": "/sentiment", "icon": "bi-chat-quote-fill"},
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
sidebar = html.Aside([
|
| 36 |
+
html.Div([html.Span("FIN", className="logo-accent"), html.Span("DASH")], className="sidebar-logo"),
|
| 37 |
+
html.P("Phase 6 · Analytics", className="sidebar-subtitle"),
|
| 38 |
+
html.Hr(className="sidebar-divider"),
|
| 39 |
+
html.Nav([
|
| 40 |
+
dcc.Link(
|
| 41 |
+
html.Div([html.I(className=f"{i['icon']} me-2"), i["label"]], className="sidebar-link"),
|
| 42 |
+
href=i["href"], className="nav-item-link",
|
| 43 |
+
)
|
| 44 |
+
for i in NAV_ITEMS
|
| 45 |
+
], className="sidebar-nav"),
|
| 46 |
+
html.Div(className="sidebar-spacer"),
|
| 47 |
+
html.Div([
|
| 48 |
+
html.Div("● LIVE", className="live-badge"),
|
| 49 |
+
html.P("API endpoints active", className="sidebar-footer-text"),
|
| 50 |
+
], className="sidebar-footer"),
|
| 51 |
+
], className="sidebar")
|
| 52 |
+
|
| 53 |
+
topbar = html.Header([
|
| 54 |
+
html.Div(id="page-title", className="topbar-title"),
|
| 55 |
+
html.Div([
|
| 56 |
+
dcc.Interval(id="clock-interval", interval=1000, n_intervals=0),
|
| 57 |
+
html.Span(id="live-clock", className="topbar-clock"),
|
| 58 |
+
html.Span(" UTC", className="topbar-tz"),
|
| 59 |
+
], className="topbar-right"),
|
| 60 |
+
], className="topbar")
|
| 61 |
+
|
| 62 |
+
app.layout = html.Div([
|
| 63 |
+
dcc.Location(id="url", refresh=False),
|
| 64 |
+
sidebar,
|
| 65 |
+
html.Div([topbar, html.Main(dash.page_container, className="page-content")], className="main-wrapper"),
|
| 66 |
+
], className="app-shell")
|
| 67 |
+
|
| 68 |
+
@callback(Output("live-clock", "children"), Input("clock-interval", "n_intervals"))
|
| 69 |
+
def update_clock(_):
|
| 70 |
+
return datetime.datetime.utcnow().strftime("%H:%M:%S")
|
| 71 |
+
|
| 72 |
+
@callback(Output("page-title", "children"), Input("url", "pathname"))
|
| 73 |
+
def update_title(path):
|
| 74 |
+
return {
|
| 75 |
+
"/overview": "Market Overview", "/anomalies": "Anomaly Detector",
|
| 76 |
+
"/forecasts": "Price Forecasts", "/portfolio": "Portfolio Optimiser",
|
| 77 |
+
"/sentiment": "Sentiment Analysis",
|
| 78 |
+
}.get(path, "Dashboard")
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
app.run(debug=True, host="0.0.0.0", port=8050)
|
dashboard/assets/theme.css
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:root {
|
| 2 |
+
--bg: #050810; --surface: #0d1117; --surface2: #161b27;
|
| 3 |
+
--border: #1e2738; --accent: #00e5ff; --accent2: #7c3aed;
|
| 4 |
+
--green: #00c98d; --red: #ff4d6d; --orange: #ff8c42;
|
| 5 |
+
--text: #e2e8f0; --muted: #64748b; --radius: 6px; --sidebar-w: 230px;
|
| 6 |
+
}
|
| 7 |
+
*, *::before, *::after {
|
| 8 |
+
box-sizing: border-box;
|
| 9 |
+
margin: 0; padding: 0;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
body {
|
| 13 |
+
background: var(--bg);
|
| 14 |
+
color: var(--text);
|
| 15 |
+
font-family: 'Syne', sans-serif;
|
| 16 |
+
font-size: 14px;
|
| 17 |
+
line-height: 1.6;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.app-shell {
|
| 21 |
+
display: flex;
|
| 22 |
+
min-height: 100vh;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.sidebar {
|
| 26 |
+
width: var(--sidebar-w);
|
| 27 |
+
min-height: 100vh;
|
| 28 |
+
background: var(--surface);
|
| 29 |
+
border-right: 1px solid var(--border);
|
| 30 |
+
display: flex;
|
| 31 |
+
flex-direction: column;
|
| 32 |
+
padding: 24px 16px;
|
| 33 |
+
position: fixed;
|
| 34 |
+
top: 0;
|
| 35 |
+
left: 0;
|
| 36 |
+
bottom: 0;
|
| 37 |
+
z-index: 100;
|
| 38 |
+
|
| 39 |
+
}
|
| 40 |
+
.sidebar-logo {
|
| 41 |
+
font-weight: 800;
|
| 42 |
+
font-size: 22px;
|
| 43 |
+
letter-spacing: 2px;
|
| 44 |
+
color: var(--text);
|
| 45 |
+
margin-bottom: 4px;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.logo-accent {
|
| 49 |
+
color: var(--accent);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.sidebar-subtitle { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }
|
| 53 |
+
.sidebar-divider { border-color: var(--border); margin: 16px 0; }
|
| 54 |
+
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
|
| 55 |
+
.nav-item-link { text-decoration: none !important; color: inherit; }
|
| 56 |
+
.sidebar-link { display: flex; align-items: center; padding: 9px 12px; border-radius: var(--radius); color: var(--muted); font-size: 13px; font-weight: 600; transition: background .15s, color .15s; cursor: pointer; }
|
| 57 |
+
.sidebar-link:hover { background: var(--surface2); color: var(--accent); }
|
| 58 |
+
.sidebar-spacer { flex: 1; }
|
| 59 |
+
.live-badge { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--green); letter-spacing: 1px; margin-bottom: 4px; animation: pulse 2s infinite; }
|
| 60 |
+
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
|
| 61 |
+
.sidebar-footer-text { font-size: 11px; color: var(--muted); margin: 0; }
|
| 62 |
+
|
| 63 |
+
/* Main */
|
| 64 |
+
.main-wrapper { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }
|
| 65 |
+
.topbar { height: 52px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 28px; position: sticky; top: 0; z-index: 90; }
|
| 66 |
+
.topbar-title { font-weight: 700; font-size: 16px; color: var(--text); }
|
| 67 |
+
.topbar-right { display: flex; align-items: center; gap: 6px; }
|
| 68 |
+
.topbar-clock { font-family: 'JetBrains Mono', monospace; font-size: 14px; color: var(--accent); font-weight: 600; letter-spacing: 1px; }
|
| 69 |
+
.topbar-tz { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--muted); }
|
| 70 |
+
.page-content { padding: 28px; flex: 1; }
|
| 71 |
+
|
| 72 |
+
/* Cards */
|
| 73 |
+
.dash-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
|
| 74 |
+
.dash-card-title { font-size: 11px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 14px; }
|
| 75 |
+
|
| 76 |
+
/* Metric tiles */
|
| 77 |
+
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; margin-bottom: 20px; }
|
| 78 |
+
.metric-tile { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
|
| 79 |
+
.metric-tile-label { font-size: 10px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
|
| 80 |
+
.metric-tile-value { font-family: 'JetBrains Mono', monospace; font-size: 22px; font-weight: 600; color: var(--text); line-height: 1; }
|
| 81 |
+
.metric-tile-delta { font-family: 'JetBrains Mono', monospace; font-size: 12px; margin-top: 4px; }
|
| 82 |
+
.pos { color: var(--green); } .neg { color: var(--red); } .neu { color: var(--muted); }
|
| 83 |
+
|
| 84 |
+
/* Table */
|
| 85 |
+
.dash-table { width: 100%; border-collapse: collapse; }
|
| 86 |
+
.dash-table th { font-size: 10px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; }
|
| 87 |
+
.dash-table td { padding: 10px 12px; border-bottom: 1px solid rgba(30,39,56,.6); font-size: 13px; font-family: 'JetBrains Mono', monospace; }
|
| 88 |
+
.dash-table tr:hover td { background: var(--surface2); }
|
| 89 |
+
|
| 90 |
+
/* Badges */
|
| 91 |
+
.badge-pos { background: rgba(0,201,141,.15); color: var(--green); padding: 2px 8px; border-radius: 4px; font-size: 11px; }
|
| 92 |
+
.badge-neg { background: rgba(255,77,109,.15); color: var(--red); padding: 2px 8px; border-radius: 4px; font-size: 11px; }
|
| 93 |
+
.badge-neu { background: rgba(100,116,139,.15);color: var(--muted); padding: 2px 8px; border-radius: 4px; font-size: 11px; }
|
| 94 |
+
.badge-sev-high { background: rgba(255,77,109,.2); color: var(--red); padding: 2px 8px; border-radius: 4px; font-size: 11px; }
|
| 95 |
+
.badge-sev-medium { background: rgba(255,140,66,.2); color: var(--orange); padding: 2px 8px; border-radius: 4px; font-size: 11px; }
|
| 96 |
+
.badge-sev-low { background: rgba(0,229,255,.15); color: var(--accent); padding: 2px 8px; border-radius: 4px; font-size: 11px; }
|
| 97 |
+
|
| 98 |
+
/* News */
|
| 99 |
+
.news-item { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
|
| 100 |
+
.news-item:last-child { border-bottom: none; }
|
| 101 |
+
.news-headline { font-size: 13px; color: var(--text); margin-bottom: 4px; }
|
| 102 |
+
.news-meta { font-size: 11px; color: var(--muted); font-family: 'JetBrains Mono', monospace; }
|
| 103 |
+
|
| 104 |
+
/* Layout */
|
| 105 |
+
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
|
| 106 |
+
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
|
| 107 |
+
@media (max-width:1100px) { .two-col, .three-col { grid-template-columns: 1fr; } }
|
| 108 |
+
.filter-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 12px 16px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 20px; }
|
| 109 |
+
.filter-label { font-size: 11px; font-weight: 700; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; }
|
| 110 |
+
.ci-legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 8px; }
|
| 111 |
+
.ci-box { width: 16px; height: 10px; background: rgba(0,229,255,.15); border: 1px solid var(--accent); border-radius: 2px; }
|
| 112 |
+
.shap-bar-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
|
| 113 |
+
.shap-feature { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--muted); width: 160px; flex-shrink: 0; text-align: right; }
|
| 114 |
+
.shap-bar-bg { flex: 1; height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
|
| 115 |
+
.shap-bar-fill { height: 100%; border-radius: 4px; }
|
| 116 |
+
.shap-val { font-family: 'JetBrains Mono', monospace; font-size: 12px; width: 54px; text-align: right; flex-shrink: 0; }
|
dashboard/components/__init__.py
ADDED
|
File without changes
|
dashboard/components/sidebar.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import dash
|
| 2 |
+
import dash_bootstrap_components as dbc
|
| 3 |
+
from dash import html
|
| 4 |
+
|
| 5 |
+
SIDEBAR_STYLE = {
|
| 6 |
+
"position": "fixed",
|
| 7 |
+
"top": 0,
|
| 8 |
+
"left": 0,
|
| 9 |
+
"bottom": 0,
|
| 10 |
+
"width": "16rem",
|
| 11 |
+
"padding": "2rem 1rem",
|
| 12 |
+
"background-color": "#1a1a2e", # dark navy
|
| 13 |
+
"overflow-y": "auto"
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
CONTENT_STYLE = {
|
| 17 |
+
"margin-left": "17rem",
|
| 18 |
+
"padding": "2rem 1rem"
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
sidebar = html.Div(
|
| 22 |
+
[
|
| 23 |
+
html.H4("FIP", className="text-white mb-4"),
|
| 24 |
+
html.Hr(style={"border-color": "#444"}),
|
| 25 |
+
dbc.Nav(
|
| 26 |
+
[
|
| 27 |
+
dbc.NavLink("Overview", href="/", active="exact"),
|
| 28 |
+
dbc.NavLink("Prices", href="/prices", active="exact"),
|
| 29 |
+
dbc.NavLink("Forecasts", href="/forecasts", active="exact"),
|
| 30 |
+
dbc.NavLink("Anomalies", href="/anomalies", active="exact"),
|
| 31 |
+
dbc.NavLink("Sentiment", href="/sentiment", active="exact"),
|
| 32 |
+
],
|
| 33 |
+
vertical=True,
|
| 34 |
+
pills=True,
|
| 35 |
+
),
|
| 36 |
+
],
|
| 37 |
+
style=SIDEBAR_STYLE
|
| 38 |
+
)
|
dashboard/pages/__init__.py
ADDED
|
File without changes
|
dashboard/pages/anomalies.py
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Page 2 — Anomaly Dashboard
|
| 3 |
+
Candlestick chart with anomaly markers, severity filter,
|
| 4 |
+
anomaly timeline, SHAP explanation panel.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import dash
|
| 8 |
+
from dash import html, dcc, Input, Output, callback
|
| 9 |
+
import plotly.graph_objects as go
|
| 10 |
+
import pandas as pd
|
| 11 |
+
import numpy as np
|
| 12 |
+
import datetime
|
| 13 |
+
|
| 14 |
+
dash.register_page(__name__, path="/anomalies", name="Anomaly Detector")
|
| 15 |
+
|
| 16 |
+
TICKERS = ["AAPL", "MSFT", "GOOGL", "AMZN", "NVDA"]
|
| 17 |
+
COLORS = dict(accent="#00e5ff", green="#00c98d", red="#ff4d6d", orange="#ff8c42",
|
| 18 |
+
surface="#0d1117", surface2="#161b27", border="#1e2738", muted="#64748b", text="#e2e8f0")
|
| 19 |
+
|
| 20 |
+
SHAP_FEATURES = ["Volume spike", "Bollinger break", "RSI divergence", "MACD cross", "News sentiment", "Intraday gap"]
|
| 21 |
+
|
| 22 |
+
def _gen_ohlc(n=120, base=182.0):
|
| 23 |
+
dates = pd.bdate_range(end=datetime.date.today(), periods=n)
|
| 24 |
+
closes = [base]
|
| 25 |
+
for _ in range(n - 1):
|
| 26 |
+
closes.append(closes[-1] * (1 + np.random.normal(0, 0.015)))
|
| 27 |
+
opens = [closes[0]] + closes[:-1]
|
| 28 |
+
highs = [max(o, c) * (1 + abs(np.random.normal(0, .005))) for o, c in zip(opens, closes)]
|
| 29 |
+
lows = [min(o, c) * (1 - abs(np.random.normal(0, .005))) for o, c in zip(opens, closes)]
|
| 30 |
+
return pd.DataFrame(dict(date=dates, open=opens, high=highs, low=lows, close=closes))
|
| 31 |
+
|
| 32 |
+
def _gen_anomalies(df, severity="all"):
|
| 33 |
+
n = len(df)
|
| 34 |
+
idx = sorted(np.random.choice(n, size=max(4, n // 15), replace=False))
|
| 35 |
+
rows = []
|
| 36 |
+
for i in idx:
|
| 37 |
+
sev = np.random.choice(["high", "medium", "low"], p=[.25, .45, .3])
|
| 38 |
+
if severity != "all" and sev != severity:
|
| 39 |
+
continue
|
| 40 |
+
rows.append(dict(
|
| 41 |
+
date=df.iloc[i]["date"],
|
| 42 |
+
price=df.iloc[i]["close"],
|
| 43 |
+
severity=sev,
|
| 44 |
+
score=round(np.random.uniform(0.6, 0.99), 3),
|
| 45 |
+
shap={f: round(np.random.uniform(-1, 1), 3) for f in SHAP_FEATURES},
|
| 46 |
+
))
|
| 47 |
+
return rows
|
| 48 |
+
|
| 49 |
+
def make_candle_chart(df, anomalies):
|
| 50 |
+
fig = go.Figure()
|
| 51 |
+
fig.add_trace(go.Candlestick(
|
| 52 |
+
x=df["date"], open=df["open"], high=df["high"], low=df["low"], close=df["close"],
|
| 53 |
+
increasing=dict(line=dict(color=COLORS["green"]), fillcolor=COLORS["green"] + "55"),
|
| 54 |
+
decreasing=dict(line=dict(color=COLORS["red"]), fillcolor=COLORS["red"] + "55"),
|
| 55 |
+
name="OHLC",
|
| 56 |
+
))
|
| 57 |
+
color_map = {"high": COLORS["red"], "medium": COLORS["orange"], "low": COLORS["accent"]}
|
| 58 |
+
symbol_map= {"high": "x-open", "medium": "triangle-up-open", "low": "circle-open"}
|
| 59 |
+
for sev in ["high", "medium", "low"]:
|
| 60 |
+
pts = [a for a in anomalies if a["severity"] == sev]
|
| 61 |
+
if pts:
|
| 62 |
+
fig.add_trace(go.Scatter(
|
| 63 |
+
x=[p["date"] for p in pts],
|
| 64 |
+
y=[p["price"] * 1.025 for p in pts],
|
| 65 |
+
mode="markers",
|
| 66 |
+
marker=dict(symbol=symbol_map[sev], color=color_map[sev], size=12, line=dict(width=2)),
|
| 67 |
+
name=f"{sev.title()} severity",
|
| 68 |
+
customdata=[[p["score"]] for p in pts],
|
| 69 |
+
hovertemplate=f"<b>{sev.title()} Anomaly</b><br>Score: %{{customdata[0]:.3f}}<extra></extra>",
|
| 70 |
+
))
|
| 71 |
+
fig.update_layout(
|
| 72 |
+
paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
|
| 73 |
+
font=dict(color=COLORS["text"]), height=380,
|
| 74 |
+
xaxis=dict(showgrid=False, zeroline=False, color=COLORS["muted"], rangeslider=dict(visible=False)),
|
| 75 |
+
yaxis=dict(showgrid=True, gridcolor=COLORS["border"], zeroline=False, color=COLORS["muted"]),
|
| 76 |
+
legend=dict(bgcolor="rgba(0,0,0,0)", bordercolor=COLORS["border"]),
|
| 77 |
+
margin=dict(l=10, r=10, t=20, b=10),
|
| 78 |
+
hovermode="x unified",
|
| 79 |
+
)
|
| 80 |
+
return fig
|
| 81 |
+
|
| 82 |
+
def make_timeline(anomalies):
|
| 83 |
+
if not anomalies:
|
| 84 |
+
return go.Figure()
|
| 85 |
+
color_map = {"high": COLORS["red"], "medium": COLORS["orange"], "low": COLORS["accent"]}
|
| 86 |
+
fig = go.Figure()
|
| 87 |
+
for sev in ["high", "medium", "low"]:
|
| 88 |
+
pts = [a for a in anomalies if a["severity"] == sev]
|
| 89 |
+
if pts:
|
| 90 |
+
fig.add_trace(go.Scatter(
|
| 91 |
+
x=[p["date"] for p in pts], y=[p["score"] for p in pts],
|
| 92 |
+
mode="markers+lines",
|
| 93 |
+
marker=dict(color=color_map[sev], size=8),
|
| 94 |
+
line=dict(color=color_map[sev], width=1, dash="dot"),
|
| 95 |
+
name=sev.title(),
|
| 96 |
+
))
|
| 97 |
+
fig.update_layout(
|
| 98 |
+
paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
|
| 99 |
+
font=dict(color=COLORS["text"]), height=160,
|
| 100 |
+
xaxis=dict(showgrid=False, color=COLORS["muted"]),
|
| 101 |
+
yaxis=dict(showgrid=True, gridcolor=COLORS["border"], color=COLORS["muted"],
|
| 102 |
+
title="Anomaly Score", range=[0, 1]),
|
| 103 |
+
legend=dict(bgcolor="rgba(0,0,0,0)"),
|
| 104 |
+
margin=dict(l=10, r=10, t=10, b=10),
|
| 105 |
+
)
|
| 106 |
+
return fig
|
| 107 |
+
|
| 108 |
+
def shap_panel(anomaly):
|
| 109 |
+
if not anomaly:
|
| 110 |
+
return html.P("Click an anomaly marker to see SHAP explanation.", style={"color": COLORS["muted"], "fontSize": "13px"})
|
| 111 |
+
shap = anomaly["shap"]
|
| 112 |
+
total = sum(abs(v) for v in shap.values())
|
| 113 |
+
items = sorted(shap.items(), key=lambda x: abs(x[1]), reverse=True)
|
| 114 |
+
bars = []
|
| 115 |
+
for feat, val in items:
|
| 116 |
+
pct = abs(val) / total * 100
|
| 117 |
+
color = COLORS["green"] if val > 0 else COLORS["red"]
|
| 118 |
+
bars.append(html.Div([
|
| 119 |
+
html.Div(feat, className="shap-feature"),
|
| 120 |
+
html.Div(html.Div(style={"width": f"{pct:.0f}%", "background": color}, className="shap-bar-fill"), className="shap-bar-bg"),
|
| 121 |
+
html.Div(f"{val:+.3f}", className="shap-val", style={"color": color}),
|
| 122 |
+
], className="shap-bar-wrap"))
|
| 123 |
+
badge_cls = f"badge-sev-{anomaly['severity']}"
|
| 124 |
+
return html.Div([
|
| 125 |
+
html.Div([
|
| 126 |
+
html.Strong(f"Anomaly — {str(anomaly['date'])[:10]}", style={"color": COLORS["text"]}),
|
| 127 |
+
html.Span(anomaly["severity"].title(), className=badge_cls, style={"marginLeft": "10px"}),
|
| 128 |
+
html.Span(f"Score: {anomaly['score']:.3f}", style={"color": COLORS["muted"], "fontSize": "12px", "marginLeft": "10px", "fontFamily": "JetBrains Mono"}),
|
| 129 |
+
], style={"marginBottom": "14px"}),
|
| 130 |
+
*bars,
|
| 131 |
+
])
|
| 132 |
+
|
| 133 |
+
# ── Layout ────────────────────────────────────────────────────────────────────
|
| 134 |
+
layout = html.Div([
|
| 135 |
+
# Filter bar
|
| 136 |
+
html.Div([
|
| 137 |
+
html.Span("Ticker:", className="filter-label"),
|
| 138 |
+
dcc.Dropdown(
|
| 139 |
+
id="an-ticker", options=[{"label": t, "value": t} for t in TICKERS],
|
| 140 |
+
value="AAPL", clearable=False,
|
| 141 |
+
style={"width": "130px", "background": "#161b27"},
|
| 142 |
+
),
|
| 143 |
+
html.Span("Severity:", className="filter-label"),
|
| 144 |
+
dcc.RadioItems(
|
| 145 |
+
id="an-severity",
|
| 146 |
+
options=[{"label": s.title(), "value": s} for s in ["all", "high", "medium", "low"]],
|
| 147 |
+
value="all", inline=True,
|
| 148 |
+
labelStyle={"marginRight": "14px", "color": "#64748b", "fontSize": "13px"},
|
| 149 |
+
),
|
| 150 |
+
], className="filter-bar"),
|
| 151 |
+
|
| 152 |
+
# Candlestick chart
|
| 153 |
+
html.Div([
|
| 154 |
+
html.Div("Candlestick · Anomaly Markers", className="dash-card-title"),
|
| 155 |
+
dcc.Graph(id="an-candle", config=dict(displayModeBar=True)),
|
| 156 |
+
], className="dash-card"),
|
| 157 |
+
|
| 158 |
+
# Timeline
|
| 159 |
+
html.Div([
|
| 160 |
+
html.Div("Anomaly Timeline", className="dash-card-title"),
|
| 161 |
+
dcc.Graph(id="an-timeline", config=dict(displayModeBar=False)),
|
| 162 |
+
], className="dash-card"),
|
| 163 |
+
|
| 164 |
+
# Table + SHAP
|
| 165 |
+
html.Div([
|
| 166 |
+
html.Div([
|
| 167 |
+
html.Div("Detected Anomalies", className="dash-card-title"),
|
| 168 |
+
html.Div(id="an-table"),
|
| 169 |
+
], className="dash-card"),
|
| 170 |
+
html.Div([
|
| 171 |
+
html.Div("SHAP Feature Importance", className="dash-card-title"),
|
| 172 |
+
html.Div(id="an-shap"),
|
| 173 |
+
], className="dash-card"),
|
| 174 |
+
], className="two-col"),
|
| 175 |
+
])
|
| 176 |
+
|
| 177 |
+
_store = {} # server-side cache keyed by ticker
|
| 178 |
+
|
| 179 |
+
@callback(
|
| 180 |
+
Output("an-candle", "figure"),
|
| 181 |
+
Output("an-timeline", "figure"),
|
| 182 |
+
Output("an-table", "children"),
|
| 183 |
+
Output("an-shap", "children"),
|
| 184 |
+
Input("an-ticker", "value"),
|
| 185 |
+
Input("an-severity", "value"),
|
| 186 |
+
)
|
| 187 |
+
def refresh(ticker, severity):
|
| 188 |
+
np.random.seed(hash(ticker) % 2**31)
|
| 189 |
+
df = _gen_ohlc(120, base={"AAPL":182,"MSFT":415,"GOOGL":175,"AMZN":195,"NVDA":875}[ticker])
|
| 190 |
+
all_anoms = _gen_anomalies(df, "all")
|
| 191 |
+
_store["anomalies"] = all_anoms
|
| 192 |
+
filtered = [a for a in all_anoms if severity == "all" or a["severity"] == severity]
|
| 193 |
+
|
| 194 |
+
candle = make_candle_chart(df, filtered)
|
| 195 |
+
timeline = make_timeline(filtered)
|
| 196 |
+
|
| 197 |
+
# Table
|
| 198 |
+
rows = [html.Tr([
|
| 199 |
+
html.Td(str(a["date"])[:10]),
|
| 200 |
+
html.Td(f"${a['price']:.2f}"),
|
| 201 |
+
html.Td(html.Span(a["severity"].title(), className=f"badge-sev-{a['severity']}")),
|
| 202 |
+
html.Td(f"{a['score']:.3f}", style={"fontFamily":"JetBrains Mono"}),
|
| 203 |
+
]) for a in filtered]
|
| 204 |
+
table = html.Table([
|
| 205 |
+
html.Thead(html.Tr([html.Th(h) for h in ["Date","Price","Severity","Score"]])),
|
| 206 |
+
html.Tbody(rows),
|
| 207 |
+
], className="dash-table")
|
| 208 |
+
|
| 209 |
+
# SHAP — use first anomaly as default
|
| 210 |
+
shap = shap_panel(filtered[0] if filtered else None)
|
| 211 |
+
return candle, timeline, table, shap
|
dashboard/pages/forecasts.py
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Page 3 — Price Forecasts
|
| 3 |
+
Actual vs predicted line chart with confidence band,
|
| 4 |
+
ticker / horizon selector, model accuracy metrics.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import dash
|
| 8 |
+
from dash import html, dcc, Input, Output, callback
|
| 9 |
+
import plotly.graph_objects as go
|
| 10 |
+
import pandas as pd
|
| 11 |
+
import numpy as np
|
| 12 |
+
import datetime
|
| 13 |
+
|
| 14 |
+
dash.register_page(__name__, path="/forecasts", name="Price Forecasts")
|
| 15 |
+
|
| 16 |
+
TICKERS = ["AAPL", "MSFT", "GOOGL", "AMZN", "NVDA", "META", "TSLA"]
|
| 17 |
+
HORIZONS = [7, 30, 90]
|
| 18 |
+
COLORS = dict(accent="#00e5ff", green="#00c98d", red="#ff4d6d",
|
| 19 |
+
surface="#0d1117", surface2="#161b27", border="#1e2738", muted="#64748b", text="#e2e8f0")
|
| 20 |
+
|
| 21 |
+
BASES = dict(AAPL=182, MSFT=415, GOOGL=175, AMZN=195, NVDA=875, META=520, TSLA=248)
|
| 22 |
+
|
| 23 |
+
def gen_series(ticker, horizon):
|
| 24 |
+
np.random.seed(hash(ticker + str(horizon)) % 2**31)
|
| 25 |
+
base = BASES[ticker]
|
| 26 |
+
hist_n = 90
|
| 27 |
+
hist_dates = pd.bdate_range(end=datetime.date.today(), periods=hist_n)
|
| 28 |
+
hist_prices = [base]
|
| 29 |
+
for _ in range(hist_n - 1):
|
| 30 |
+
hist_prices.append(hist_prices[-1] * (1 + np.random.normal(0.0003, 0.015)))
|
| 31 |
+
|
| 32 |
+
# In-sample predictions (last 30 days of history)
|
| 33 |
+
insample_n = 30
|
| 34 |
+
insample_pred = [p * (1 + np.random.normal(0, 0.007)) for p in hist_prices[-insample_n:]]
|
| 35 |
+
|
| 36 |
+
# Out-of-sample forecast
|
| 37 |
+
fcast_dates = pd.bdate_range(start=hist_dates[-1] + pd.Timedelta(days=1), periods=horizon)
|
| 38 |
+
drift = np.random.normal(0.0002, 0.0005)
|
| 39 |
+
fcast_mu = [hist_prices[-1]]
|
| 40 |
+
for _ in range(horizon - 1):
|
| 41 |
+
fcast_mu.append(fcast_mu[-1] * (1 + np.random.normal(drift, 0.012)))
|
| 42 |
+
# Widening CI
|
| 43 |
+
ci_width = [p * 0.015 * np.sqrt(i + 1) for i, p in enumerate(fcast_mu)]
|
| 44 |
+
ci_upper = [m + w for m, w in zip(fcast_mu, ci_width)]
|
| 45 |
+
ci_lower = [m - w for m, w in zip(fcast_mu, ci_width)]
|
| 46 |
+
|
| 47 |
+
# Accuracy metrics
|
| 48 |
+
actuals = hist_prices[-insample_n:]
|
| 49 |
+
mae = np.mean(np.abs(np.array(actuals) - np.array(insample_pred)))
|
| 50 |
+
rmse = np.sqrt(np.mean((np.array(actuals) - np.array(insample_pred)) ** 2))
|
| 51 |
+
mape = np.mean(np.abs((np.array(actuals) - np.array(insample_pred)) / np.array(actuals))) * 100
|
| 52 |
+
r2 = 1 - np.sum((np.array(actuals) - np.array(insample_pred))**2) / np.sum((np.array(actuals) - np.mean(actuals))**2)
|
| 53 |
+
|
| 54 |
+
return dict(
|
| 55 |
+
hist_dates=hist_dates, hist_prices=hist_prices,
|
| 56 |
+
insample_dates=hist_dates[-insample_n:], insample_pred=insample_pred,
|
| 57 |
+
fcast_dates=fcast_dates, fcast_mu=fcast_mu,
|
| 58 |
+
ci_upper=ci_upper, ci_lower=ci_lower,
|
| 59 |
+
mae=mae, rmse=rmse, mape=mape, r2=r2,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
def make_forecast_chart(data):
|
| 63 |
+
fig = go.Figure()
|
| 64 |
+
|
| 65 |
+
# Actual history (blue line)
|
| 66 |
+
fig.add_trace(go.Scatter(
|
| 67 |
+
x=data["hist_dates"], y=data["hist_prices"],
|
| 68 |
+
mode="lines", name="Actual",
|
| 69 |
+
line=dict(color="#00e5ff", width=2),
|
| 70 |
+
))
|
| 71 |
+
|
| 72 |
+
# In-sample prediction (dashed)
|
| 73 |
+
fig.add_trace(go.Scatter(
|
| 74 |
+
x=data["insample_dates"], y=data["insample_pred"],
|
| 75 |
+
mode="lines", name="In-sample fit",
|
| 76 |
+
line=dict(color="#7c3aed", width=1.5, dash="dot"),
|
| 77 |
+
))
|
| 78 |
+
|
| 79 |
+
# CI band (shaded)
|
| 80 |
+
fig.add_trace(go.Scatter(
|
| 81 |
+
x=list(data["fcast_dates"]) + list(data["fcast_dates"])[::-1],
|
| 82 |
+
y=list(data["ci_upper"]) + list(data["ci_lower"])[::-1],
|
| 83 |
+
fill="toself", fillcolor="rgba(0,229,255,0.08)",
|
| 84 |
+
line=dict(color="rgba(0,0,0,0)"), name="95% CI",
|
| 85 |
+
hoverinfo="skip",
|
| 86 |
+
))
|
| 87 |
+
|
| 88 |
+
# Forecast mean (grey)
|
| 89 |
+
fig.add_trace(go.Scatter(
|
| 90 |
+
x=data["fcast_dates"], y=data["fcast_mu"],
|
| 91 |
+
mode="lines", name="Forecast",
|
| 92 |
+
line=dict(color="#94a3b8", width=2, dash="dash"),
|
| 93 |
+
))
|
| 94 |
+
|
| 95 |
+
# Divider line
|
| 96 |
+
fig.add_vline(
|
| 97 |
+
x=str(data["hist_dates"][-1])[:10],
|
| 98 |
+
line=dict(color="#64748b", width=1, dash="dot"),
|
| 99 |
+
annotation_text="Forecast start",
|
| 100 |
+
annotation_font=dict(color="#64748b", size=11),
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
fig.update_layout(
|
| 104 |
+
paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
|
| 105 |
+
font=dict(color=COLORS["text"]), height=420,
|
| 106 |
+
xaxis=dict(showgrid=False, color=COLORS["muted"]),
|
| 107 |
+
yaxis=dict(showgrid=True, gridcolor=COLORS["border"], color=COLORS["muted"]),
|
| 108 |
+
legend=dict(bgcolor="rgba(0,0,0,0)", bordercolor=COLORS["border"]),
|
| 109 |
+
margin=dict(l=10, r=10, t=20, b=10),
|
| 110 |
+
hovermode="x unified",
|
| 111 |
+
)
|
| 112 |
+
return fig
|
| 113 |
+
|
| 114 |
+
def make_metrics(data):
|
| 115 |
+
tiles = [
|
| 116 |
+
("MAE", f"${data['mae']:.2f}", "Mean Abs Error", "neu"),
|
| 117 |
+
("RMSE", f"${data['rmse']:.2f}", "Root Mean Sq Error", "neg" if data["rmse"] > 5 else "pos"),
|
| 118 |
+
("MAPE", f"{data['mape']:.2f}%", "Mean Abs % Error", "neg" if data["mape"] > 3 else "pos"),
|
| 119 |
+
("R²", f"{data['r2']:.4f}", "Coeff of Determination", "pos" if data["r2"] > 0.9 else "neg"),
|
| 120 |
+
]
|
| 121 |
+
return [
|
| 122 |
+
html.Div([
|
| 123 |
+
html.Div(label, className="metric-tile-label"),
|
| 124 |
+
html.Div(val, className="metric-tile-value"),
|
| 125 |
+
html.Div(desc, className=f"metric-tile-delta {cls}"),
|
| 126 |
+
], className="metric-tile")
|
| 127 |
+
for label, val, desc, cls in tiles
|
| 128 |
+
]
|
| 129 |
+
|
| 130 |
+
# ── Layout ────────────────────────────────────────────────────────────────────
|
| 131 |
+
layout = html.Div([
|
| 132 |
+
html.Div([
|
| 133 |
+
html.Span("Ticker:", className="filter-label"),
|
| 134 |
+
dcc.Dropdown(
|
| 135 |
+
id="fc-ticker", options=[{"label": t, "value": t} for t in TICKERS],
|
| 136 |
+
value="AAPL", clearable=False, style={"width": "130px"},
|
| 137 |
+
),
|
| 138 |
+
html.Span("Horizon:", className="filter-label"),
|
| 139 |
+
dcc.RadioItems(
|
| 140 |
+
id="fc-horizon",
|
| 141 |
+
options=[{"label": f"{h}d", "value": h} for h in HORIZONS],
|
| 142 |
+
value=30, inline=True,
|
| 143 |
+
labelStyle={"marginRight": "14px", "color": "#64748b", "fontSize": "13px"},
|
| 144 |
+
),
|
| 145 |
+
], className="filter-bar"),
|
| 146 |
+
|
| 147 |
+
html.Div([
|
| 148 |
+
html.Div("Actual vs Forecast · Confidence Band", className="dash-card-title"),
|
| 149 |
+
dcc.Graph(id="fc-chart", config=dict(displayModeBar=True)),
|
| 150 |
+
html.Div([
|
| 151 |
+
html.Div(className="ci-box"),
|
| 152 |
+
html.Span("95% Confidence Interval"),
|
| 153 |
+
], className="ci-legend"),
|
| 154 |
+
], className="dash-card"),
|
| 155 |
+
|
| 156 |
+
html.Div([
|
| 157 |
+
html.Div("Model Accuracy Metrics — In-Sample (Last 30 Days)", className="dash-card-title"),
|
| 158 |
+
html.Div(id="fc-metrics", className="metric-grid"),
|
| 159 |
+
], className="dash-card"),
|
| 160 |
+
])
|
| 161 |
+
|
| 162 |
+
@callback(
|
| 163 |
+
Output("fc-chart", "figure"),
|
| 164 |
+
Output("fc-metrics", "children"),
|
| 165 |
+
Input("fc-ticker", "value"),
|
| 166 |
+
Input("fc-horizon", "value"),
|
| 167 |
+
)
|
| 168 |
+
def refresh(ticker, horizon):
|
| 169 |
+
data = gen_series(ticker, horizon)
|
| 170 |
+
return make_forecast_chart(data), make_metrics(data)
|
dashboard/pages/overview.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Page 1 — Market Overview
|
| 3 |
+
Live prices table, 1-day sparklines, market breadth gauge, top movers, sentiment heatmap.
|
| 4 |
+
Refreshes every 60 seconds via dcc.Interval.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import dash
|
| 8 |
+
from dash import html, dcc, Input, Output, callback
|
| 9 |
+
import plotly.graph_objects as go
|
| 10 |
+
import plotly.express as px
|
| 11 |
+
import pandas as pd
|
| 12 |
+
import numpy as np
|
| 13 |
+
import datetime, random
|
| 14 |
+
|
| 15 |
+
dash.register_page(__name__, path="/overview", name="Market Overview")
|
| 16 |
+
|
| 17 |
+
TICKERS = ["AAPL", "MSFT", "GOOGL", "AMZN", "NVDA", "META", "TSLA", "JPM", "GS", "SPY"]
|
| 18 |
+
COLORS = dict(accent="#00e5ff", green="#00c98d", red="#ff4d6d", surface="#0d1117", surface2="#161b27", border="#1e2738", muted="#64748b", text="#e2e8f0")
|
| 19 |
+
|
| 20 |
+
# ── Helpers ───────────────────────────────────────────────────────────────────
|
| 21 |
+
def _rng_price(base, n=78):
|
| 22 |
+
"""Simulate n intraday ticks starting from base."""
|
| 23 |
+
prices = [base]
|
| 24 |
+
for _ in range(n - 1):
|
| 25 |
+
prices.append(prices[-1] * (1 + np.random.normal(0, 0.003)))
|
| 26 |
+
return prices
|
| 27 |
+
|
| 28 |
+
def generate_market_data():
|
| 29 |
+
bases = dict(AAPL=182, MSFT=415, GOOGL=175, AMZN=195, NVDA=875, META=520,
|
| 30 |
+
TSLA=248, JPM=198, GS=462, SPY=510)
|
| 31 |
+
rows = []
|
| 32 |
+
for t in TICKERS:
|
| 33 |
+
prices = _rng_price(bases[t])
|
| 34 |
+
chg = (prices[-1] - prices[0]) / prices[0] * 100
|
| 35 |
+
rows.append(dict(
|
| 36 |
+
ticker=t, price=round(prices[-1], 2),
|
| 37 |
+
change=round(chg, 2),
|
| 38 |
+
volume=random.randint(5_000_000, 80_000_000),
|
| 39 |
+
mktcap=round(bases[t] * random.uniform(5e9, 3e12) / 1e12, 2),
|
| 40 |
+
sparkline=prices,
|
| 41 |
+
))
|
| 42 |
+
return rows
|
| 43 |
+
|
| 44 |
+
def make_sparkline(prices, color):
|
| 45 |
+
fig = go.Figure(go.Scatter(
|
| 46 |
+
y=prices, mode="lines",
|
| 47 |
+
line=dict(color=color, width=1.5),
|
| 48 |
+
fill="tozeroy",
|
| 49 |
+
fillcolor=color.replace(")", ", 0.1)").replace("rgb", "rgba") if "rgb" in color else color + "22",
|
| 50 |
+
))
|
| 51 |
+
fig.update_layout(
|
| 52 |
+
margin=dict(l=0, r=0, t=0, b=0), paper_bgcolor="rgba(0,0,0,0)",
|
| 53 |
+
plot_bgcolor="rgba(0,0,0,0)", xaxis=dict(visible=False), yaxis=dict(visible=False),
|
| 54 |
+
height=40, width=120,
|
| 55 |
+
)
|
| 56 |
+
return fig
|
| 57 |
+
|
| 58 |
+
def make_breadth_gauge(pct_up):
|
| 59 |
+
fig = go.Figure(go.Indicator(
|
| 60 |
+
mode="gauge+number",
|
| 61 |
+
value=pct_up,
|
| 62 |
+
number=dict(suffix="%", font=dict(color=COLORS["text"], size=28, family="JetBrains Mono")),
|
| 63 |
+
gauge=dict(
|
| 64 |
+
axis=dict(range=[0, 100], tickcolor=COLORS["muted"], tickfont=dict(color=COLORS["muted"])),
|
| 65 |
+
bar=dict(color=COLORS["accent"]),
|
| 66 |
+
bgcolor=COLORS["surface2"],
|
| 67 |
+
bordercolor=COLORS["border"],
|
| 68 |
+
steps=[
|
| 69 |
+
dict(range=[0, 40], color="rgba(255,77,109,.15)"),
|
| 70 |
+
dict(range=[40, 60], color="rgba(100,116,139,.1)"),
|
| 71 |
+
dict(range=[60,100], color="rgba(0,201,141,.15)"),
|
| 72 |
+
],
|
| 73 |
+
threshold=dict(line=dict(color=COLORS["accent"], width=2), thickness=.75, value=pct_up),
|
| 74 |
+
),
|
| 75 |
+
title=dict(text="Market Breadth — % Advancing", font=dict(color=COLORS["muted"], size=11)),
|
| 76 |
+
))
|
| 77 |
+
fig.update_layout(
|
| 78 |
+
paper_bgcolor="rgba(0,0,0,0)", font_color=COLORS["text"],
|
| 79 |
+
height=220, margin=dict(l=20, r=20, t=40, b=10),
|
| 80 |
+
)
|
| 81 |
+
return fig
|
| 82 |
+
|
| 83 |
+
def make_sentiment_heatmap(data):
|
| 84 |
+
tickers = [d["ticker"] for d in data]
|
| 85 |
+
values = [d["change"] for d in data]
|
| 86 |
+
fig = go.Figure(go.Treemap(
|
| 87 |
+
labels=tickers, parents=[""] * len(tickers),
|
| 88 |
+
values=[abs(v) + 1 for v in values],
|
| 89 |
+
customdata=list(zip(tickers, values)),
|
| 90 |
+
hovertemplate="<b>%{customdata[0]}</b><br>Change: %{customdata[1]:+.2f}%<extra></extra>",
|
| 91 |
+
marker=dict(
|
| 92 |
+
colors=values,
|
| 93 |
+
colorscale=[[0, "#ff4d6d"], [0.5, "#161b27"], [1, "#00c98d"]],
|
| 94 |
+
cmid=0,
|
| 95 |
+
line=dict(color="#050810", width=2),
|
| 96 |
+
),
|
| 97 |
+
texttemplate="<b>%{label}</b><br>%{customdata[1]:+.2f}%",
|
| 98 |
+
textfont=dict(color="white", size=13),
|
| 99 |
+
))
|
| 100 |
+
fig.update_layout(
|
| 101 |
+
paper_bgcolor="rgba(0,0,0,0)", margin=dict(l=0, r=0, t=0, b=0),
|
| 102 |
+
height=220,
|
| 103 |
+
)
|
| 104 |
+
return fig
|
| 105 |
+
|
| 106 |
+
# ── Layout ────────────────────────────────────────────────────────────────────
|
| 107 |
+
layout = html.Div([
|
| 108 |
+
dcc.Interval(id="ov-refresh", interval=60_000, n_intervals=0),
|
| 109 |
+
|
| 110 |
+
# Metric tiles (filled by callback)
|
| 111 |
+
html.Div(id="ov-metrics", className="metric-grid"),
|
| 112 |
+
|
| 113 |
+
html.Div([
|
| 114 |
+
# Prices table
|
| 115 |
+
html.Div([
|
| 116 |
+
html.Div("Live Prices", className="dash-card-title"),
|
| 117 |
+
html.Div(id="ov-table"),
|
| 118 |
+
], className="dash-card"),
|
| 119 |
+
|
| 120 |
+
# Right column: gauge + heatmap
|
| 121 |
+
html.Div([
|
| 122 |
+
html.Div([
|
| 123 |
+
html.Div("Market Breadth", className="dash-card-title"),
|
| 124 |
+
dcc.Graph(id="ov-gauge", config=dict(displayModeBar=False)),
|
| 125 |
+
], className="dash-card"),
|
| 126 |
+
html.Div([
|
| 127 |
+
html.Div("Sentiment Heatmap", className="dash-card-title"),
|
| 128 |
+
dcc.Graph(id="ov-heatmap", config=dict(displayModeBar=False)),
|
| 129 |
+
], className="dash-card"),
|
| 130 |
+
]),
|
| 131 |
+
], className="two-col"),
|
| 132 |
+
|
| 133 |
+
# Top movers
|
| 134 |
+
html.Div([
|
| 135 |
+
html.Div("Top Movers", className="dash-card-title"),
|
| 136 |
+
html.Div(id="ov-movers"),
|
| 137 |
+
], className="dash-card"),
|
| 138 |
+
])
|
| 139 |
+
|
| 140 |
+
# ── Callbacks ─────────────────────────────────────────────────────────────────
|
| 141 |
+
@callback(
|
| 142 |
+
Output("ov-metrics", "children"),
|
| 143 |
+
Output("ov-table", "children"),
|
| 144 |
+
Output("ov-gauge", "figure"),
|
| 145 |
+
Output("ov-heatmap", "figure"),
|
| 146 |
+
Output("ov-movers", "children"),
|
| 147 |
+
Input("ov-refresh", "n_intervals"),
|
| 148 |
+
)
|
| 149 |
+
def refresh(_):
|
| 150 |
+
data = generate_market_data()
|
| 151 |
+
advances = sum(1 for d in data if d["change"] > 0)
|
| 152 |
+
pct_up = round(advances / len(data) * 100, 1)
|
| 153 |
+
|
| 154 |
+
# ── Metric tiles ──────────────────────────────────────────────────────────
|
| 155 |
+
spy = next(d for d in data if d["ticker"] == "SPY")
|
| 156 |
+
best = max(data, key=lambda x: x["change"])
|
| 157 |
+
worst = min(data, key=lambda x: x["change"])
|
| 158 |
+
vol = sum(d["volume"] for d in data)
|
| 159 |
+
tiles = [
|
| 160 |
+
("SPY", f"${spy['price']}", f"{spy['change']:+.2f}%", "pos" if spy['change']>=0 else "neg"),
|
| 161 |
+
("Advancing",f"{advances}/{len(data)}", f"{pct_up}% up", "pos" if pct_up > 50 else "neg"),
|
| 162 |
+
("Best", best["ticker"], f"+{best['change']:.2f}%","pos"),
|
| 163 |
+
("Worst", worst["ticker"], f"{worst['change']:.2f}%","neg"),
|
| 164 |
+
("Volume", f"{vol/1e9:.1f}B", "shares traded", "neu"),
|
| 165 |
+
]
|
| 166 |
+
metric_els = [
|
| 167 |
+
html.Div([
|
| 168 |
+
html.Div(label, className="metric-tile-label"),
|
| 169 |
+
html.Div(value, className="metric-tile-value"),
|
| 170 |
+
html.Div(delta, className=f"metric-tile-delta {cls}"),
|
| 171 |
+
], className="metric-tile")
|
| 172 |
+
for label, value, delta, cls in tiles
|
| 173 |
+
]
|
| 174 |
+
|
| 175 |
+
# ── Prices table ──────────────────────────────────────────────────────────
|
| 176 |
+
rows = []
|
| 177 |
+
for d in data:
|
| 178 |
+
color = COLORS["green"] if d["change"] >= 0 else COLORS["red"]
|
| 179 |
+
spark = make_sparkline(d["sparkline"], color)
|
| 180 |
+
badge = "badge-pos" if d["change"] >= 0 else "badge-neg"
|
| 181 |
+
rows.append(html.Tr([
|
| 182 |
+
html.Td(html.Strong(d["ticker"]), style={"color": COLORS["text"]}),
|
| 183 |
+
html.Td(f"${d['price']:,.2f}"),
|
| 184 |
+
html.Td(html.Span(f"{d['change']:+.2f}%", className=badge)),
|
| 185 |
+
html.Td(f"{d['volume']/1e6:.1f}M"),
|
| 186 |
+
html.Td(f"${d['mktcap']:.2f}T"),
|
| 187 |
+
html.Td(dcc.Graph(figure=spark, config=dict(displayModeBar=False), style=dict(height="40px", width="120px"))),
|
| 188 |
+
]))
|
| 189 |
+
table = html.Table([
|
| 190 |
+
html.Thead(html.Tr([html.Th(h) for h in ["Ticker","Price","Change","Volume","Mkt Cap","1D Spark"]])),
|
| 191 |
+
html.Tbody(rows),
|
| 192 |
+
], className="dash-table")
|
| 193 |
+
|
| 194 |
+
# ── Top movers ────────────────────────────────────────────────────────────
|
| 195 |
+
sorted_data = sorted(data, key=lambda x: x["change"], reverse=True)
|
| 196 |
+
gainers = sorted_data[:3]
|
| 197 |
+
losers = sorted_data[-3:][::-1]
|
| 198 |
+
mover_els = []
|
| 199 |
+
for label, items, cls in [("Gainers", gainers, "pos"), ("Losers", losers, "neg")]:
|
| 200 |
+
mover_els.append(html.Div([
|
| 201 |
+
html.Div(label, className=f"dash-card-title {cls}"),
|
| 202 |
+
html.Div([
|
| 203 |
+
html.Div([
|
| 204 |
+
html.Strong(d["ticker"], style={"color": COLORS["text"], "marginRight": "10px"}),
|
| 205 |
+
html.Span(f"{d['change']:+.2f}%", className=f"badge-{'pos' if d['change']>0 else 'neg'}"),
|
| 206 |
+
], style={"padding": "8px 0", "borderBottom": f"1px solid {COLORS['border']}"})
|
| 207 |
+
for d in items
|
| 208 |
+
]),
|
| 209 |
+
], style={"flex": "1"}))
|
| 210 |
+
movers_layout = html.Div(mover_els, style={"display": "flex", "gap": "40px"})
|
| 211 |
+
|
| 212 |
+
return metric_els, table, make_breadth_gauge(pct_up), make_sentiment_heatmap(data), movers_layout
|
dashboard/pages/portfolio.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Page 4 — Portfolio Optimiser
|
| 3 |
+
Pie chart of optimal weights, efficient frontier scatter,
|
| 4 |
+
Sharpe/Sortino metrics, rebalancing suggestions.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import dash
|
| 8 |
+
from dash import html, dcc, Input, Output, callback
|
| 9 |
+
import plotly.graph_objects as go
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
dash.register_page(__name__, path="/portfolio", name="Portfolio Optimiser")
|
| 13 |
+
|
| 14 |
+
TICKERS = ["AAPL", "MSFT", "GOOGL", "AMZN", "NVDA", "META", "TSLA", "JPM", "GS"]
|
| 15 |
+
COLORS = dict(accent="#00e5ff", green="#00c98d", red="#ff4d6d", orange="#ff8c42",
|
| 16 |
+
surface="#0d1117", surface2="#161b27", border="#1e2738", muted="#64748b", text="#e2e8f0")
|
| 17 |
+
PALETTE = ["#00e5ff","#7c3aed","#00c98d","#ff8c42","#ff4d6d","#38bdf8","#a78bfa","#34d399","#fbbf24"]
|
| 18 |
+
|
| 19 |
+
def simulate_frontier(n_portfolios=600, n_assets=9, seed=42):
|
| 20 |
+
np.random.seed(seed)
|
| 21 |
+
mu = np.random.uniform(0.06, 0.22, n_assets)
|
| 22 |
+
sigma = np.random.uniform(0.12, 0.35, n_assets)
|
| 23 |
+
corr = np.eye(n_assets)
|
| 24 |
+
for i in range(n_assets):
|
| 25 |
+
for j in range(i+1, n_assets):
|
| 26 |
+
r = np.random.uniform(0.1, 0.7)
|
| 27 |
+
corr[i,j] = corr[j,i] = r
|
| 28 |
+
cov = np.outer(sigma, sigma) * corr
|
| 29 |
+
|
| 30 |
+
vols, rets, sharpes, weights = [], [], [], []
|
| 31 |
+
for _ in range(n_portfolios):
|
| 32 |
+
w = np.random.dirichlet(np.ones(n_assets))
|
| 33 |
+
r = w @ mu
|
| 34 |
+
v = np.sqrt(w @ cov @ w)
|
| 35 |
+
s = r / v
|
| 36 |
+
vols.append(v); rets.append(r); sharpes.append(s); weights.append(w)
|
| 37 |
+
|
| 38 |
+
best_idx = int(np.argmax(sharpes))
|
| 39 |
+
return dict(
|
| 40 |
+
vols=vols, rets=rets, sharpes=sharpes,
|
| 41 |
+
opt_vol=vols[best_idx], opt_ret=rets[best_idx], opt_sharpe=sharpes[best_idx],
|
| 42 |
+
opt_weights=weights[best_idx],
|
| 43 |
+
mu=mu, sigma=sigma,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
def make_frontier(data):
|
| 47 |
+
fig = go.Figure()
|
| 48 |
+
fig.add_trace(go.Scatter(
|
| 49 |
+
x=data["vols"], y=data["rets"],
|
| 50 |
+
mode="markers",
|
| 51 |
+
marker=dict(
|
| 52 |
+
color=data["sharpes"], colorscale="Turbo",
|
| 53 |
+
size=5, opacity=0.6,
|
| 54 |
+
colorbar=dict(title="Sharpe", tickfont=dict(color=COLORS["muted"]), titlefont=dict(color=COLORS["muted"])),
|
| 55 |
+
),
|
| 56 |
+
name="Portfolios",
|
| 57 |
+
hovertemplate="Vol: %{x:.1%}<br>Ret: %{y:.1%}<extra></extra>",
|
| 58 |
+
))
|
| 59 |
+
fig.add_trace(go.Scatter(
|
| 60 |
+
x=[data["opt_vol"]], y=[data["opt_ret"]],
|
| 61 |
+
mode="markers",
|
| 62 |
+
marker=dict(symbol="star", color=COLORS["accent"], size=16, line=dict(color="white", width=1)),
|
| 63 |
+
name=f"Optimal (Sharpe={data['opt_sharpe']:.2f})",
|
| 64 |
+
hovertemplate=f"Optimal Portfolio<br>Vol: {data['opt_vol']:.1%}<br>Ret: {data['opt_ret']:.1%}<br>Sharpe: {data['opt_sharpe']:.2f}<extra></extra>",
|
| 65 |
+
))
|
| 66 |
+
fig.update_layout(
|
| 67 |
+
paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
|
| 68 |
+
font=dict(color=COLORS["text"]), height=360,
|
| 69 |
+
xaxis=dict(title="Volatility (Ann.)", showgrid=True, gridcolor=COLORS["border"], color=COLORS["muted"], tickformat=".0%"),
|
| 70 |
+
yaxis=dict(title="Return (Ann.)", showgrid=True, gridcolor=COLORS["border"], color=COLORS["muted"], tickformat=".0%"),
|
| 71 |
+
legend=dict(bgcolor="rgba(0,0,0,0)", bordercolor=COLORS["border"]),
|
| 72 |
+
margin=dict(l=10, r=10, t=20, b=10),
|
| 73 |
+
)
|
| 74 |
+
return fig
|
| 75 |
+
|
| 76 |
+
def make_pie(weights):
|
| 77 |
+
fig = go.Figure(go.Pie(
|
| 78 |
+
labels=TICKERS,
|
| 79 |
+
values=[round(w, 4) for w in weights],
|
| 80 |
+
hole=0.45,
|
| 81 |
+
marker=dict(colors=PALETTE, line=dict(color="#050810", width=2)),
|
| 82 |
+
textinfo="label+percent",
|
| 83 |
+
textfont=dict(size=12, color="white"),
|
| 84 |
+
hovertemplate="<b>%{label}</b><br>Weight: %{value:.1%}<extra></extra>",
|
| 85 |
+
))
|
| 86 |
+
fig.update_layout(
|
| 87 |
+
paper_bgcolor="rgba(0,0,0,0)",
|
| 88 |
+
font=dict(color=COLORS["text"]), height=300,
|
| 89 |
+
legend=dict(bgcolor="rgba(0,0,0,0)", font=dict(size=11)),
|
| 90 |
+
margin=dict(l=0, r=0, t=0, b=0),
|
| 91 |
+
annotations=[dict(text="Optimal", x=0.5, y=0.5, font_size=14, showarrow=False, font_color=COLORS["muted"])],
|
| 92 |
+
)
|
| 93 |
+
return fig
|
| 94 |
+
|
| 95 |
+
def metrics_tiles(data, current_weights):
|
| 96 |
+
rf = 0.052
|
| 97 |
+
ann_ret = data["opt_ret"]
|
| 98 |
+
ann_vol = data["opt_vol"]
|
| 99 |
+
sharpe = (ann_ret - rf) / ann_vol
|
| 100 |
+
sortino_v = ann_vol * 0.7
|
| 101 |
+
sortino = (ann_ret - rf) / sortino_v
|
| 102 |
+
max_dd = np.random.uniform(-0.18, -0.08)
|
| 103 |
+
tiles = [
|
| 104 |
+
("Sharpe Ratio", f"{sharpe:.3f}", "> 1.0 target", "pos" if sharpe > 1 else "neg"),
|
| 105 |
+
("Sortino Ratio", f"{sortino:.3f}", "> 1.5 target", "pos" if sortino > 1.5 else "neg"),
|
| 106 |
+
("Ann. Return", f"{ann_ret:.1%}", "Expected", "pos"),
|
| 107 |
+
("Ann. Volatility",f"{ann_vol:.1%}","Portfolio risk", "neu"),
|
| 108 |
+
("Max Drawdown", f"{max_dd:.1%}", "Historical", "neg"),
|
| 109 |
+
]
|
| 110 |
+
return [
|
| 111 |
+
html.Div([
|
| 112 |
+
html.Div(label, className="metric-tile-label"),
|
| 113 |
+
html.Div(val, className="metric-tile-value"),
|
| 114 |
+
html.Div(desc, className=f"metric-tile-delta {cls}"),
|
| 115 |
+
], className="metric-tile")
|
| 116 |
+
for label, val, desc, cls in tiles
|
| 117 |
+
]
|
| 118 |
+
|
| 119 |
+
def rebalance_table(opt_weights, current_weights):
|
| 120 |
+
rows = []
|
| 121 |
+
for t, opt, cur in zip(TICKERS, opt_weights, current_weights):
|
| 122 |
+
diff = opt - cur
|
| 123 |
+
cls = "badge-pos" if diff > 0.005 else ("badge-neg" if diff < -0.005 else "badge-neu")
|
| 124 |
+
label = "BUY" if diff > 0.005 else ("SELL" if diff < -0.005 else "HOLD")
|
| 125 |
+
rows.append(html.Tr([
|
| 126 |
+
html.Td(t), html.Td(f"{cur:.1%}"), html.Td(f"{opt:.1%}"),
|
| 127 |
+
html.Td(f"{diff:+.1%}", className="pos" if diff > 0 else "neg"),
|
| 128 |
+
html.Td(html.Span(label, className=cls)),
|
| 129 |
+
]))
|
| 130 |
+
return html.Table([
|
| 131 |
+
html.Thead(html.Tr([html.Th(h) for h in ["Ticker","Current","Optimal","Δ Weight","Action"]])),
|
| 132 |
+
html.Tbody(rows),
|
| 133 |
+
], className="dash-table")
|
| 134 |
+
|
| 135 |
+
# ── Layout ────────────────────────────────────────────────────────────────────
|
| 136 |
+
layout = html.Div([
|
| 137 |
+
html.Div([
|
| 138 |
+
html.Span("Objective:", className="filter-label"),
|
| 139 |
+
dcc.RadioItems(
|
| 140 |
+
id="po-objective",
|
| 141 |
+
options=[{"label": l, "value": v} for l, v in [("Max Sharpe","sharpe"),("Min Volatility","minvol"),("Max Return","maxret")]],
|
| 142 |
+
value="sharpe", inline=True,
|
| 143 |
+
labelStyle={"marginRight": "14px", "color": "#64748b", "fontSize": "13px"},
|
| 144 |
+
),
|
| 145 |
+
html.Span("Risk-free rate:", className="filter-label"),
|
| 146 |
+
dcc.Input(id="po-rf", type="number", value=5.2, min=0, max=15, step=0.1,
|
| 147 |
+
style={"width": "80px", "background": "#161b27", "border": "1px solid #1e2738",
|
| 148 |
+
"color": "#e2e8f0", "borderRadius": "4px", "padding": "4px 8px"}),
|
| 149 |
+
html.Span("%", style={"color": "#64748b"}),
|
| 150 |
+
], className="filter-bar"),
|
| 151 |
+
|
| 152 |
+
html.Div([
|
| 153 |
+
html.Div([
|
| 154 |
+
html.Div("Optimal Portfolio Weights", className="dash-card-title"),
|
| 155 |
+
dcc.Graph(id="po-pie", config=dict(displayModeBar=False)),
|
| 156 |
+
], className="dash-card"),
|
| 157 |
+
html.Div([
|
| 158 |
+
html.Div("Efficient Frontier", className="dash-card-title"),
|
| 159 |
+
dcc.Graph(id="po-frontier", config=dict(displayModeBar=True)),
|
| 160 |
+
], className="dash-card"),
|
| 161 |
+
], className="two-col"),
|
| 162 |
+
|
| 163 |
+
html.Div([
|
| 164 |
+
html.Div("Risk / Return Metrics", className="dash-card-title"),
|
| 165 |
+
html.Div(id="po-metrics", className="metric-grid"),
|
| 166 |
+
], className="dash-card"),
|
| 167 |
+
|
| 168 |
+
html.Div([
|
| 169 |
+
html.Div("Rebalancing Suggestions vs Current Allocation", className="dash-card-title"),
|
| 170 |
+
html.Div(id="po-rebalance"),
|
| 171 |
+
], className="dash-card"),
|
| 172 |
+
])
|
| 173 |
+
|
| 174 |
+
@callback(
|
| 175 |
+
Output("po-pie", "figure"),
|
| 176 |
+
Output("po-frontier", "figure"),
|
| 177 |
+
Output("po-metrics", "children"),
|
| 178 |
+
Output("po-rebalance", "children"),
|
| 179 |
+
Input("po-objective", "value"),
|
| 180 |
+
Input("po-rf", "value"),
|
| 181 |
+
)
|
| 182 |
+
def refresh(objective, rf):
|
| 183 |
+
data = simulate_frontier()
|
| 184 |
+
# Simulate current (sub-optimal) allocation
|
| 185 |
+
np.random.seed(99)
|
| 186 |
+
current = np.random.dirichlet(np.ones(len(TICKERS)))
|
| 187 |
+
return (
|
| 188 |
+
make_pie(data["opt_weights"]),
|
| 189 |
+
make_frontier(data),
|
| 190 |
+
metrics_tiles(data, current),
|
| 191 |
+
rebalance_table(data["opt_weights"], current),
|
| 192 |
+
)
|
dashboard/pages/sentiment.py
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Page 5 — Sentiment Analysis
|
| 3 |
+
News feed with FinBERT score badges, 30-day sentiment timeline,
|
| 4 |
+
correlation between sentiment and next-day returns.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import dash
|
| 8 |
+
from dash import html, dcc, Input, Output, callback
|
| 9 |
+
import plotly.graph_objects as go
|
| 10 |
+
import pandas as pd
|
| 11 |
+
import numpy as np
|
| 12 |
+
import datetime, random
|
| 13 |
+
|
| 14 |
+
dash.register_page(__name__, path="/sentiment", name="Sentiment Analysis")
|
| 15 |
+
|
| 16 |
+
TICKERS = ["AAPL", "MSFT", "GOOGL", "AMZN", "NVDA", "META", "TSLA"]
|
| 17 |
+
COLORS = dict(accent="#00e5ff", green="#00c98d", red="#ff4d6d", orange="#ff8c42",
|
| 18 |
+
surface="#0d1117", surface2="#161b27", border="#1e2738", muted="#64748b", text="#e2e8f0")
|
| 19 |
+
|
| 20 |
+
HEADLINES = [
|
| 21 |
+
"{t} beats earnings estimates by 8% as cloud revenue surges",
|
| 22 |
+
"Analysts upgrade {t} to Strong Buy ahead of product launch",
|
| 23 |
+
"{t} faces regulatory scrutiny over data privacy practices",
|
| 24 |
+
"{t} announces $10B share buyback programme",
|
| 25 |
+
"Supply chain disruption hits {t} quarterly guidance",
|
| 26 |
+
"{t} expands AI integration across flagship product line",
|
| 27 |
+
"Activist investor takes stake in {t}, pushes for restructuring",
|
| 28 |
+
"{t} CEO signals optimism for second-half recovery",
|
| 29 |
+
"{t} misses revenue target; stock falls in after-hours trading",
|
| 30 |
+
"{t} secures major government contract worth $2.4B",
|
| 31 |
+
"Labour concerns at {t} facilities spark union talks",
|
| 32 |
+
"{t} launches next-gen chip platform outperforming rivals",
|
| 33 |
+
]
|
| 34 |
+
SOURCES = ["Reuters", "Bloomberg", "CNBC", "WSJ", "FT", "MarketWatch", "The Verge", "Barron's"]
|
| 35 |
+
|
| 36 |
+
def gen_news(ticker, n=8):
|
| 37 |
+
items = []
|
| 38 |
+
base_dt = datetime.datetime.utcnow()
|
| 39 |
+
for i in range(n):
|
| 40 |
+
score = round(np.random.uniform(-1, 1), 3)
|
| 41 |
+
dt = base_dt - datetime.timedelta(hours=random.randint(1, 48))
|
| 42 |
+
items.append(dict(
|
| 43 |
+
headline=random.choice(HEADLINES).replace("{t}", ticker),
|
| 44 |
+
source=random.choice(SOURCES),
|
| 45 |
+
score=score,
|
| 46 |
+
label="Positive" if score > 0.15 else ("Negative" if score < -0.15 else "Neutral"),
|
| 47 |
+
ts=dt.strftime("%b %d · %H:%M"),
|
| 48 |
+
))
|
| 49 |
+
return sorted(items, key=lambda x: x["ts"], reverse=True)
|
| 50 |
+
|
| 51 |
+
def gen_sentiment_ts(ticker, n=30):
|
| 52 |
+
np.random.seed(hash(ticker) % 2**31)
|
| 53 |
+
dates = pd.bdate_range(end=datetime.date.today(), periods=n)
|
| 54 |
+
scores = np.random.uniform(-0.6, 0.8, n)
|
| 55 |
+
# smooth
|
| 56 |
+
scores = pd.Series(scores).ewm(span=5).mean().values
|
| 57 |
+
returns = scores * np.random.uniform(0.3, 0.7, n) + np.random.normal(0, 0.008, n)
|
| 58 |
+
return dates, scores, returns
|
| 59 |
+
|
| 60 |
+
def make_sentiment_timeline(ticker):
|
| 61 |
+
dates, scores, _ = gen_sentiment_ts(ticker)
|
| 62 |
+
fig = go.Figure()
|
| 63 |
+
colors = [COLORS["green"] if s > 0.1 else (COLORS["red"] if s < -0.1 else COLORS["muted"]) for s in scores]
|
| 64 |
+
fig.add_trace(go.Bar(
|
| 65 |
+
x=dates, y=scores, marker_color=colors, name="Daily Sentiment",
|
| 66 |
+
hovertemplate="%{x|%b %d}<br>Score: %{y:.3f}<extra></extra>",
|
| 67 |
+
))
|
| 68 |
+
fig.add_trace(go.Scatter(
|
| 69 |
+
x=dates, y=pd.Series(scores).rolling(5).mean(),
|
| 70 |
+
mode="lines", line=dict(color=COLORS["accent"], width=2),
|
| 71 |
+
name="5-day MA",
|
| 72 |
+
))
|
| 73 |
+
fig.add_hline(y=0, line=dict(color=COLORS["border"], width=1))
|
| 74 |
+
fig.update_layout(
|
| 75 |
+
paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
|
| 76 |
+
font=dict(color=COLORS["text"]), height=240,
|
| 77 |
+
xaxis=dict(showgrid=False, color=COLORS["muted"]),
|
| 78 |
+
yaxis=dict(showgrid=True, gridcolor=COLORS["border"], color=COLORS["muted"], range=[-1, 1]),
|
| 79 |
+
legend=dict(bgcolor="rgba(0,0,0,0)"),
|
| 80 |
+
margin=dict(l=10, r=10, t=10, b=10),
|
| 81 |
+
barmode="overlay",
|
| 82 |
+
)
|
| 83 |
+
return fig
|
| 84 |
+
|
| 85 |
+
def make_correlation_scatter(ticker):
|
| 86 |
+
dates, scores, returns = gen_sentiment_ts(ticker, n=60)
|
| 87 |
+
corr = np.corrcoef(scores, returns)[0, 1]
|
| 88 |
+
fig = go.Figure(go.Scatter(
|
| 89 |
+
x=scores, y=returns,
|
| 90 |
+
mode="markers",
|
| 91 |
+
marker=dict(
|
| 92 |
+
color=scores, colorscale=[[0,"#ff4d6d"],[0.5,"#64748b"],[1,"#00c98d"]],
|
| 93 |
+
size=7, opacity=0.75, cmid=0,
|
| 94 |
+
),
|
| 95 |
+
hovertemplate="Sentiment: %{x:.3f}<br>Next-day return: %{y:.2%}<extra></extra>",
|
| 96 |
+
))
|
| 97 |
+
# Trend line
|
| 98 |
+
m, b = np.polyfit(scores, returns, 1)
|
| 99 |
+
xs = np.linspace(min(scores), max(scores), 50)
|
| 100 |
+
fig.add_trace(go.Scatter(
|
| 101 |
+
x=xs, y=m*xs+b, mode="lines",
|
| 102 |
+
line=dict(color=COLORS["accent"], width=2, dash="dot"),
|
| 103 |
+
name=f"Trend (r={corr:.2f})",
|
| 104 |
+
))
|
| 105 |
+
fig.update_layout(
|
| 106 |
+
paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
|
| 107 |
+
font=dict(color=COLORS["text"]), height=240,
|
| 108 |
+
xaxis=dict(title="Sentiment Score", showgrid=True, gridcolor=COLORS["border"], color=COLORS["muted"]),
|
| 109 |
+
yaxis=dict(title="Next-day Return", showgrid=True, gridcolor=COLORS["border"], color=COLORS["muted"], tickformat=".1%"),
|
| 110 |
+
legend=dict(bgcolor="rgba(0,0,0,0)"),
|
| 111 |
+
margin=dict(l=10, r=10, t=10, b=10),
|
| 112 |
+
)
|
| 113 |
+
return fig, corr
|
| 114 |
+
|
| 115 |
+
def make_news_feed(news):
|
| 116 |
+
items = []
|
| 117 |
+
for n in news:
|
| 118 |
+
badge_cls = "badge-pos" if n["label"] == "Positive" else ("badge-neg" if n["label"] == "Negative" else "badge-neu")
|
| 119 |
+
items.append(html.Div([
|
| 120 |
+
html.Div([
|
| 121 |
+
html.Span(f"{n['score']:+.3f}", className=badge_cls),
|
| 122 |
+
], style={"flexShrink": "0", "paddingTop": "2px"}),
|
| 123 |
+
html.Div([
|
| 124 |
+
html.P(n["headline"], className="news-headline"),
|
| 125 |
+
html.P(f"{n['source']} · {n['ts']}", className="news-meta"),
|
| 126 |
+
]),
|
| 127 |
+
], className="news-item"))
|
| 128 |
+
return html.Div(items)
|
| 129 |
+
|
| 130 |
+
def agg_metrics(ticker):
|
| 131 |
+
_, scores, returns = gen_sentiment_ts(ticker, 30)
|
| 132 |
+
avg = np.mean(scores)
|
| 133 |
+
pct_pos = np.mean(scores > 0.1) * 100
|
| 134 |
+
corr = np.corrcoef(scores, returns)[0, 1]
|
| 135 |
+
tiles = [
|
| 136 |
+
("Avg Sentiment", f"{avg:+.3f}", "30-day mean", "pos" if avg > 0 else "neg"),
|
| 137 |
+
("% Positive", f"{pct_pos:.0f}%","Days bullish", "pos" if pct_pos > 50 else "neg"),
|
| 138 |
+
("Sentiment–Ret Corr", f"{corr:.3f}", "Predictive power","pos" if corr > 0.1 else ("neg" if corr < -0.1 else "neu")),
|
| 139 |
+
]
|
| 140 |
+
return [
|
| 141 |
+
html.Div([
|
| 142 |
+
html.Div(label, className="metric-tile-label"),
|
| 143 |
+
html.Div(val, className="metric-tile-value"),
|
| 144 |
+
html.Div(desc, className=f"metric-tile-delta {cls}"),
|
| 145 |
+
], className="metric-tile")
|
| 146 |
+
for label, val, desc, cls in tiles
|
| 147 |
+
]
|
| 148 |
+
|
| 149 |
+
# ── Layout ────────────────────────────────────────────────────────────────────
|
| 150 |
+
layout = html.Div([
|
| 151 |
+
html.Div([
|
| 152 |
+
html.Span("Ticker:", className="filter-label"),
|
| 153 |
+
dcc.Dropdown(
|
| 154 |
+
id="sn-ticker", options=[{"label": t, "value": t} for t in TICKERS],
|
| 155 |
+
value="NVDA", clearable=False, style={"width": "130px"},
|
| 156 |
+
),
|
| 157 |
+
], className="filter-bar"),
|
| 158 |
+
|
| 159 |
+
html.Div(id="sn-metrics", className="metric-grid", style={"marginBottom": "20px"}),
|
| 160 |
+
|
| 161 |
+
html.Div([
|
| 162 |
+
html.Div([
|
| 163 |
+
html.Div("FinBERT News Feed", className="dash-card-title"),
|
| 164 |
+
html.Div(id="sn-feed"),
|
| 165 |
+
], className="dash-card"),
|
| 166 |
+
html.Div([
|
| 167 |
+
html.Div([
|
| 168 |
+
html.Div("30-Day Sentiment Timeline", className="dash-card-title"),
|
| 169 |
+
dcc.Graph(id="sn-timeline", config=dict(displayModeBar=False)),
|
| 170 |
+
], className="dash-card"),
|
| 171 |
+
html.Div([
|
| 172 |
+
html.Div("Sentiment vs Next-Day Return", className="dash-card-title"),
|
| 173 |
+
dcc.Graph(id="sn-corr", config=dict(displayModeBar=False)),
|
| 174 |
+
html.Div(id="sn-corr-label", style={"marginTop": "8px", "fontSize": "12px", "color": "#64748b", "fontFamily": "JetBrains Mono"}),
|
| 175 |
+
], className="dash-card"),
|
| 176 |
+
]),
|
| 177 |
+
], className="two-col"),
|
| 178 |
+
])
|
| 179 |
+
|
| 180 |
+
@callback(
|
| 181 |
+
Output("sn-metrics", "children"),
|
| 182 |
+
Output("sn-feed", "children"),
|
| 183 |
+
Output("sn-timeline", "figure"),
|
| 184 |
+
Output("sn-corr", "figure"),
|
| 185 |
+
Output("sn-corr-label", "children"),
|
| 186 |
+
Input("sn-ticker", "value"),
|
| 187 |
+
)
|
| 188 |
+
def refresh(ticker):
|
| 189 |
+
random.seed(hash(ticker))
|
| 190 |
+
np.random.seed(hash(ticker) % 2**31)
|
| 191 |
+
news = gen_news(ticker)
|
| 192 |
+
timeline_fig = make_sentiment_timeline(ticker)
|
| 193 |
+
corr_fig, corr = make_correlation_scatter(ticker)
|
| 194 |
+
corr_label = f"Pearson r = {corr:.3f} ({'positive' if corr > 0 else 'negative'} correlation)"
|
| 195 |
+
return (
|
| 196 |
+
agg_metrics(ticker),
|
| 197 |
+
make_news_feed(news),
|
| 198 |
+
timeline_fig,
|
| 199 |
+
corr_fig,
|
| 200 |
+
corr_label,
|
| 201 |
+
)
|
ml/portfolio_optimizer.py
CHANGED
|
@@ -15,6 +15,7 @@ logger = get_logger(__name__)
|
|
| 15 |
TICKERS = ['AAPL', 'MSFT', 'NVDA', 'TSLA', 'GOOGL']
|
| 16 |
RISK_FREE_RATE = 0.05 # 5% annual
|
| 17 |
TRADING_DAYS = 252 # days in a trading year
|
|
|
|
| 18 |
def neg_sharpe(weights, mean_returns, cov_matrix):
|
| 19 |
port_returns = np.sum(mean_returns * weights ) * TRADING_DAYS
|
| 20 |
port_volatility = np.sqrt(weights @ cov_matrix @ weights) * np.sqrt(TRADING_DAYS)
|
|
@@ -93,7 +94,6 @@ def black_litterman(returns_df: pd.DataFrame,
|
|
| 93 |
)
|
| 94 |
return result.x
|
| 95 |
|
| 96 |
-
|
| 97 |
|
| 98 |
|
| 99 |
def kelly_criterion(returns_df: pd.DataFrame) -> np.ndarray:
|
|
|
|
| 15 |
TICKERS = ['AAPL', 'MSFT', 'NVDA', 'TSLA', 'GOOGL']
|
| 16 |
RISK_FREE_RATE = 0.05 # 5% annual
|
| 17 |
TRADING_DAYS = 252 # days in a trading year
|
| 18 |
+
|
| 19 |
def neg_sharpe(weights, mean_returns, cov_matrix):
|
| 20 |
port_returns = np.sum(mean_returns * weights ) * TRADING_DAYS
|
| 21 |
port_volatility = np.sqrt(weights @ cov_matrix @ weights) * np.sqrt(TRADING_DAYS)
|
|
|
|
| 94 |
)
|
| 95 |
return result.x
|
| 96 |
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
def kelly_criterion(returns_df: pd.DataFrame) -> np.ndarray:
|
pyproject.toml
CHANGED
|
@@ -7,6 +7,8 @@ requires-python = "==3.11.*"
|
|
| 7 |
dependencies = [
|
| 8 |
"apache-airflow>=2.10.5",
|
| 9 |
"ccxt>=4.5.40",
|
|
|
|
|
|
|
| 10 |
"dotenv>=0.9.9",
|
| 11 |
"graphviz>=0.21",
|
| 12 |
"mlflow>=2.10.0",
|
|
|
|
| 7 |
dependencies = [
|
| 8 |
"apache-airflow>=2.10.5",
|
| 9 |
"ccxt>=4.5.40",
|
| 10 |
+
"dash>=4.0.0",
|
| 11 |
+
"dash-bootstrap-components>=2.0.4",
|
| 12 |
"dotenv>=0.9.9",
|
| 13 |
"graphviz>=0.21",
|
| 14 |
"mlflow>=2.10.0",
|
uv.lock
CHANGED
|
@@ -667,6 +667,38 @@ wheels = [
|
|
| 667 |
{ url = "https://files.pythonhosted.org/packages/e7/05/c19819d5e3d95294a6f5947fb9b9629efb316b96de511b418c53d245aae6/cycler-0.12.1-py3-none-any.whl", hash = "sha256:85cef7cff222d8644161529808465972e51340599459b8ac3ccbac5a854e0d30", size = 8321, upload-time = "2023-10-07T05:32:16.783Z" },
|
| 668 |
]
|
| 669 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 670 |
[[package]]
|
| 671 |
name = "databricks-sdk"
|
| 672 |
version = "0.94.0"
|
|
@@ -807,6 +839,8 @@ source = { virtual = "." }
|
|
| 807 |
dependencies = [
|
| 808 |
{ name = "apache-airflow", marker = "sys_platform == 'linux'" },
|
| 809 |
{ name = "ccxt", marker = "sys_platform == 'linux'" },
|
|
|
|
|
|
|
| 810 |
{ name = "dotenv", marker = "sys_platform == 'linux'" },
|
| 811 |
{ name = "graphviz", marker = "sys_platform == 'linux'" },
|
| 812 |
{ name = "mlflow", marker = "sys_platform == 'linux'" },
|
|
@@ -829,6 +863,8 @@ dependencies = [
|
|
| 829 |
requires-dist = [
|
| 830 |
{ name = "apache-airflow", specifier = ">=2.10.5" },
|
| 831 |
{ name = "ccxt", specifier = ">=4.5.40" },
|
|
|
|
|
|
|
| 832 |
{ name = "dotenv", specifier = ">=0.9.9" },
|
| 833 |
{ name = "graphviz", specifier = ">=0.21" },
|
| 834 |
{ name = "mlflow", specifier = ">=2.10.0" },
|
|
@@ -1564,6 +1600,15 @@ version = "0.0.12"
|
|
| 1564 |
source = { registry = "https://pypi.org/simple" }
|
| 1565 |
sdist = { url = "https://files.pythonhosted.org/packages/17/0d/74f0293dfd7dcc3837746d0138cbedd60b31701ecc75caec7d3f281feba0/multitasking-0.0.12.tar.gz", hash = "sha256:2fba2fa8ed8c4b85e227c5dd7dc41c7d658de3b6f247927316175a57349b84d1", size = 19984, upload-time = "2025-07-20T21:27:51.636Z" }
|
| 1566 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1567 |
[[package]]
|
| 1568 |
name = "natsort"
|
| 1569 |
version = "8.4.0"
|
|
@@ -1573,6 +1618,15 @@ wheels = [
|
|
| 1573 |
{ url = "https://files.pythonhosted.org/packages/ef/82/7a9d0550484a62c6da82858ee9419f3dd1ccc9aa1c26a1e43da3ecd20b0d/natsort-8.4.0-py3-none-any.whl", hash = "sha256:4732914fb471f56b5cce04d7bae6f164a592c7712e1c85f9ef585e197299521c", size = 38268, upload-time = "2023-06-20T04:17:17.522Z" },
|
| 1574 |
]
|
| 1575 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1576 |
[[package]]
|
| 1577 |
name = "networkx"
|
| 1578 |
version = "3.6.1"
|
|
@@ -1965,6 +2019,19 @@ wheels = [
|
|
| 1965 |
{ url = "https://files.pythonhosted.org/packages/48/31/05e764397056194206169869b50cf2fee4dbbbc71b344705b9c0d878d4d8/platformdirs-4.9.2-py3-none-any.whl", hash = "sha256:9170634f126f8efdae22fb58ae8a0eaa86f38365bc57897a6c4f781d1f5875bd", size = 21168, upload-time = "2026-02-16T03:56:08.891Z" },
|
| 1966 |
]
|
| 1967 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1968 |
[[package]]
|
| 1969 |
name = "pluggy"
|
| 1970 |
version = "1.6.0"
|
|
@@ -2369,6 +2436,15 @@ wheels = [
|
|
| 2369 |
{ url = "https://files.pythonhosted.org/packages/f3/27/82ca7942881268d482b1c95a7936d3eac0a3b521d0c3ff0ba7cf485d2f3e/requests_ratelimiter-0.9.1-py3-none-any.whl", hash = "sha256:1246fac2ab307385a6170e9b321241e7b42e28c627f45b4f590371a66e1e05bd", size = 11013, upload-time = "2026-02-13T00:06:09.3Z" },
|
| 2370 |
]
|
| 2371 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2372 |
[[package]]
|
| 2373 |
name = "rich"
|
| 2374 |
version = "14.3.3"
|
|
|
|
| 667 |
{ url = "https://files.pythonhosted.org/packages/e7/05/c19819d5e3d95294a6f5947fb9b9629efb316b96de511b418c53d245aae6/cycler-0.12.1-py3-none-any.whl", hash = "sha256:85cef7cff222d8644161529808465972e51340599459b8ac3ccbac5a854e0d30", size = 8321, upload-time = "2023-10-07T05:32:16.783Z" },
|
| 668 |
]
|
| 669 |
|
| 670 |
+
[[package]]
|
| 671 |
+
name = "dash"
|
| 672 |
+
version = "4.0.0"
|
| 673 |
+
source = { registry = "https://pypi.org/simple" }
|
| 674 |
+
dependencies = [
|
| 675 |
+
{ name = "flask", marker = "sys_platform == 'linux'" },
|
| 676 |
+
{ name = "importlib-metadata", marker = "sys_platform == 'linux'" },
|
| 677 |
+
{ name = "nest-asyncio", marker = "sys_platform == 'linux'" },
|
| 678 |
+
{ name = "plotly", marker = "sys_platform == 'linux'" },
|
| 679 |
+
{ name = "requests", marker = "sys_platform == 'linux'" },
|
| 680 |
+
{ name = "retrying", marker = "sys_platform == 'linux'" },
|
| 681 |
+
{ name = "setuptools", marker = "sys_platform == 'linux'" },
|
| 682 |
+
{ name = "typing-extensions", marker = "sys_platform == 'linux'" },
|
| 683 |
+
{ name = "werkzeug", marker = "sys_platform == 'linux'" },
|
| 684 |
+
]
|
| 685 |
+
sdist = { url = "https://files.pythonhosted.org/packages/20/dd/3aed9bfd81dfd8f44b3a5db0583080ac9470d5e92ee134982bd5c69e286e/dash-4.0.0.tar.gz", hash = "sha256:c5f2bca497af288f552aea3ae208f6a0cca472559003dac84ac21187a1c3a142", size = 6943263, upload-time = "2026-02-03T19:42:27.92Z" }
|
| 686 |
+
wheels = [
|
| 687 |
+
{ url = "https://files.pythonhosted.org/packages/0b/8c/dd63d210b28a7589f4bc1e84880525368147425c717d12834ab562f52d14/dash-4.0.0-py3-none-any.whl", hash = "sha256:e36b4b4eae9e1fa4136bf4f1450ed14ef76063bc5da0b10f8ab07bd57a7cb1ab", size = 7247521, upload-time = "2026-02-03T19:42:25.01Z" },
|
| 688 |
+
]
|
| 689 |
+
|
| 690 |
+
[[package]]
|
| 691 |
+
name = "dash-bootstrap-components"
|
| 692 |
+
version = "2.0.4"
|
| 693 |
+
source = { registry = "https://pypi.org/simple" }
|
| 694 |
+
dependencies = [
|
| 695 |
+
{ name = "dash", marker = "sys_platform == 'linux'" },
|
| 696 |
+
]
|
| 697 |
+
sdist = { url = "https://files.pythonhosted.org/packages/cc/d4/5b7da808ff5acb3a6ca702f504d8ef05bc7d4c475b18dadefd783b1120c3/dash_bootstrap_components-2.0.4.tar.gz", hash = "sha256:c3206c0923774bbc6a6ddaa7822b8d9aa5326b0d3c1e7cd795cc975025fe2484", size = 115599, upload-time = "2025-08-20T19:42:09.449Z" }
|
| 698 |
+
wheels = [
|
| 699 |
+
{ url = "https://files.pythonhosted.org/packages/d6/38/1efeec8b4d741c09ccd169baf8a00c07a0176b58e418d4cd0c30dffedd22/dash_bootstrap_components-2.0.4-py3-none-any.whl", hash = "sha256:767cf0084586c1b2b614ccf50f79fe4525fdbbf8e3a161ed60016e584a14f5d1", size = 204044, upload-time = "2025-08-20T19:42:07.928Z" },
|
| 700 |
+
]
|
| 701 |
+
|
| 702 |
[[package]]
|
| 703 |
name = "databricks-sdk"
|
| 704 |
version = "0.94.0"
|
|
|
|
| 839 |
dependencies = [
|
| 840 |
{ name = "apache-airflow", marker = "sys_platform == 'linux'" },
|
| 841 |
{ name = "ccxt", marker = "sys_platform == 'linux'" },
|
| 842 |
+
{ name = "dash", marker = "sys_platform == 'linux'" },
|
| 843 |
+
{ name = "dash-bootstrap-components", marker = "sys_platform == 'linux'" },
|
| 844 |
{ name = "dotenv", marker = "sys_platform == 'linux'" },
|
| 845 |
{ name = "graphviz", marker = "sys_platform == 'linux'" },
|
| 846 |
{ name = "mlflow", marker = "sys_platform == 'linux'" },
|
|
|
|
| 863 |
requires-dist = [
|
| 864 |
{ name = "apache-airflow", specifier = ">=2.10.5" },
|
| 865 |
{ name = "ccxt", specifier = ">=4.5.40" },
|
| 866 |
+
{ name = "dash", specifier = ">=4.0.0" },
|
| 867 |
+
{ name = "dash-bootstrap-components", specifier = ">=2.0.4" },
|
| 868 |
{ name = "dotenv", specifier = ">=0.9.9" },
|
| 869 |
{ name = "graphviz", specifier = ">=0.21" },
|
| 870 |
{ name = "mlflow", specifier = ">=2.10.0" },
|
|
|
|
| 1600 |
source = { registry = "https://pypi.org/simple" }
|
| 1601 |
sdist = { url = "https://files.pythonhosted.org/packages/17/0d/74f0293dfd7dcc3837746d0138cbedd60b31701ecc75caec7d3f281feba0/multitasking-0.0.12.tar.gz", hash = "sha256:2fba2fa8ed8c4b85e227c5dd7dc41c7d658de3b6f247927316175a57349b84d1", size = 19984, upload-time = "2025-07-20T21:27:51.636Z" }
|
| 1602 |
|
| 1603 |
+
[[package]]
|
| 1604 |
+
name = "narwhals"
|
| 1605 |
+
version = "2.17.0"
|
| 1606 |
+
source = { registry = "https://pypi.org/simple" }
|
| 1607 |
+
sdist = { url = "https://files.pythonhosted.org/packages/75/59/81d0f4cad21484083466f278e6b392addd9f4205b48d45b5c8771670ebf8/narwhals-2.17.0.tar.gz", hash = "sha256:ebd5bc95bcfa2f8e89a8ac09e2765a63055162837208e67b42d6eeb6651d5e67", size = 620306, upload-time = "2026-02-23T09:44:34.142Z" }
|
| 1608 |
+
wheels = [
|
| 1609 |
+
{ url = "https://files.pythonhosted.org/packages/4b/27/20770bd6bf8fbe1e16f848ba21da9df061f38d2e6483952c29d2bb5d1d8b/narwhals-2.17.0-py3-none-any.whl", hash = "sha256:2ac5307b7c2b275a7d66eeda906b8605e3d7a760951e188dcfff86e8ebe083dd", size = 444897, upload-time = "2026-02-23T09:44:32.006Z" },
|
| 1610 |
+
]
|
| 1611 |
+
|
| 1612 |
[[package]]
|
| 1613 |
name = "natsort"
|
| 1614 |
version = "8.4.0"
|
|
|
|
| 1618 |
{ url = "https://files.pythonhosted.org/packages/ef/82/7a9d0550484a62c6da82858ee9419f3dd1ccc9aa1c26a1e43da3ecd20b0d/natsort-8.4.0-py3-none-any.whl", hash = "sha256:4732914fb471f56b5cce04d7bae6f164a592c7712e1c85f9ef585e197299521c", size = 38268, upload-time = "2023-06-20T04:17:17.522Z" },
|
| 1619 |
]
|
| 1620 |
|
| 1621 |
+
[[package]]
|
| 1622 |
+
name = "nest-asyncio"
|
| 1623 |
+
version = "1.6.0"
|
| 1624 |
+
source = { registry = "https://pypi.org/simple" }
|
| 1625 |
+
sdist = { url = "https://files.pythonhosted.org/packages/83/f8/51569ac65d696c8ecbee95938f89d4abf00f47d58d48f6fbabfe8f0baefe/nest_asyncio-1.6.0.tar.gz", hash = "sha256:6f172d5449aca15afd6c646851f4e31e02c598d553a667e38cafa997cfec55fe", size = 7418, upload-time = "2024-01-21T14:25:19.227Z" }
|
| 1626 |
+
wheels = [
|
| 1627 |
+
{ url = "https://files.pythonhosted.org/packages/a0/c4/c2971a3ba4c6103a3d10c4b0f24f461ddc027f0f09763220cf35ca1401b3/nest_asyncio-1.6.0-py3-none-any.whl", hash = "sha256:87af6efd6b5e897c81050477ef65c62e2b2f35d51703cae01aff2905b1852e1c", size = 5195, upload-time = "2024-01-21T14:25:17.223Z" },
|
| 1628 |
+
]
|
| 1629 |
+
|
| 1630 |
[[package]]
|
| 1631 |
name = "networkx"
|
| 1632 |
version = "3.6.1"
|
|
|
|
| 2019 |
{ url = "https://files.pythonhosted.org/packages/48/31/05e764397056194206169869b50cf2fee4dbbbc71b344705b9c0d878d4d8/platformdirs-4.9.2-py3-none-any.whl", hash = "sha256:9170634f126f8efdae22fb58ae8a0eaa86f38365bc57897a6c4f781d1f5875bd", size = 21168, upload-time = "2026-02-16T03:56:08.891Z" },
|
| 2020 |
]
|
| 2021 |
|
| 2022 |
+
[[package]]
|
| 2023 |
+
name = "plotly"
|
| 2024 |
+
version = "6.6.0"
|
| 2025 |
+
source = { registry = "https://pypi.org/simple" }
|
| 2026 |
+
dependencies = [
|
| 2027 |
+
{ name = "narwhals", marker = "sys_platform == 'linux'" },
|
| 2028 |
+
{ name = "packaging", marker = "sys_platform == 'linux'" },
|
| 2029 |
+
]
|
| 2030 |
+
sdist = { url = "https://files.pythonhosted.org/packages/24/fb/41efe84970cfddefd4ccf025e2cbfafe780004555f583e93dba3dac2cdef/plotly-6.6.0.tar.gz", hash = "sha256:b897f15f3b02028d69f755f236be890ba950d0a42d7dfc619b44e2d8cea8748c", size = 7027956, upload-time = "2026-03-02T21:10:25.321Z" }
|
| 2031 |
+
wheels = [
|
| 2032 |
+
{ url = "https://files.pythonhosted.org/packages/52/d2/c6e44dba74f17c6216ce1b56044a9b93a929f1c2d5bdaff892512b260f5e/plotly-6.6.0-py3-none-any.whl", hash = "sha256:8d6daf0f87412e0c0bfe72e809d615217ab57cc715899a1e5145135a7800d1d0", size = 9910315, upload-time = "2026-03-02T21:10:18.131Z" },
|
| 2033 |
+
]
|
| 2034 |
+
|
| 2035 |
[[package]]
|
| 2036 |
name = "pluggy"
|
| 2037 |
version = "1.6.0"
|
|
|
|
| 2436 |
{ url = "https://files.pythonhosted.org/packages/f3/27/82ca7942881268d482b1c95a7936d3eac0a3b521d0c3ff0ba7cf485d2f3e/requests_ratelimiter-0.9.1-py3-none-any.whl", hash = "sha256:1246fac2ab307385a6170e9b321241e7b42e28c627f45b4f590371a66e1e05bd", size = 11013, upload-time = "2026-02-13T00:06:09.3Z" },
|
| 2437 |
]
|
| 2438 |
|
| 2439 |
+
[[package]]
|
| 2440 |
+
name = "retrying"
|
| 2441 |
+
version = "1.4.2"
|
| 2442 |
+
source = { registry = "https://pypi.org/simple" }
|
| 2443 |
+
sdist = { url = "https://files.pythonhosted.org/packages/c8/5a/b17e1e257d3e6f2e7758930e1256832c9ddd576f8631781e6a072914befa/retrying-1.4.2.tar.gz", hash = "sha256:d102e75d53d8d30b88562d45361d6c6c934da06fab31bd81c0420acb97a8ba39", size = 11411, upload-time = "2025-08-03T03:35:25.189Z" }
|
| 2444 |
+
wheels = [
|
| 2445 |
+
{ url = "https://files.pythonhosted.org/packages/67/f3/6cd296376653270ac1b423bb30bd70942d9916b6978c6f40472d6ac038e7/retrying-1.4.2-py3-none-any.whl", hash = "sha256:bbc004aeb542a74f3569aeddf42a2516efefcdaff90df0eb38fbfbf19f179f59", size = 10859, upload-time = "2025-08-03T03:35:23.829Z" },
|
| 2446 |
+
]
|
| 2447 |
+
|
| 2448 |
[[package]]
|
| 2449 |
name = "rich"
|
| 2450 |
version = "14.3.3"
|