Book Image

Mastering R for Quantitative Finance

Book Image

Mastering R for Quantitative Finance

Overview of this book

Table of Contents (20 chapters)
Mastering R for Quantitative Finance
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

The life of a Double-no-touch option – a simulation


How has the DNT price been evolving during the second quarter of 2014? We have the open-high-low-close type time series with five minute frequency for AUDUSD, so we know all the extreme prices:

d <- read.table("audusd.csv", colClasses = c("character", rep("numeric",5)), sep = ";", header = TRUE)
underlying <- as.vector(t(d[, 2:5]))
t <- rep( d[,6], each = 4)
n <- length(t)
option_price <- rep(0, n)

for (i in 1:n) {
  option_price[i] <- dnt1(S = underlying[i], K = 1000000, U = 0.9600, L = 0.9200, sigma = 0.06, T = t[i]/(60*24*365), r = 0.0025, b = -0.0250)
}
a <- min(option_price)
b <- max(option_price)
option_price_transformed = (option_price - a) * 0.03 / (b - a) + 0.92

par(mar = c(6, 3, 3, 5))
matplot(cbind(underlying,option_price_transformed), type = "l",
    lty = 1, col = c("grey", "red"),
    main = "Price of underlying and DNT",
    xaxt = "n", yaxt = "n",  ylim = c(0.91,0.97),
    ylab = "", xlab = "Remaining...