We will stimulate the stock prices that follow geometric brownian motion for the future and then use them to calculate the premium prices of Exotic Options.
Pricing of Exotic Option using numerical methods. Monte carlo stimulation method
cat("\014")
library(sde)
## Warning: package 'sde' was built under R version 3.2.4
## Loading required package: MASS
## Loading required package: stats4
## Loading required package: fda
## Warning: package 'fda' was built under R version 3.2.4
## Loading required package: splines
## Loading required package: Matrix
##
## Attaching package: 'fda'
##
## The following object is masked from 'package:graphics':
##
## matplot
##
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## sde 2.0.14
## Companion package to the book
## 'Simulation and Inference for Stochastic Differential Equations With R Examples'
## Iacus, Springer NY, (2008)
## To check the errata corrige of the book, type vignette("sde.errata")
library(quantmod)
## Loading required package: xts
## Loading required package: TTR
## Version 0.4-0 included new data defaults. See ?getSymbols.
today='2016-03-29'
r=0.03
getSymbols('SPY', src = 'yahoo', from = '2005-01-01',to=today)
## As of 0.4-0, 'getSymbols' uses env=parent.frame() and
## auto.assign=TRUE by default.
##
## This behavior will be phased out in 0.5-0 when the call will
## default to use auto.assign=FALSE. getOption("getSymbols.env") and
## getOptions("getSymbols.auto.assign") are now checked for alternate defaults
##
## This message is shown once per session and may be disabled by setting
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for more details.
## Warning in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=",
## from.m, : downloaded length 208809 != reported length 200
## [1] "SPY"
sigma=sd(dailyReturn(SPY))
s0=coredata(Cl(SPY[today]))
s0=s0[1]
T = 3
strike=210
nt=100000
n=200
#############Generate nt trajectories
dt=T/n
t=seq(0,T,by=dt)
X=matrix(rep(0,length(t)*nt), nrow=nt)
Y=matrix(rep(0,length(t)*nt), nrow=nt)
for (i in 1:nt)
{
X[i,]= GBM(x=s0,r=r,sigma=sigma,T=T,N=n)
}
##Plot
#bounds for simulated prices
plot(t,X[1,],t='l',col=1,
ylab="Price P(t)",xlab="Time t", main="Simulated stochastic future paths")
for(i in 2:nt)
{
lines(t,X[i,],col=i)
}
Aavg <- array(0,dim=c(0,nt))
Aoption.call <- array(0,dim=c(0,nt))
Aoption.put <- array(0,dim=c(0,nt))
for (i in 1:nt)
{
Aavg[i]=mean(X[i,])
Aoption.call[i]=exp(-r*T)*(max((Aavg[i]-strike),0))
Aoption.put[i]=exp(-r*T)*(max((-(Aavg[i]-strike)),0))
}
(arithmetic.asian.call=mean(Aoption.call))
## [1] 4.274536
(arithmetic.asian.put=mean(Aoption.put))
## [1] 0.0430393
Gavg <- array(0,dim=c(0,nt))
Goption.call <- array(0,dim=c(0,nt))
Goption.put <- array(0,dim=c(0,nt))
for (i in 1:nt)
{
Gavg[i]=exp(mean(log(X[i,])))
Goption.call[i]=exp(-r*T)*(max((exp(Gavg[i])-strike),0))
Goption.put[i]=exp(-r*T)*(max((-(exp(Gavg[i])-strike)),0))
}
(geometric.asian.call=mean(Goption.call))
## [1] 5.890475e+94
(geometric.asian.put=mean(Goption.put))
## [1] 0
path <- array(0,dim=c(0,n))
for (i in 0:n+1)
{
path[i]=mean(X[,i])
}
plot(t,path,t='l',col=3,xlab="Time(t)",ylab="Price($)",main="Average path of stock")
library(RQuantLib)
## Warning: package 'RQuantLib' was built under R version 3.2.4
library(fExoticOptions)
## Warning: package 'fExoticOptions' was built under R version 3.2.4
## Loading required package: timeDate
##
## Attaching package: 'timeDate'
##
## The following objects are masked from 'package:RQuantLib':
##
## isHoliday, isWeekend
##
## Loading required package: timeSeries
##
## Attaching package: 'timeSeries'
##
## The following object is masked from 'package:zoo':
##
## time<-
##
## Loading required package: fBasics
##
##
## Rmetrics Package fBasics
## Analysing Markets and calculating Basic Statistics
## Copyright (C) 2005-2014 Rmetrics Association Zurich
## Educational Software for Financial Engineering and Computational Science
## Rmetrics is free software and comes with ABSOLUTELY NO WARRANTY.
## https://www.rmetrics.org --- Mail to: info@rmetrics.org
##
## Attaching package: 'fBasics'
##
## The following object is masked from 'package:TTR':
##
## volatility
##
## Loading required package: fOptions
## Warning: package 'fOptions' was built under R version 3.2.4
##
##
## Rmetrics Package fOptions
## Pricing and Evaluating Basic Options
## Copyright (C) 2005-2014 Rmetrics Association Zurich
## Educational Software for Financial Engineering and Computational Science
## Rmetrics is free software and comes with ABSOLUTELY NO WARRANTY.
## https://www.rmetrics.org --- Mail to: info@rmetrics.org
TurnbullWakemanAsianApproxOption(TypeFlag = "c", S = s0, SA = s0,
X = strike, Time = T, time = T, tau = 0 , r = r,b = r, sigma = sigma)
##
## Title:
## Turnbull Wakeman Asian Approximated Option
##
## Call:
## TurnbullWakemanAsianApproxOption(TypeFlag = "c", S = s0, SA = s0,
## X = strike, Time = T, time = T, tau = 0, r = r, b = r, sigma = sigma)
##
## Parameters:
## Value:
## TypeFlag c
## S 205.119995
## SA 205.119995
## X 210
## Time 3
## time 3
## tau 0
## r 0.03
## b 0.03
## sigma 0.0125693071624312
##
## Option Price:
## 4.278104
##
## Description:
## Sun Apr 17 16:01:06 2016
TurnbullWakemanAsianApproxOption(TypeFlag = "p", S = s0, SA = s0,
X = strike, Time = T, time = T, tau = 0 , r = r,b = r, sigma = sigma)
##
## Title:
## Turnbull Wakeman Asian Approximated Option
##
## Call:
## TurnbullWakemanAsianApproxOption(TypeFlag = "p", S = s0, SA = s0,
## X = strike, Time = T, time = T, tau = 0, r = r, b = r, sigma = sigma)
##
## Parameters:
## Value:
## TypeFlag p
## S 205.119995
## SA 205.119995
## X 210
## Time 3
## time 3
## tau 0
## r 0.03
## b 0.03
## sigma 0.0125693071624312
##
## Option Price:
## 0.04326591
##
## Description:
## Sun Apr 17 16:01:06 2016
AsianOption("geometric", "call", underlying=s0, strike=strike, div=0.0,
riskFree=r, maturity=T, vol=sigma)
## Concise summary of valuation for AsianOption
## value delta gamma vega theta rho divRho
## 4.2048 0.9145 0.0341 16.8684 -2.7229 268.7540 -281.3685
AsianOption("geometric", "put", underlying=s0, strike=strike, div=0.0,
riskFree=r, maturity=T, vol=sigma)
## Concise summary of valuation for AsianOption
## value delta gamma vega theta rho divRho
## 0.0439 -0.0415 0.0341 18.1007 0.0910 -12.8929 12.7612
Lmin <- array(0,dim=c(0,nt))
Lmax <- array(0,dim=c(0,nt))
Loption.call <- array(0,dim=c(0,nt))
Loption.put <- array(0,dim=c(0,nt))
for (i in 1:nt)
{
Lmin[i]=min(X[i,])
Lmax[i]=max(X[i,])
Loption.call[i]=exp(-r*T)*(max((X[i,n+1]-Lmin[i]),0))
Loption.put[i]=exp(-r*T)*(max(Lmax[i]-X[i,n+1],0))
}
(lookback.float.call=mean(Loption.call))
## [1] 17.99624
(lookback.float.put=mean(Loption.put))
## [1] 0.3751179
B=220
payoff <- array(0,dim=c(0,nt))
payoff1 <- array(0,dim=c(0,nt))
for (i in 1:nt)
{
if(Lmax[i]>B)
{
payoff[i]=max(X[i,n+1]-strike,0)
payoff1[i]=0
}
else
{
payoff[i]=0
payoff1[i]=max(X[i,n+1]-strike,0)
}
}
mean.payoff=mean(payoff)
mean.payoff1=mean(payoff1)
(barrier.option.upin = exp(-r*T)*mean.payoff)
## [1] 12.18314
(barrier.option.downin = exp(-r*T)*mean.payoff1)
## [1] 1.011311
BarrierOption(barrType="upin", type="call", underlying=s0,
strike=strike, dividendYield=0, riskFreeRate=r,
maturity=T, volatility=sigma, barrier=B)
## Concise summary of valuation for BarrierOption
## value delta gamma vega theta rho divRho
## 12.261 NA NA NA NA NA NA