What is Monte Carlo simulation?
A Monte Carlo simulation, also known as a multiple probability simulation, is employed to model the likelihood of different outcomes in scenarios influenced by random variables. This technique helps in comprehending the effects of uncertainty and risk, and finds applications in fields such as investing, business, physics, and engineering.
How is MC model used for investing?
To conduct a Monte Carlo simulation, historical data of an asset is analyzed to understand its past price movements. Using this data, we calculate statistical measures such as the average daily return, standard deviation, and variance. These measures help in understanding the asset's typical behavior over time.
Once these parameters are determined, we introduce randomness into the simulation to represent market volatility. We generate random values based on the standard deviation of the asset's returns. These random values are then combined with the asset's drift, which represents its consistent directional movement.
Using these values, we construct equations to predict the asset's future price movements. By repeatedly applying these equations for multiple time periods, we simulate various potential trajectories for the asset's price.
Through this process, we generate numerous simulations, each representing a possible outcome for the asset's price. Analyzing these simulations allows us to understand the range of possible scenarios and assess the likelihood of different outcomes.
Why does the simulation work so well?
Monte Carlo simulations are highly effective due to their capacity to integrate randomness and variability, facilitating exploration of a broad spectrum of potential outcomes. A key advantage is their ability to accurately capture real-world randomness and variability, thus ensuring that rare or extreme events are appropriately accounted for, which traditional analytical methods may overlook. Furthermore, Monte Carlo simulations enable sensitivity analysis, allowing users to assess the impact of parameter changes on system behavior, aiding in informed decision-making.
In summary, Monte Carlo simulations' effectiveness lies in their ability to leverage randomness, historical data, and probabilistic models to simulate real-world scenarios comprehensively. This versatility makes them invaluable for risk assessment, decision-making, and problem-solving across a wide range of disciplines.
Applying Monte Carlo Simulations
Certain methods substitute a single average value for the unknown variable when there is a lot of uncertainty in the forecast or estimate. Alternatively, the Monte Carlo Simulation takes a number of numbers and averages them.
Applications for Monte Carlo simulations are numerous in domains where random variables are a problem, such as business and investing. They are used to calculate the likelihood that an asset's price will move in a specific direction and the probability of cost overruns in major projects.
The math behind MC models in finance
For a Monte Carlo simulation, there are majorly 4 steps involved. They can be summarized as follows:
Step 1: Using the asset's historical price data, create a sequence of periodic daily returns using the natural logarithm to estimate one potential price trajectory:
Step 2: The average daily return, standard deviation, and variance inputs can then be obtained by applying the mean(), std() and var() functions in NumPy library of Python to the complete resultant series, respectively. The drift is equivalent to:
where : σ = Standard Deviation.
Step 3: Next we obtain a random value by using:
Random Value = standard_deviation * norm.ppf(np.random.rand())
Then we compute the following day’s price using the equation for day i:
These formulas describe the probabilistic process of generating the next day's price based on the current day's price, incorporating both deterministic (drift) and stochastic(random value) components.
Step 4: This computation should be done as many times as desired. (One day is represented by each repeat.) A simulation of the asset's potential price movement is the end outcome. An arbitrary number of simulations can be generated in order to determine the likelihood that the price of an asset will follow a specific trajectory.
Algorithm
Data retrieval and preprocessing:
get_data() : it uses the ‘yf.download’ method from the ‘yfinance’ library to download stock price data for the specified stocks from start to end dates. It returns the mean returns and covariance matrix as output.
cagr() : It calculates the Compound Annual Growth Rate (CAGR) based on the initial value, final value, and number of years.
Setting up the Monte Carlo Simulation:
In the Monte Carlo simulation, random normal variables, denoted as Z, are generated to simulate the daily returns of the portfolio for each stock over a specified time period T. These random variables capture the stochastic nature of financial markets and serve as the basis for simulating different market scenarios. By using the np.random.normal() function with the specified size parameter, a matrix of random normal variables is created, representing the daily returns of the portfolio for each stock across multiple time periods.
Running the Simulation:
The Cholesky decomposition is crucial for accurately reflecting the covariance structure of data. It decomposes the covariance matrix into a lower triangular matrix, preserving correlations between stocks. This simplifies generating correlated variables efficiently. By combining mean returns with the Cholesky matrix and random variables, daily returns are generated, maintaining the covariance structure. Simulated returns are then used to project portfolio values over time using cumulative products and weighted sums. This aids in assessing risks and making informed investment decisions.
Visualization:
After calculating the investment time, average CAGR and maximum CAGR, the simulated portfolio values over time are plotted. Insights into the performance of the simulated portfolio, showing the average and maximum CAGR and visualizing the portfolio's value over time.
Example: When running the code for e-commerce companies ['AMZN', 'BABA', 'EBAY', 'SHOP', 'RKUNF', 'PDD', 'MELI'] from May 2019 to May 2022, the following simulation is generated:
Analysis
The results provide insights into the potential growth of the portfolio under different scenarios. The average CAGR gives an indication of the expected annual growth rate of the portfolio, while the maximum CAGR represents the best-case scenario for growth.
Additionally, the plot visualizes the simulated portfolio values over time, showing how the portfolio's value evolves under different market conditions. This can help investors understand the range of possible outcomes and make informed decisions about their investment strategies.
It is important to note that the average cagr and maximum cagr being generated will be different each time the code is run. This is because the weights are generated randomly and differently each time the code runs.
But it is precisely why monte carlo simulation is helpful. They incorporate randomness and variability into their calculations. In the context of generating average compound annual growth rate (CAGR) and maximum CAGR for a portfolio, the random generation of weights ensures that each simulation run produces different outcomes. This reflects the inherent uncertainty and unpredictability present in financial markets.
By allowing weights to be randomly generated each time the code runs, Monte Carlo simulations capture a range of potential scenarios, reflecting the diversity of possible outcomes in real-world investment environments. This variability accounts for factors such as market fluctuations, changes in asset performance, and other uncertainties that impact portfolio returns.
Monte Carlo analysis produces a distribution of potential portfolio performance metrics, such as average CAGR and maximum CAGR. This distribution allows investors to assess the range of possible outcomes, understand the likelihood of achieving certain levels of return, and evaluate the associated risks.
In summary, while the random generation of weights may lead to variations in average and maximum CAGR each time the code runs, Monte Carlo simulations offer a robust framework for evaluating investment strategies by accounting for uncertainty and providing probabilistic insights into portfolio performance.
Code
The link to the Python notebook wherein the code of the above project is provided:
The result so obtained on various sectors are as such:
Modern Portfolio Theory v/s Monte-Carlo Simulation
Markowitz portfolio optimization aims to find the optimal allocation of assets in a portfolio to achieve the highest expected return for a given level of risk, or conversely, the lowest risk for a given level of return. It considers the mean return and covariance matrix of assets to construct efficient frontiers. While Monte Carlo optimisation is a simulation-based technique that models uncertain variables by creating random samples from probability distributions.
Markowitz optimization is widely used in finance and investment management for its simplicity and effectiveness in balancing risk and return. Monte Carlo optimization is often used when the underlying distributions are complex or when explicit mathematical formulations are difficult to obtain. It provides a flexible framework for incorporating various sources of uncertainty into the optimization process.
Citations and References
IBM>Topics>Monte Carlo Simulations
Favourite part