This project simulates future stock price paths using a Monte Carlo method with a Geometric Brownian Motion + Jump Diffusion model. It calculates Value at Risk (VaR) and Conditional VaR (CVaR), identifies historical jumps in log returns, and outputs detailed simulation data and risk metrics in both graphical and CSV format.
- ✅ Fetches historical stock data using
yfinance - ✅ Computes log-adjusted returns and statistical parameters
- ✅ Simulates multiple price paths using:
- Geometric Brownian Motion
- Poisson-driven Jump Diffusion
- ✅ Calculates:
- Value at Risk (VaR)
- Conditional VaR (CVaR / Expected Shortfall)
- ✅ Detects price jumps based on standard deviation cutoff
- ✅ Visualizes:
- Simulated price paths
- Histogram of final simulated prices with VaR overlay
- ✅ Saves:
- Price path simulations
- Jump event logs
- Summary statistics
-
Fetch Stock Data
User provides a stock ticker, date range, and simulation preferences.
-
Jump Detection
Users can choose to auto-detect jumps based on statistical deviations from a specified sigma cutoff, or manually input their own values for average jump frequency (λ), mean jump size (μj), and jump volatility (σj). Example for auto-detect output:
Example for user input and no average jump:
-
Monte Carlo Simulation
Thousands of future paths are simulated incorporating both drift, volatility, and jump events.
-
Risk Calculation
From simulated ending prices:
Results are plotted and optionally saved to CSV files for further analysis.
Exports
data/{Ticker}_price_paths.csv— Simulated prices for all trialsdata/{Ticker}_jumps.csv— Dates where return jumps exceeded thresholddata/{Ticker}_summary.csv— Summary stats (VaR, CVaR, λ, etc.)data/{Ticker}_Simulated_Price_Paths.png— 📈 Line chart of simulated price pathsdata/{Ticker}_Distribution_of_Final_Simulated_Prices.png— 📊 Histogram showing final price distribution with VaR cutoff
- Ticker: Stock symbol (e.g.,
AAPL,MSFT) - Date Range: Start and end date for historical data. If end date is NA, will take today's date
- Simulation Days: Number of future trading days to simulate (e.g., 1, 5, 30)
- Trials: Number of Monte Carlo trials (e.g., 1000, 10,000)
- Confidence Level: For VaR and CVaR (e.g., 0.90, 0.95)
pip install yfinance numpy pandas matplotlib seaborn scipy tabulate




