Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (59 sloc) 4.01 KB
library("TTR")
# BS d1
D1 <- function (S, E, r, volatility, expiry) {
(log(S / E) + (r + 0.5 * volatility ^ 2) * (expiry)) / (volatility * sqrt(expiry))
}
# BS d2
D2 <- function (d1, volatility, expiry) {
d1 - volatility * sqrt(expiry)
}
# call
C <- function (S, d1, d2, E, r, expiry) {
S * pnorm(d1) - E * exp(-r * (expiry)) * pnorm(d2)
}
# put
P <- function (S, d1, d2, E, r, expiry) {
-S * pnorm(-d1) + E * exp(-r * (expiry)) * pnorm(-d2)
}
# asset: RIU9, expires in 71 days, price: 138820, Trade date: 10.07.2019 0:00:00
asset = 138820
expiry = 1 / 252 * 71
callStrikes = c(130000,132500,135000,137500,140000,142500,145000,147500,150000,152500,155000,157500,160000,162500,165000)
callPrices = c(10800,7950,7190,5560,4270,3150,2250,1600,1070,640,300,170,150,110,60)
putStrikes = c(80000,97500,100000,105000,110000,112500,115000,117500,120000,122500,125000,127500,130000,132500,135000,137500,140000,142500,147500)
putPrices = c(40,80,100,130,220,270,400,490,670,930,1170,1420,2030,2640,3400,4270,5530,6750,11200)
Open = c(116950,115750,117570,117740,118350,117820,118500,119450,119760,121820,120330,121300,120320,121590,121950,121680,121890,123350,123290,121560,120360,120170,120940,120000,119660,121210,120230,119400,119300,117880,117200,120350,120320,121590,120720,120690,123030,124360,122430,123050,123700,122160,122550,123510,123490,126400,125650,125580,127460,128070,128710,130910,131270,131020,131180,132660,133170,136090,134480,135810,135430,136200,136150,135230,137550,136690,137120,138430,137210,138300,137610)
High = c(118280,117790,118000,119000,118350,118500,119300,120580,121790,122000,121830,121700,121520,122600,122390,122210,123500,124110,123690,121560,120550,121200,121300,120800,121000,121440,120720,120000,119410,118500,120500,121000,121990,121590,121580,123150,124760,124520,124070,123770,124050,122920,124130,124070,127300,127260,126640,128060,128670,130070,131630,131490,132690,132330,133110,133850,136650,136370,136350,136560,136390,137080,136780,138360,137910,137730,138580,138850,138310,138340,139270)
Low = c(115550,115750,117000,117620,117270,117630,118440,119390,119570,120400,119850,120000,120060,121550,121150,121670,121720,122800,121470,120200,119690,119950,120050,119430,119660,118750,119380,118950,117150,117000,117110,119620,120080,120420,120330,120630,122640,121980,121880,122960,121590,121390,122540,122070,122450,125180,125200,125370,127330,127870,128450,129910,130970,130530,127100,132610,132710,133800,134350,134460,134470,135270,135160,134600,136370,136130,137120,137210,136600,137310,136830)
Close = c(115960,117790,117400,118520,117990,118460,119300,119500,121650,120400,120600,120270,121250,121980,121690,121870,123340,123320,121720,120200,120150,121030,120350,119630,121000,120240,119720,119740,117680,117700,120500,120520,121640,120770,121120,123100,124690,122500,122990,123650,123540,122600,123600,123880,126740,125720,125630,127540,128200,128650,130800,131430,131030,131300,132780,132960,136030,134450,135690,135370,136070,136130,135280,137710,136610,137170,138470,137260,138220,137510,138820)
ohlc <- data.frame(Open, High, Low, Close)
vYZ <- volatility(ohlc, calc = "yang.zhang")
hv = vYZ[length(vYZ)]
callPricesHV = array(length(callStrikes))
putPricesHV = array(length(putStrikes))
for (i in 1:length(callStrikes))
{
S = asset
E = callStrikes[i]
r = 0
d1 = D1(S, E, r, hv, expiry)
d2 = D2(d1, hv, expiry)
callPricesHV[i] = C(S, d1, d2, E, r, expiry)
}
for (i in 1:length(putStrikes))
{
S = asset
E = putStrikes[i]
r = 0
d1 = D1(S, E, r, hv, expiry)
d2 = D2(d1, hv, expiry)
putPricesHV[i] = P(S, d1, d2, E, r, expiry)
}
xrange = range(putStrikes, callStrikes)
yrange = range(putPrices, callPrices)
plot(xrange, yrange, type = "n", xlab = "Strike", ylab = "Price")
points(putStrikes, putPrices, col = "red3", type = "o")
points(callStrikes, callPrices, col = "forestgreen", type = "o")
points(callStrikes, callPricesHV, col = "blue", type = "o")
points(putStrikes, putPricesHV, col = "orange", type = "o")
abline(v=asset, col="black")
You can’t perform that action at this time.