0% found this document useful (0 votes)
11 views

Resources 2

This document discusses using the Monte Carlo method to predict stock price movements. It explains that stock prices follow random walks and are unpredictable based on past prices alone. The Monte Carlo method runs simulations with random returns drawn from a normal distribution to predict a range of possible future prices. It provides instructions to choose a stock, obtain historical price data, calculate returns, fit a normal distribution, run simulations drawing from the distribution to predict prices for the next 30 days, and compare the results to actual subsequent prices.

Uploaded by

chakradhar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Resources 2

This document discusses using the Monte Carlo method to predict stock price movements. It explains that stock prices follow random walks and are unpredictable based on past prices alone. The Monte Carlo method runs simulations with random returns drawn from a normal distribution to predict a range of possible future prices. It provides instructions to choose a stock, obtain historical price data, calculate returns, fit a normal distribution, run simulations drawing from the distribution to predict prices for the next 30 days, and compare the results to actual subsequent prices.

Uploaded by

chakradhar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

By now I hope you have basic knowledge of what Tickers are and how data for different

ticker symbols is scraped. For the further analysis I'll be choosing Infosys Limited stock
(mainly because it is one of the most actively traded stocks for the past few days).
It's ticker symbol is INFY.NS
You are free to choose any other stock and experiment with it.

The core component of the project is Random Walk Theory, which is a belief that market
price movements are independent of past values except in the way that they follow the same
distribution.
You can read more about it here:
Random walk

We'll be using Monte Carlo method for generating various simulations for predicting the
future price movement. Simply put, the Monte Carlo method runs an enormous number
of trials with different random numbers generated from an underlying distribution
(here Normal Distribution) for the uncertain variables (here price of the stock).

Here's a good read on monte carlo method:


Montecarlo

For the project:

Create a new jupyter notebook on Google Colab and start by importing the required libraries.
Choose a stock of your choice and scrape its price data for some fixed days (say 30 days).
(Have a look at the data and maybe try predicting the future price movements before actually
implementing the code.)
Important note: We'll be using Adjusted close price for our analysis because of being
adjusted with any important decisions and events like stock splits and dividends it is a good
measure of market price. Make sure you select the 'Adj Close' column of your scraped
data.

Now to implement Monte Carlo Method, you need to know the independent and dependent
variables. Clearly price is the dependent variable and we need to predict it based on the
randomized returns (independent variable).

Calculate historical returns using price.pct_change() (consider price as your pandas


DataFrame of Adjusted Price)

Make sure you remove NaN(Not a Number) values, generated in the first row because of not
having data from the previous day to calculate percent change.

For the next step of the Monte Carlo method you are required to know the probability
distribution of the independent variable.
For the infosys stock, here's what I got:
It follows a somewhat left skewed normal distribution.

Using np.random.normal we'll choose values from standard normal distribution and then to
account for skewness we'll take about 20% values above mean and 25% values below
mean.
(I am choosing 10 simulations to calculate price for next 30 days)

Set upper and lower limits (using nom.ppf() which basically finds the value of a random
variable for which the CDF takes the given value), and if any value is beyond this limit make
them equal to the limit values.

Make sure you set the np.random.seed() to some value so that you get the same results
every time you run the code.

Now from standard normal distribution we'll calculate returns based on the formula:

returns (normal distribution)= returns (standard normal distribution) * standard


deviation (of normal distribution) + mean (of normal distribution)

Below is my code including all the above steps.

Store predicted price values in a new list by initializing with last price you had and calculating
new price by:
new price= previous price*(1+returns)
Plot the figure to see your predicted values

Here's what my code shows:

With this you are done with predicting future prices using the Monte Carlo method.

You can play around with your code to explore more.

For example, instead of using data from the last 30 days, I scraped data for the last 45 days
and calculated results on the first 30 days only and compared my results on the next 15
days. Here's what I got:
Here black color represents the actual price, following values similar to predicted price
range.

You might also like