Spaces:
Sleeping
Sleeping
File size: 8,147 Bytes
72fc0ee | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | """
QuantLib Pro - Streamlit application entry point.
Uses st.navigation with Material Design icons (Streamlit 1.36+).
"""
import streamlit as st
import os
# Global page config - called ONCE here; pages must NOT call it
st.set_page_config(
page_title="QuantLib Pro",
page_icon=":material/candlestick_chart:",
layout="wide",
initial_sidebar_state="expanded",
)
# Check API credentials and show setup dialog if needed
def check_and_prompt_credentials():
"""Check for API credentials and prompt user if they're missing."""
fred_key = os.getenv("FRED_API_KEY", "")
fred_configured = fred_key and fred_key != "REPLACE_WITH_FRED_API_KEY" and len(fred_key) > 10
av_key = os.getenv("ALPHA_VANTAGE_API_KEY", "")
av_configured = av_key and av_key != "REPLACE_WITH_ALPHA_VANTAGE_KEY" and len(av_key) > 10
# If credentials are missing, show setup instructions
if not fred_configured or not av_configured:
st.warning("π **API Credentials Setup Required**")
with st.expander("**Click here to set up your API credentials for full functionality**", expanded=True):
st.markdown("""
### π Get the Most Out of QuantLib Pro!
To access all features including real-time market data, economic indicators, and enhanced analytics,
please configure your free API credentials:
""")
col1, col2 = st.columns(2)
with col1:
if not fred_configured:
st.error("β **FRED API Key Missing**")
st.markdown("""
**Federal Reserve Economic Data (FRED)**
- Free API for US economic data
- Get your key: [https://fred.stlouisfed.org/docs/api/api_key.html](https://fred.stlouisfed.org/docs/api/api_key.html)
- Required for: Economic indicators, yield curves, inflation data
""")
else:
st.success("β
**FRED API Key Configured**")
with col2:
if not av_configured:
st.error("β **Alpha Vantage API Key Missing**")
st.markdown("""
**Alpha Vantage Market Data**
- Free API for stock market data
- Get your key: [https://www.alphavantage.co/support/#api-key](https://www.alphavantage.co/support/#api-key)
- Required for: Real-time quotes, technical indicators, forex data
""")
else:
st.success("β
**Alpha Vantage API Key Configured**")
st.info("""
**π How to Configure:**
1. Get your free API keys from the links above
2. Go to **Settings** (in the Developer section of the sidebar)
3. Enter your API keys in the configuration panel
4. Restart the application to apply changes
**π‘ Note:** You can still use QuantLib Pro without these keys, but some features will be limited to Yahoo Finance data only.
""")
if st.button("π§ Go to Settings", type="primary"):
st.switch_page("pages/18_Settings.py")
st.divider()
# Show credentials prompt on app startup
check_and_prompt_credentials()
# Persistent sidebar shown on every page
with st.sidebar:
st.markdown("## QuantLib Pro")
st.caption("Enterprise Quantitative Finance Platform")
st.divider()
st.markdown("### Analysis Parameters")
st.markdown("##### Date Range")
c1, c2 = st.columns(2)
with c1:
start_date = st.date_input("Start", value=None)
with c2:
end_date = st.date_input("End", value=None)
st.markdown("##### Risk Parameters")
risk_free_rate = st.slider(
"Risk-free Rate (%)", 0.0, 10.0, 2.0, 0.1
) / 100
confidence_level = st.slider(
"VaR Confidence (%)", 90, 99, 95
) / 100
st.session_state.risk_free_rate = risk_free_rate
st.session_state.confidence_level = confidence_level
if start_date:
st.session_state.start_date = start_date
if end_date:
st.session_state.end_date = end_date
st.divider()
st.markdown("### System Status")
# Import requests at module level to avoid issues
try:
import requests
except ImportError:
requests = None
# Check API status (only if not in cloud environment)
is_cloud_deployment = os.getenv("STREAMLIT_SHARING_MODE") or os.getenv("STREAMLIT_CLOUD") or "streamlit.app" in os.getenv("HOSTNAME", "")
if not is_cloud_deployment and requests:
try:
r = requests.get("http://localhost:8000/health/", timeout=1)
st.success("API: Online") if r.status_code == 200 else st.warning("API: Degraded")
except Exception:
st.info("API: Standalone Mode")
else:
st.info("API: Cloud Mode")
# Check data providers
fred_key = os.getenv("FRED_API_KEY", "")
fred_ok = fred_key and fred_key != "REPLACE_WITH_FRED_API_KEY" and len(fred_key) > 10
av_key = os.getenv("ALPHA_VANTAGE_API_KEY", "")
av_ok = av_key and av_key != "REPLACE_WITH_ALPHA_VANTAGE_KEY" and len(av_key) > 10
st.success("UI: Online")
st.success("Yahoo Finance: Ready")
if fred_ok:
st.success("FRED: Connected")
else:
st.warning("FRED: Configure in Settings")
if av_ok:
st.success("Alpha Vantage: Connected")
else:
st.warning("Alpha Vantage: Configure in Settings")
st.divider()
st.caption("v1.0.0 Β· Streamlit Β· FastAPI")
# Navigation with grouped sections and Material Design icons
pg = st.navigation(
{
"Core": [
st.Page("pages/0_Home.py", title="Home", icon=":material/home:"),
st.Page("pages/1_Portfolio.py", title="Portfolio", icon=":material/pie_chart:"),
st.Page("pages/2_Risk.py", title="Risk", icon=":material/shield:"),
st.Page("pages/3_Options.py", title="Options", icon=":material/calculate:"),
],
"Market": [
st.Page("pages/4_Market_Regime.py", title="Market Regime", icon=":material/track_changes:"),
st.Page("pages/5_Macro.py", title="Macro", icon=":material/public:"),
st.Page("pages/6_Volatility_Surface.py", title="Vol Surface", icon=":material/show_chart:"),
st.Page("pages/10_Market_Analysis.py", title="Market Analysis", icon=":material/bar_chart:"),
],
"Trading": [
st.Page("pages/7_Backtesting.py", title="Backtesting", icon=":material/history:"),
st.Page("pages/11_Trading_Signals.py", title="Trading Signals", icon=":material/sensors:"),
st.Page("pages/8_Advanced_Analytics.py", title="Analytics", icon=":material/analytics:"),
],
"Infrastructure": [
st.Page("pages/12_Liquidity.py", title="Liquidity", icon=":material/water_drop:"),
st.Page("pages/13_Systemic_Risk.py", title="Systemic Risk", icon=":material/hub:"),
st.Page("pages/9_Data_Management.py", title="Data Management", icon=":material/storage:"),
],
"Monitoring": [
st.Page("pages/14_Trader_Stress_Monitor.py", title="Stress Monitor", icon=":material/psychology:"),
st.Page("pages/16_UAT_Dashboard.py", title="UAT Dashboard", icon=":material/dashboard:"),
st.Page("pages/15_Testing.py", title="Testing", icon=":material/science:"),
],
"Developer": [
st.Page("pages/17_API_Explorer.py", title="API Explorer", icon=":material/api:"),
st.Page("pages/18_Settings.py", title="Settings", icon=":material/settings:"),
],
}
)
pg.run()
|