How jeevanba273/factor-model-and-smart-beta-portfolio-builder works
Project Type & Purpose
• This is a monolithic, data-driven web application built with Streamlit.
• Purpose: Provide an interactive UI for factor analysis, portfolio construction, and backtesting using CSV-based historical data for the Indian stock market.
• Deployment: Hosted on Railway as a single container/service.
File Structure Analysis
• Top-level:
– app.py (entry point containing UI, business logic)
– requirements.txt (Python dependencies)
– data/ (historical CSV files, one per year)
• No separate frontend/backend repos: UI and logic are combined in app.py under Streamlit.
• No external database—local CSV files act as the data store.
• Deployment and environment managed via Railway (per README).
README Insights
• UI Layer: Streamlit (page layout, user controls, chart placeholders).
• Business Logic:
– Factor score calculations (value, momentum, low volatility, quality)
– Portfolio construction & rebalancing
– Backtest simulation
• Data Processing: Pandas/NumPy, optional StatsModels
• Visualization: Plotly charts
• Caching: Streamlit’s @st.cache decorator to speed repeated computations
• Hosting: Railway (container + scalable environment)
Main Components & Interactions
a. Browser / Client
– Renders Streamlit UI; sends user events (slider changes, date picks, run analysis).
b. Streamlit Server (app.py)
– UI Layer: Streamlit widgets (sliders, date pickers, tabs)
– Controller / Orchestrator: Coordinates UI events → invokes business logic
– Data Access Layer: Reads CSV files from data/ folder
– Business Logic Layer:
• Factor calculation modules (in-memory Pandas pipelines)
• Composite score generation
• Backtest engine (rebalancing loops, performance metrics)
– Cache Layer: Memoizes heavy operations via @st.cache
– Visualization Layer: Generates Plotly figures for the UI
c. Data Storage
– Local file system (data/*.csv). Optionally show “Data Lake” as a generic CSV-based store.
d. Deployment Infrastructure
– GitHub (source control) → Railway CI/CD → Container
– Railway runtime environment (Python 3.12, dependencies from requirements.txt)
e. External References (optional)
– NIFTY 50 index for benchmark comparison (could be an API or preloaded CSV)
– NSE (original data provider—out-of-scope)
Architectural Patterns & Design Principles
• Monolithic service: Single container, no microservices.
• Layered approach inside app.py: UI → Controller → Data Access → Business Logic → Visualization.
• Stateless compute functions + caching for idempotent operations.
• Vectorized data processing (Pandas) for performance.
• Separation of concerns: Keep factor formulas, backtest loops, and UI code logically distinct (use functions or modules within app.py).
• Rectangle with rounded corners for UI
• Standard rectangle for compute modules