How ronaldkanyepi/portfolio-optimization-pyomo works
Project type and purpose
• This is a single‐page, data‐driven full-stack Streamlit application focused on portfolio optimization.
• It uses Streamlit for the UI, yfinance as an external data source, Pyomo (with IPOPT) as the optimization engine, and common data-science libraries for processing and visualization.
File structure
• At the top level you have:
• main.py – contains both the Streamlit UI code and calls into data retrieval, processing, optimization, and plotting.
• requirements.txt – declares dependencies.
Key components
a. Presentation Layer (Streamlit UI)
• User’s browser (or local host) interacts with the Streamlit server process in main.py.
• Displays form controls (ticker selection, date pickers) and renders charts/tables.
b. Data Retrieval Layer
• yfinance Python client fetches historical stock price data from Yahoo Finance API.
• External Service: Yahoo Finance (HTTP calls).
c. Data Processing Layer
• pandas & numpy compute returns, covariance matrices, etc.
d. Optimization Engine
• Pyomo model definition + IPOPT solver binary.
• Takes processed data and user’s target return constraint to solve the risk-minimization problem.
e. Visualization Layer
• seaborn/matplotlib produce the correlation heatmap and allocation bar charts.
f. Local Environment
• Python interpreter, virtual environment, and IPOPT binary installed on user’s machine.
Relationships & data flow
1. User → Streamlit UI: enters tickers + date range
2. Streamlit UI → Data Retrieval: calls yfinance to download price history
3. Retrieved data → Data Processing: calculate daily returns, covariance
4. Processed data + target return → Optimization Engine (Pyomo → IPOPT)
5. Solution (allocations, risk, expected return) → Streamlit UI
6. Streamlit UI → Visualization: call seaborn/matplotlib to render charts
7. Charts & tables → User browser
Architectural patterns & design principles
• Single-page reactive app: UI code and business logic co-located but conceptually layered.
• Modular data flow: clearly separate data retrieval, processing, optimization, and visualization.
• External dependency isolation: IPOPT is an out-of-process solver; yfinance is an external web service.
Capturing essential details
• That main.py hosts all these layers in one process.
• IPOPT as an external executable invoked by Pyomo.
• Network boundary around the Yahoo Finance calls.
• Optionally, note the Python venv as the deployment context, and requirements.txt as the dependency manifest.