A Streamlit web app for analyzing portfolio performance, asset behavior, and cross-asset correlation using Yahoo Finance data.
Hosted app:
This app helps you move from a simple ticker list to a portfolio-level view of:
- Risk and return metrics
- Asset-level performance
- Correlation structure
- Contribution by asset
- Downloadable reporting in Excel
It is designed for quick exploratory analysis with editable portfolio inputs and immediate visual and metric feedback.
- Editable portfolio table (
Tickers,Allocation Percentage) - Date-range based analysis
- Portfolio summary metrics:
- Expected Return (annualized)
- Volatility / StdDev (annualized)
- Sharpe Ratio
- Max Drawdown
- Cumulative Return
- Asset-level metrics:
- Annualized Return
- Volatility
- Cumulative Return
- Observations
- Asset contribution table:
- Contribution (log)
- Contribution Share
- Correlation matrix with styled heatmap
- Price visualization modes:
- Raw price
- Indexed to 100 (first valid date per asset)
- One-click Excel export with multiple analysis sheets
- Set
Start DateandEnd Date. - Edit the portfolio table:
- Add or remove tickers
- Adjust allocation percentages
- Click
Calculate. - Review:
- Portfolio Summary
- Asset Metrics
- Asset Contribution
- Correlation Matrix
- Price chart and data table (
PricevsIndexed)
- Download the full
.xlsxreport.
If the hosted app is sleeping, click the blue reactivation button:
Portfolio input section:
Portfolio summary and contribution views:
Price chart and correlation output examples:
Price view toggle (Price vs Indexed) and data table:
Download section:
main.pyStreamlit app orchestration: UI, validation, calculations, rendering, and export.
stock_api.pyFetches closing price history from Yahoo Finance.data_transform.pyLog-return calculation and price normalization (base=100).metrics.pyAsset and portfolio metrics.corr_matrix.pyCorrelation matrix computation with minimum-data guardrails.heatmap.pyStyled correlation table.line_chart.pyAltair line chart for price and index views.xlsx_summary_report.pyMulti-sheet Excel export builder.streamlit_helper.pyStreamlit display helpers (for example, total-row highlighting).
tests/test_stock_api.pytests/test_data_transform.pytests/test_metrics.pytests/test_corr_matrix.pytests/test_heatmap.py
Install dependencies:
pip install -r requirements.txtRun app:
streamlit run main.pyRun tests:
pytest- Data source: Yahoo Finance (
yfinance) - Returns used for analytics: daily log returns
log_return = ln(P_t) - ln(P_(t-1))
- Log return calculation rejects non-positive prices.
- Portfolio calculations use allocation weights normalized across valid assets.
- Correlation requires sufficient overlapping valid observations.
The app blocks analysis and shows errors when:
- Portfolio is empty
- Any ticker is blank
- Duplicate tickers exist
- Allocation contains negative values
- Total allocation exceeds 100%
- Date range is invalid (
start >= end) - Price data is unavailable for selected assets and date range
The download includes these sheets:
parametersportfolio_allocationportfo_summaryasset_metricasset_contribprice_historyprice_history_indexedcorrelation_matrix
This project began as a CS50P final project focused on stock correlation and evolved into a modular portfolio analytics app (V2) with broader metrics, validation, and richer export and reporting.








