This worksheet looks at simulating, both arithmetics and geometric, Brownian motion for stock prices, pricing options, and calculating Greeks using numerical differentiation.
Remember to always set your working directory to the source file location. Go to ‘Session’, scroll down to ‘Set Working Directory’, and click ‘To Source File Location’. Read carefully the below and follow the instructions to complete the tasks and answer any questions. Submit your work to RPubs as detailed in previous notes.
Always read carefully the instructions on Sakai. For clarity, tasks/questions to be completed/answered are highlighted in red color (visible in preview) and numbered according to their particular placement in the task section. Quite often you will need to add your own code chunk.
Execute all code chunks, preview, publish, and submit link on Sakai follwoing the naming convention. Make sure to add comments to your code where appropriate. Use own language!
This task follows the two examples in the book R Example 5.1/p 148 for simulating an arithmetic Brownian motion and R Example 5.2/p152 for simulating a geometric motion. Two new packages will be required for this worksheet. They are included in the code chunk below.
#Install package quantmod
if(!require("quantmod",quietly = TRUE))
install.packages("quantmod",dependencies = TRUE, repos = "https://cloud.r-project.org")
#Install package sde for Stochastic Differential Equation
if(!require("sde",quietly = TRUE))
install.packages("sde",dependencies = TRUE, repos = "https://cloud.r-project.org")
#Install package fOptions for pricing and evaluating basic options
if(!require("fOptions",quietly = TRUE))
install.packages("fOptions",dependencies = TRUE, repos = "https://cloud.r-project.org")
##### 1A) Follow example in book to simulate and plot example of an arithmetic Brownian motion. Consider three values for n (number of points): \(2^2, 2^5, 2^{12}\). Explain behavior as n increases.
##inputs:
alpha=0;
sigma=1;
T=1;
n=2^(2);
X0=0.1;
##Generate 1 trajectory
dt=T/n
t=seq(0,T,by=dt)
x=c(X0,alpha*dt+sigma*sqrt(dt)*rnorm(n,mean=0,sd=1))
Xt=cumsum(x)
plot(t,Xt,type='l',xlab="time")
n=2^(5);
dt=T/n
t=seq(0,T,by=dt)
x=c(X0,alpha*dt+sigma*sqrt(dt)*rnorm(n,mean=0,sd=1))
Xt=cumsum(x)
plot(t,Xt,type='l',xlab="time")
n=2^(12)
dt=T/n
t=seq(0,T,by=dt)
x=c(X0,alpha*dt+sigma*sqrt(dt)*rnorm(n,mean=0,sd=1))
Xt=cumsum(x)
plot(t,Xt,type='l',xlab="time")
As n increases, the Brownian Motion has more time periods in the timer interval, hence the movement of the variable will go from discrete to continuous.
##### 1B) Write the mathematical equation representing the values along the y-axis in the above plot. Separately express what the value of each variable in the equation is.
The mathematical equation is: \(x_{i}\)=\(x_{i-1}\)+\(\alpha\)dt+\(\sigma\)sqrt(dt)*\(\varepsilon_{i}\)
In the equation, \(x_{i}\) means the y-aixs value in the plot now, \(x_{i-1}\) means the y-axis value in the short previous time, \(\alpha\) means the drift of the Brownian Motion, dt means the small change of time, \(\sigma\) mean the variance of Brownian Motion, \(\varepsilon_{i}\) means a number stochastically generated from standard normal distribution.
##### 1C) Follow example in book to simulate a geometric Brownian motion.
library(sde)
mu=0.16;
sigma=0.2;
P0=40;
T = 1/12 ##1 month
nt=50;
n=2^(8)
##Generate nt trajectories
dt=T/n; 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)}
##Plot
ymax=max(X); ymin=min(X) #bounds for simulated prices
plot(t,X[1,],t='l',ylim=c(ymin, ymax), col=1, ylab="Price P(t)",xlab="time t")
for(i in 2:nt){lines(t,X[i,], t='l',ylim=c(ymin, ymax),col=i)}
##### 1D) Write the mathematical equation representing the values along the y-axis in the above plot. Separately express what the value of each variable in the equation is.
The mathematical equation is: \(P_{T}\)=\(P_{0}\)exp(\(\mu\)-0.5\(\sigma^{2}\))T+\(\sigma\)\(\varepsilon_{t}\)*sqrt(\(\Delta_{t}\))
In the equation, \(P_{T}\) means the price now, \(P_{0}\) means the initial price at time 0, \(\mu\) means the expected value of the price, \(\sigma\) mean the variance of the price, T means the length of time interval, \(\varepsilon_{t}\) means a number stochastically generated from standard normal distribution, \(\Delta_{t}\) means the small change of time.
##### 1E) How is the geometric Brownian simulation different from the arithmetic simulation? Elaborate.
We can use geometric Brownian Motion to simulate the price of a stock, but we can’t use arithmetic Brownian Motion to describe it. We only can use it to simulate the log return of the stock.
If \(\mu\) and \(\sigma\) are the mean and variance of the simple return of the stock, the geometric Brownian Motion which describes the motion of the stock price has the drift of \(\mu\) and the variance of \(\sigma^{2}\). However, the arithmetic Brownian Motion which is used to describe the motion of the log return of the stock, has the drift of \(\mu\)-0.5\(\sigma^{2}\) and the variance of \(\sigma^{2}\).
Follows the example in the book R Example 5.3/p 156 and R Example 5.5/p 157
##### 2A) Calculate the Call and Put price of the given European Option. Explain what the variables r and b in the function call GBSOption represent.
library(fOptions)
GBSOption(TypeFlag = "c", S = 60, X = 65, Time = 1/4, r = 0.08, b = 0.08, sigma = 0.30)
Title:
Black Scholes Option Valuation
Call:
GBSOption(TypeFlag = "c", S = 60, X = 65, Time = 1/4, r = 0.08,
b = 0.08, sigma = 0.3)
Parameters:
Value:
TypeFlag c
S 60
X 65
Time 0.25
r 0.08
b 0.08
sigma 0.3
Option Price:
2.133372
Description:
Wed Dec 12 00:05:07 2018
GBSOption(TypeFlag = "p", S = 60, X = 65, Time = 1/4, r = 0.08, b = 0.08, sigma = 0.30)
Title:
Black Scholes Option Valuation
Call:
GBSOption(TypeFlag = "p", S = 60, X = 65, Time = 1/4, r = 0.08,
b = 0.08, sigma = 0.3)
Parameters:
Value:
TypeFlag p
S 60
X 65
Time 0.25
r 0.08
b 0.08
sigma 0.3
Option Price:
5.846286
Description:
Wed Dec 12 00:05:08 2018
The variables r in the function GBSOption represents the risk-free interest rate per annum, and the variables b in the function GBSOption represents the cost-of-carry, which is the storage cost plus the interest rate that is paid to finance the stock and discounts the dividend earned. For a non-dividend paying stock the cost-of-carry is r (the risk-free interest rate), because there are no storage costsand no income is earned.
##### 2B) Calculate the particular Greeks Delta, Gamma, and Vega for the above corresponding Call option.
library(fOptions)
GBSGreeks(Selection="delta",TypeFlag="c",S=60,X=65, Time=1/4,r=0.08,b=0.08,sigma=0.30)
[1] 0.3724829
GBSGreeks(Selection="gamma",TypeFlag="c",S=60,X=65, Time=1/4,r=0.08,b=0.08,sigma=0.30)
[1] 0.04204276
GBSGreeks(Selection="vega",TypeFlag="c",S=60,X=65, Time=1/4,r=0.08,b=0.08,sigma=0.30)
[1] 11.35154
##### 2C) Calculate the Delta, Gamma, and Vega for same option using instead numerical differentiation. Write the mathematical equations corresponding to each numerical differentiation.
library(fOptions)
GBSOption(TypeFlag = "c", S = 60, X = 65, Time = 1/4, r = 0.08, b = 0.08, sigma = 0.30)
Title:
Black Scholes Option Valuation
Call:
GBSOption(TypeFlag = "c", S = 60, X = 65, Time = 1/4, r = 0.08,
b = 0.08, sigma = 0.3)
Parameters:
Value:
TypeFlag c
S 60
X 65
Time 0.25
r 0.08
b 0.08
sigma 0.3
Option Price:
2.133372
Description:
Wed Dec 12 00:57:26 2018
GBSOption(TypeFlag = "c", S = 61, X = 65, Time = 1/4, r = 0.08, b = 0.08, sigma = 0.30)
Title:
Black Scholes Option Valuation
Call:
GBSOption(TypeFlag = "c", S = 61, X = 65, Time = 1/4, r = 0.08,
b = 0.08, sigma = 0.3)
Parameters:
Value:
TypeFlag c
S 61
X 65
Time 0.25
r 0.08
b 0.08
sigma 0.3
Option Price:
2.526986
Description:
Wed Dec 12 00:57:27 2018
GBSOption(TypeFlag = "c", S = 59, X = 65, Time = 1/4, r = 0.08, b = 0.08, sigma = 0.30)
Title:
Black Scholes Option Valuation
Call:
GBSOption(TypeFlag = "c", S = 59, X = 65, Time = 1/4, r = 0.08,
b = 0.08, sigma = 0.3)
Parameters:
Value:
TypeFlag c
S 59
X 65
Time 0.25
r 0.08
b 0.08
sigma 0.3
Option Price:
1.781754
Description:
Wed Dec 12 00:57:28 2018
GBSOption(TypeFlag = "c", S = 60, X = 65, Time = 1/4, r = 0.08, b = 0.08, sigma = 0.31)
Title:
Black Scholes Option Valuation
Call:
GBSOption(TypeFlag = "c", S = 60, X = 65, Time = 1/4, r = 0.08,
b = 0.08, sigma = 0.31)
Parameters:
Value:
TypeFlag c
S 60
X 65
Time 0.25
r 0.08
b 0.08
sigma 0.31
Option Price:
2.24717
Description:
Wed Dec 12 00:57:28 2018
GBSOption(TypeFlag = "c", S = 60, X = 65, Time = 1/4, r = 0.08, b = 0.08, sigma = 0.29)
Title:
Black Scholes Option Valuation
Call:
GBSOption(TypeFlag = "c", S = 60, X = 65, Time = 1/4, r = 0.08,
b = 0.08, sigma = 0.29)
Parameters:
Value:
TypeFlag c
S 60
X 65
Time 0.25
r 0.08
b 0.08
sigma 0.29
Option Price:
2.020159
Description:
Wed Dec 12 00:57:28 2018
According to the options prices we just calculated, we continue to calculate the Delta, Gamma and Vega using numerical differentiation:
Delta=(2.526986-1.781754)/(2*1)
Gamma=(2.526986+1.781754-2*2.133372)/(1^2)
Vega= (2.24717-2.020159)/(2*0.01)
Delta
[1] 0.372616
Gamma
[1] 0.041996
Vega
[1] 11.35055
The mathematical equations corresponding to each numerical differentiation are:
Delta=dG/dP=(G(Pt+\(\Delta\)P, t)-G(Pt-\(\Delta\)P, t))/2\(\Delta\)P
Gamma= dG/dP^2=(G(Pt+\(\Delta\)P, t)+G(Pt-\(\Delta\)P, t)-2G(Pt, t))/(\(\Delta\)P)^2
Vega= dG/d\(\sigma\)=G(Pt, \(\sigma\)+\(\Delta\)\(\sigma\))-G(Pt, \(\sigma\)-\(\Delta\)\(\sigma\), t)/2\(\Delta\)\(\sigma\)
##### 2D) Compare results from 2B and 2C. Share observations.
From the results on 2B, we know that the Delta of specified option is 0.3724829, the Gamma of it is 0.04204276, and the Vega of it is 11.35154 by using the formula of Greeks to calculate these values. These are continuous sensitives of the option prices to changes in stock price and volatility.
However, from the result on 2C, we know that Delta of specified option is 0.372616, the Gamma of it is 0.041996, and the Vega of it is 11.35055. This time, we use the numerical differentiation to calculate these discrete sensitives values.
Comparing these 2 types of results, we notice that they are close to each other. Therefore, we can conclude that when using numerical differentiation, if the change in the parameter is relatively very small, the results of calculating discrete sensitives values(Greeks) may be close to continuous sensitives values(Greeks).