Reputation: 137
Simulate in a graph 50 sample paths of a stock price $80 over 90 days modeled as geometric Brownian motion with drift parameter 0.1 and volatility 0.5. Show in a graph this process on the vertical axis Price option and time on the horizontal axis. Find the probability that in 90 days the option price of will rise to at least $100.
library(sde)
mu<-0.1
sigma<-0.5
P0<-80 #initial price
T <-90/360 #time in years
nt=10000 #number of trajectories within each simulation
n=100 #time periods
dt<-T/n #length of time periods
t <- seq(0,T,by=dt)
X=matrix(rep(0,length(t)*nt),nrow = nt)
for(i in 1:nt) {
X[i,]=GBM(x=P0, r=mu, sigma=sigma, T=T, N=n)
}
ymax=max(X); ymin=min(X) #bounds for simulated prices
plot(t,X[1,],type="l", ylim=c(ymin,ymax), col=1, xlab="Time", ylab="Price Y(t)")
for(i in 2:nt){
lines(t,X[i,], type='l', ylim=c(ymin, ymax), col=i)
}
Prob<-sum(nt>=100)/nt
Prob
Upvotes: 3
Views: 3989
Reputation: 16988
The answer depends on how you interpret your parameters t
, n
and T
.
I make a few assumptions: since
T <- 90/360
i suppose, this means 90 days of a year (approx. 360, which is common in finance for a year). Your definition of t
n <- 100
dt <- T/n
t <- seq(0, T, by=dt)
gives the timesteps for your simulation, therefore your day 90 is simply given by max(t) = 0.25 = T
with index 101
, the last element of t
.
X
contains 50 paths of your stochastic process, indexed by X[i,]
, at timesteps j
given by X[,j]
. So if you want to know the values of your 50 simulations at day 90 just look at X[,101]
.
So you want to know how many of your paths exceed 100 at day 90. Just count them by
success <- sum(X[,101] >= 100)
If you want to calculate a empirical probability just divide them by the number of your paths. Therefore
emp_prob <- success/nt
Upvotes: 1