**Monte Carlo Simulation: Introduction****Important Terms**-
**Theory of Monte Carlo Simulation** -
**Monte Carlo In Finance** -
**Forecasting the stock price using Monte Carlo Analysis** -
**Geometric Brownian Motion (GBM)**

*Contributed by: Sreekanth Tadakaluru LinkedIn Profile: https://www.linkedin.com/in/sreekanth-tadakaluru-3301649b/ *

First, the only certainty is that there is no certainty. Second, every decision as a consequence is a matter of weighing probabilities. Third, despite uncertainty, we must decide and we must act. And lastly, we need to judge decisions not only on the results but how those decisions were made. – Robert E. Rubin

**Introduction to Monte Carlo Simulation**

Monte Carlo simulation (also known as Monte Carlo Analysis) is a computerized mathematical technique that helps the people to quantify the risk associated with quantitative analysis and decision making. Monte Carlo simulation is a type of simulation that relies on repeated random sampling and statistical analysis to compute the results. This method of simulation is very closely related to random experiments, experiments for which the specific result is not known in advance. In this context, Monte Carlo simulation can be considered as a methodical way of doing so-called what-if analysis. This approach is used by professionals in many fields as finance, project management, energy, manufacturing, engineering, research and development, insurance, oil and gas, transportation, and the environment.

**Important** **Terms**

**Random Sampling**Refers to a variety of selection techniques in which sample members are selected by chance, but with a known probability of selection.**Random Number Generator**generates random numbers that can be used where unbiased results are critical, such as when shuffling a deck of cards for a poker game or drawing numbers for a lottery, etc.**Probability Distribution**is a statistical function that describes all the possible values and likelihoods that a random variable can take within a given range.

Also Read: Understanding Probability Distribution

Some of Probability distributions are-

- Bernoulli Distribution
- Uniform Distribution
- Binomial Distribution
- Normal Distribution
- Poisson Distribution
- Exponential Distribution

**Theory of Monte Carlo Simulation**

The main idea behind the Monte Carlo simulation is the repeated random sampling of the random variable and the aggregation of the results. The result of the model is recorded, and the process is repeated. When the simulation is complete, the results can be averaged to determine the estimated value.

**Monte Carlo In Finance**

Financial models heavily rely on assumptions. Not all but some of those assumptions have highly associated uncertainty and risk. In these cases, Monte Carlo Simulation helps us to analyse the effect of randomness introduced by some of the variables in our model. The simulation works by performing repetitive calculations using random inputs for these assumptions and then averages out the most probable output of the model.

The main use case of Monte Carlo In Finance are-

- Portfolio Valuation
- Sensitivity Analysis
- Cash Flows
- Options Pricing or Equity Pricing
- Valuation of Equity Options
- Valuation of fixed income instruments and interest rate derivatives
- Project Finance

**Forecasting the stock price using Monte Carlo Analysis **

It would be great if we can precisely predict how stock prices will change in the near or far future. We would be rich, but it is almost impossible to create exact predictions. There are so many factors involved in the movement of stock prices that are hard to model. Investors make their decisions based on empirical evidence and stock market indicators. While a piece of breaking news in the country causes an investor to buy a stock, it causes another one to sell that same stock. Therefore, predicting stock prices is a difficult job, but we still have valuable tools that can help us to understand the stock price movement up to some point.

**Geometric Brownian Motion (GBM)**

To find the expected asset price, a Geometric Brownian Motion has been used, which expresses the change in stock price using a constant drift µ and volatility σ as a stochastic differential equation (SDE)

*S(t) is Current day Price**S is Previous day price**Μ* is the expected return

*σ* is the standard deviation of returns

*W(t) is random value from normal distribution***Forecasted Price = Previous Day Price * exp (drift + random Value)**

For each period, our model assumes the price will “drift” up by the expected return. But the drift will be added or subtracted by a random shock. The random shock will be the standard deviation “s” multiplied by a random number “e.”

Finally,

GBM Assumes the logarithmic change of the stock price to be a normally distributed random variable. To forecast the Price using Monte Carlo Simulation, Infy Stock price has been downloaded from Yahoo for the past 5 years. The data has been shown below.

Infy Stock Price for past 5 years .

**Step 1 : Calculate the daily Returns**

The daily returns are calculated as the percent change between the previous price and current day price.

Returns = (Previous day Price-Current Day Price)/ Previous day Price

**Code:**

`infy_ts_data['Returns']=infy_ts_data['Adj Close'].pct_change()`

**Step 2 : Calculate Mean, Variance and Standard Deviation of Returns**

**Code:**

```
infy_ret_mu = infy_ts_data['Returns'].mean()
infy_ret_var = infy_ts_data['Returns'].var()
infy_ret_std = infy_ts_data['Returns'].std()
print(infy_ret_mu)
print(infy_ret_var)
print(infy_ret_std)
```

**Step 3 : Calculate the Drift **

Drift = mean of returns – 0.5 * variance of the returns

**Code:**

`drift = infy_ret_mu - (0.5 * infy_ret_var)`

**Step 4 : Random Variable **

The second component of the Brownian motion is a random variable, z, a number corresponding to the distance between the mean and the events, expressed as the number of standard deviations.

We will include this random element within the “PPF” distribution to obtain the distance from the mean corresponding to each of these randomly generated probabilities.

I would like to specify the time intervals we will use will be 20, because we are interested in forecasting the stock price for the upcoming 20 days. Then, to “iterations” I will attribute the value of 10, which means I will ask the computer to produce 20 series of future stock price predictions.

**Code:**

```
intervals = 20
iterations = 20
norm.ppf(np.random.rand(intervals,iterations))
```

**Step 5 : Calculate the Daily Returns **

Daily Returns = Exp ( Drift + Random Value)

Random Value = Std Dev * Z

**Code: **

`returns = np.exp(drift+(infy_ret_std*norm.ppf(np.random.rand(intervals,iterations))))`

**Step 6 : Calculate forecasted price for next 20 days.**

New Price = Prev Price + New Returns

**Code: **

```
for t in range(1,intervals):
new_price[t] = new_price[t-1] * returns[t]
```

The below plot shows the forecasted price for the next 20 days for 20 random numbers.

The Price Calculation is based on the random numbers. But in general, the stock price depends on multiple factors. So if we include all the factors with random generation, we would get accurate predictions.

Hope you found this tutorial helpful! If you wish to upskill, you can take up Great Learning’s PGP Data Science and Business Analytics Course.

0