Generate stock option prices – How to simulate a Brownian motion

October 29, 2012
By

(This article was first published on ProbaPerception, and kindly contributed to R-bloggers)

The Brownian motion is certainly the most famous stochastic process (a random variable evolving in the time). It has been the first way to model a stock option price (Louis Bachelier’s thesis in 1900).

The reason why is easy to understand, a Brownian motion is graphically very similar to the historical price of a stock option.

A Brownian motion generated with R (n = 1000)
The historical price of the index FTSE MID 250, source Yahoo Finance.

Even though it is not any more considered as the real distribution of stock options, it is still used in finance and methods to simulate a Brownian motion are really useful. As you will see the code is strikingly easy. We have used the Donsker’s principle.

If Y(i) is a serie of k variables normally distributed, then we can  create X(i) = (Y(1) + … + Y(i))sqrt(i/k). Then X(i) is a proxy of the Brownian motion.

The code (R) : 

size = 1000
y = rnorm(size)
x = y

for (i in 1:size){
  x[i] = 1/sqrt(size)*(sum(y[1:i])*sqrt(i))
}

plot(x, type = ‘l’, xlab = ‘Time’, ylab = ‘Profit’)

To leave a comment for the author, please follow the link and comment on their blog: ProbaPerception.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training



http://www.eoda.de







ODSC

ODSC

CRC R books series











Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)