How sookeyy-12/risklens works
Project Type and Purpose
• RiskLens is a full-stack, data-driven Streamlit dashboard for advanced volatility analysis and sector risk assessment.
• The core “engine” is in the src/ library (data acquisition, volatility models, sector analytics, visualization helpers). The “app” layer (in app/) is the Streamlit presentation layer that binds UI components to the core library.
File-Structure Analysis
• Top-level directories and files:
• app/ – Streamlit application: configuration (config.py), main entrypoint (main.py), UI components (components/), and page-level views (views/).
• src/ – Core analytics library: data_fetcher.py, volatility methods (volatility.py), sector analysis (sector_analysis.py), visualization helpers (visualization.py), plus utility functions.
• data/ – Static assets (e.g., sector_mapping.csv).
• scripts/ – Standalone scripts for data fetching, volatility computation, dashboard updates.
• notebooks/ – Jupyter demos and ad-hoc analyses.
• Launchers (launch_app.py, launch_app.ps1) and dependency lists (requirements_streamlit.txt, pyproject.toml).
• tests/ – Unit tests for core library modules.
README Insights
• Describes four Streamlit pages (Home, Heatmap Analysis, Chart Analysis, About Developer).
• Calls out performance features (Streamlit caching, vectorized NumPy/Pandas ops, Plotly interactivity).
• Lists external data source (yfinance) and static sector mapping.
Key Architectural Components
a. Data Sources & Ingestion
• External: Yahoo Finance via yfinance.
• Internal: data/sector_mapping.csv.
• Ingestion layer: src/data_fetcher.py (cached with Streamlit TTL).
b. Business Logic / Analytics Layer
• Volatility calculations: src/volatility.py (Historical, Parkinson, Garman-Klass, Beta-adjusted).
• Sector analysis and regime detection: src/sector_analysis.py.
• Utility routines: src/utils.py.
c. Visualization Layer
• Plotly-based functions: src/visualization.py.
• Streamlit UI components: app/components/heatmap.py, app/components/charts.py.
d. Presentation / UI Layer
• Streamlit main app: app/main.py (sets up sidebar navigation & page routing).
• Page views: app/views/home.py, heatmap_analysis.py, chart_analysis.py, about_developer.py.
• Configuration: app/config.py (themes, default parameters).
e. Orchestration & Launch
• Launch scripts: Python and PowerShell entrypoints that invoke Streamlit or call app/main.py.
• Scheduled/standalone scripts: scripts/ directory for batch data updates or re-computations.
f. Testing & Quality
• tests/ directory for unit tests covering data ingestion, sector logic, volatility models.
Relationships & Data Flows
• data_fetcher outputs DataFrames → passed to volatility and sector_analysis.
• Analysis results → Plotly figures via visualization.
• Figures and widgets consumed by Streamlit UI components.
• User interactions in UI → trigger data fetch and recompute through caching decorators.
• Scripts in scripts/ orchestrate core library calls without UI.
Architectural Patterns & Principles
• Layered Architecture:
1. Data Layer
2. Business Logic Layer
3. Visualization Layer
4. Presentation Layer
• MVC-like separation: Core library (Model), Streamlit views (View), and app/main.py as Controller.
• Caching for performance and rate-limit safety.
• Modular, extensible design—new volatility models or data sources plug into src/.
Technologies & Frameworks
• Python 3.8+
• Streamlit (UI)
• Plotly (visuals)
• Pandas & NumPy (data processing)
• yfinance (data source)
• Pytest (testing)