|
| 1 | +import streamlit as st |
| 2 | +import pandas as pd |
| 3 | + |
| 4 | +from modules.data.data_loader import load_data |
| 5 | +from modules.analysis.indicators import add_technical_indicators |
| 6 | +from modules.analysis.metrics import get_quick_metrics |
| 7 | +from modules.analysis.forecast import make_linear_forecast |
| 8 | +from modules.visualization.plots import plot_candlestick, plot_rsi, plot_forecast |
| 9 | +from modules.ui.user_guide import render_user_guide |
| 10 | +from modules.ui.utils_ui import format_asset_title |
| 11 | + |
| 12 | + |
| 13 | +st.set_page_config(page_title="Market Insights Dashboard", layout="wide") |
| 14 | +st.title("📊 Market Insights Dashboard") |
| 15 | + |
| 16 | +# --- Sidebar --- |
| 17 | +st.sidebar.header("Settings") |
| 18 | +# Dropdown for asset selection |
| 19 | +asset_options = { |
| 20 | + # ---- Global Indices ---- |
| 21 | + "S&P 500": "^GSPC", |
| 22 | + "NASDAQ 100": "^NDX", |
| 23 | + "MSCI World": "URTH", |
| 24 | + "MSCI Emerging Markets": "EEM", |
| 25 | + |
| 26 | + # ---- Commodities ---- |
| 27 | + "Gold": "GC=F", |
| 28 | + |
| 29 | + # ---- Cryptocurrencies ---- |
| 30 | + "Bitcoin": "BTC-USD", |
| 31 | + "Ethereum": "ETH-USD", |
| 32 | + |
| 33 | + # ---- Fixed Income ---- |
| 34 | + "EU Gov Bonds 1-3Y": "EUNA.AS", # working ETF replacement |
| 35 | + |
| 36 | + # ---- Thematic ETFs ---- |
| 37 | + "VanEck Uranium & Nuclear ETF": "NLR", |
| 38 | + "iShares Global Clean Energy": "ICLN", |
| 39 | +} |
| 40 | + |
| 41 | +asset_name = st.sidebar.selectbox("Select asset", list(asset_options.keys())) |
| 42 | +ticker = asset_options[asset_name] |
| 43 | + |
| 44 | +period = st.sidebar.selectbox("Period", ["1y", "5y", "10y", "max"]) |
| 45 | +interval = st.sidebar.selectbox("Interval", ["1d", "1wk", "1mo"]) |
| 46 | + |
| 47 | +st.sidebar.header("Forecast Settings") |
| 48 | +forecast_horizon = st.sidebar.slider("Horizon (steps)", 7, 90, 14) |
| 49 | +forecast_window = st.sidebar.slider("Training window (points)", 30, 365, 120) |
| 50 | + |
| 51 | +# --- Tabs --- |
| 52 | +tab_dashboard, tab_forecast, tab_guide = st.tabs(["📈 Dashboard", "🔮 Forecast", "📘 User Guide"]) |
| 53 | + |
| 54 | +with tab_dashboard: |
| 55 | + data = load_data(ticker, period, interval) |
| 56 | + if data.empty: |
| 57 | + st.error("⚠️ No market data available for this ticker.") |
| 58 | + st.stop() |
| 59 | + |
| 60 | + data = add_technical_indicators(data) |
| 61 | + display_title = format_asset_title(asset_name, ticker) |
| 62 | + st.plotly_chart(plot_candlestick(data, display_title), width='stretch') |
| 63 | + st.subheader("📉 Relative Strength Index (RSI)") |
| 64 | + st.plotly_chart(plot_rsi(data), width='stretch') |
| 65 | + |
| 66 | + st.subheader("📈 Quick Metrics") |
| 67 | + col1, col2, col3 = st.columns(3) |
| 68 | + price, change_week, rsi = get_quick_metrics(data) |
| 69 | + col1.metric("Current Price", f"{price:.2f}") |
| 70 | + col2.metric("1-Week Change", f"{change_week:.2f}%") |
| 71 | + col3.metric("Current RSI", f"{rsi:.2f}") |
| 72 | + |
| 73 | +with tab_forecast: |
| 74 | + st.subheader("🔮 Simple Linear Forecast") |
| 75 | + data = load_data(ticker, period, interval) |
| 76 | + if data.empty: |
| 77 | + st.warning("No data available to build a forecast.") |
| 78 | + st.stop() |
| 79 | + |
| 80 | + fc = make_linear_forecast(data, interval, forecast_window, forecast_horizon) |
| 81 | + if fc.empty: |
| 82 | + st.warning("Not enough data to produce a forecast.") |
| 83 | + else: |
| 84 | + st.plotly_chart(plot_forecast(data, fc, display_title), width='stretch') |
| 85 | + |
| 86 | + st.info("This forecast uses a simple linear regression trend based on recent data.") |
| 87 | + |
| 88 | +with tab_guide: |
| 89 | + render_user_guide() |
0 commit comments