Department of Computer Science and Engineering ( Data Science )
Ty.B.Tech. Sem: VI Subject: Fianancial Market and Computing
Experiment 10
Name: Jay Topiwala SAP ID: 60009220169
Date: Experiment Title: Monte Carlo Simulation for Portfolio Risk
Assessment
Aim To use Monte Carlo Simulation for Portfolio Risk Assessment.
Software Google Colab, Visual Studio Code, Jupyter Notebook
Theory To Be Describe Monte Carlo Simulation.
Written
Monte Carlo simulation is a computational technique that uses random
sampling to obtain numerical results. It's named after the famous Monte
Carlo Casino in Monaco, reflecting its use of randomness and probability.
In the context of financial analysis and portfolio management (as in your
project), Monte Carlo simulation works like this:
1. Random Scenario Generation: It creates thousands of possible
future scenarios by randomly sampling from probability
distributions of key variables (like stock returns).
2. Repeated Iterations: By running thousands of simulations (in
your case, 10,000), it builds a comprehensive picture of possible
outcomes.
3. Probability Distribution: Rather than producing a single forecast,
Monte Carlo simulation creates a distribution of possible
outcomes, showing not just what might happen but how likely
each outcome is.
4. Risk Assessment: It's particularly valuable for quantifying risk
metrics like Value at Risk (VaR) and Conditional Value at Risk
(CVaR).
Implementatio 1. Import numpy pandas matplotlib and yahoo finance.
n
2. Define Portfolio Parameters.
Consider a portfolio consisting of Apple (AAPL), Microsoft
(MSFT), Google (GOOGL), and Amazon (AMZN).
Each stock has a specific weight in the portfolio. Total of all
weights should be 1. weights = [0.3, 0.3, 0.2, 0.2]
The historical data range is from January 1, 2018, to December 31,
2023.
10,000 Monte Carlo simulations are to be performed over a 1-year
trading period (252 days).
3. Fetch Historical Stock Data from yahoo finance. Check the
available columns in the downloaded data. Extract Adjusted
Closing Prices (or Close Prices if Adjusted Close is unavailable).
Use if-elif-else loop. Raise KeyError if both “Close” or “Adj
Close” are not found in downloaded data.
4. Calculate Daily Returns of the stocks.
The pct_change() function in Pandas calculates the percentage
change between consecutive elements in a DataFrame or Series.
5, Calculate mean and covariance of returns.
5. Monte Carlo Simulation
Ensure generated random numbers are reproducible.
Initialize an empty list to store the final portfolio returns from each
simulation.
Create a for loop to run Monte Carlo simulations num_simulations
times (e.g., 10,000 simulations).
Each iteration generates a possible one-year performance scenario
for the portfolio.
Generate Random Daily Returns for the Portfolio using
multivariate_normal function to get simulated_daily_returns.
Do the matrix multiplication of simulated_daily_returns with
weights to get one overall portfolio return per day.
Calculating Cumulative Portfolio Returns.
np.cumprod(1 + portfolio_daily_returns) computes the cumulative
product of daily returns over the year.
Subtracting 1 gives the total portfolio return from the start of the
simulation.
Storing the Final Portfolio Value and append it to the
simulated_portfolios.
6. Analyze simulation results. Find out the mean and std. dev of
simulated_portfolios.
7. Calculate VaR (Value at Risk) and CVaR (Conditional Value at
Risk).
8. Print all the four above results.
9. Plot a histogram of simulated portfolio returns, highlighting mean
return and VaR.
Conclusion Hence, we have studied Monte Carlo Simulation for Portfolio Risk
Assessment.
In our portfolio analysis, we examined a diversified Indian market
portfolio consisting of Reliance Industries (30%), ONGC (30%), Larsen
& Toubro (20%), and Indian Oil Corporation (20%). Using historical data
from 2018-2023 and 10,000 Monte Carlo simulations, we projected
potential one-year performance.
Our results show a positive expected annual return with moderate
volatility. The Value at Risk (VaR) and Conditional Value at Risk
(CVaR) metrics provide valuable insights into potential downside risks.
The visualizations help us understand the range and probability of
possible outcomes.
We conclude that this portfolio offers a reasonable balance between risk
and return based on historical data, while acknowledging that past
performance doesn't guarantee future results.
Signature of Faculty