π Portfolio Risk Simulation Dashboard
A Streamlit-based financial risk analysis tool that performs Monte Carlo simulations on stock portfolios to estimate risk metrics such as Value at Risk (VaR) and Expected Shortfall (ES).
This dashboard allows users to build a portfolio manually or upload an Excel file, simulate market scenarios using historical data, and generate a professional PDF risk report.
π Features π Portfolio Creation
Upload portfolio via Excel file
Manually select stocks from Nifty 50
Specify stock quantities
π Risk Simulation
Monte Carlo simulation using historical log returns
Configurable number of simulations
Adjustable days to expiry
π Risk Metrics
Value at Risk (VaR) β 99%
Expected Shortfall (ES)
Hedged VaR
Hedged Expected Shortfall
π Visualization
Loss distribution histogram
Interactive Streamlit dashboard
π Professional PDF Report
Automatically generates a report containing:
Portfolio holdings
Current portfolio value
Risk metrics summary
Loss distribution chart
Risk interpretation
π§ Methodology
The simulation process follows these steps:
Download historical price data using yfinance.
Compute log returns for portfolio assets and market index.
Estimate mean returns and covariance matrix.
Generate multivariate normal simulations.
Calculate simulated portfolio values.
Estimate risk metrics:
Value at Risk (VaR)
The loss threshold that will not be exceeded with 99% confidence.
Expected Shortfall (ES)
The average loss beyond the VaR level, representing tail risk.
π§° Tech Stack Tool Purpose Python Core programming language Streamlit Web dashboard NumPy Numerical simulations Pandas Data manipulation yfinance Market data retrieval Matplotlib Visualization ReportLab PDF report generation π¦ Installation
Clone the repository:
git clone https://github.com/yourusername/portfolio-risk-simulation.git cd portfolio-risk-simulation
Install dependencies:
pip install -r requirements.txt
Then open the Streamlit URL shown in your terminal.
π Example Portfolio Excel Format
Your Excel file must contain columns similar to:
Stock Quantity RELIANCE 10 INFY 20 HDFCBANK 5
The system automatically converts them to NSE tickers.
π Example Output
The dashboard provides:
Portfolio value
Loss distribution histogram
VaR & Expected Shortfall
Hedged risk metrics
Downloadable PDF risk report
This project is intended for educational and research purposes only. It should not be used as financial advice or as a substitute for professional risk management systems.
π¨βπ» Author
Developed by Purnank Gogarkar