Fbasic option

Fbasic option


The following object is masked from ‘package:TTR’:

    volatility

Warning messages:
1: package ‘fOptions’ was built under R version 3.5.1
2: package ‘timeDate’ was built under R version 3.5.1
3: package ‘timeSeries’ was built under R version 3.5.1
4: package ‘fBasics’ was built under R version 3.5.1
> library(fOptions)
> library("fExoticOptions", lib.loc="~/R/win-library/3.5")
Warning message:
package ‘fExoticOptions’ was built under R version 3.5.1
> library(fExoticOptions)
> a <- GBSOption("c", 100, 100, 1, 0.02, -0.02, 0.3, title = NULL,
+                description = NULL)
> (z <- a@price)
[1] 10.62678
> a <- GeometricAverageRateOption("c", 100, 100, 1, 0.02, -0.02, 0.3,
+                                 title = NULL, description = NULL)
> (z <- a@price)
[1] 5.889822
> vanilla <- GBSOption(TypeFlag = "c", S = 100, X = 90, Time = 1,
+                      r = 0.02, b = -0.02, sigma = 0.3)
> KO <- sapply(100:300, FUN = StandardBarrierOption, TypeFlag = "cuo",
+              S = 100, X = 90, K = 0, Time = 1, r = 0.02, b = -0.02, sigma = 0.30)
Warning messages:
1: In if (X >= H) { :
  the condition has length > 1 and only the first element will be used
2: In if (X < H) { :
  the condition has length > 1 and only the first element will be used
> plot(KO[[1]]@price, type = "l",
+      xlab = "barrier distance from spot",
+      ylab = "price of option",
+      main = "Price of KO converges to plain vanilla")
> abline(h = vanilla@price, col = "red")
> library("plot3D", lib.loc="~/R/win-library/3.5")
Warning message:
package ‘plot3D’ was built under R version 3.5.1
> library("scatterplot3d", lib.loc="~/R/win-library/3.5")
> install.packages('plot3D')
Error in install.packages : Updating loaded packages
> BS_surface <- function(S, Time, FUN, ...) {
+     require(plot3D)
+     n <- length(S)
+     k <- length(Time)
+     m <- matrix(0, n, k)
+     for (i in 1:n){
+         for (j in 1:k){
+             l <- list(S = S[i], Time = Time[j], ...)
+             m[i,j] <- max(do.call(FUN, l)@price, 0)
+         }
+     }
+     persp3D(z = m, xlab = "underlying", ylab = "Remaining time",
+             zlab = "option price", phi = 30, theta = 20, bty = "b2")
+ }
> BS_surface(seq(1, 200,length = 200), seq(0, 2, length = 200),
+            GBSOption, TypeFlag = "c", X = 90, r = 0.02, b = 0, sigma = 0.3)
> BS_surface(seq(1,200,length = 200), seq(0, 2, length = 200),
+            StandardBarrierOption, TypeFlag = "cuo", H = 130, X = 90, K = 0,
+            r = 0.02, b = -0.02, sigma = 0.30)
> BS_surface(seq(1,200,length = 200), seq(0, 2, length = 200),
+            StandardBarrierOption, TypeFlag = "cuo", H = 130, X = 90, K = 0,
+            r = 0.02, b = -0.02, sigma = 0.30)
> GetGreeks <- function(FUN, arg, epsilon,...) {
+     all_args1 <- all_args2 <- list(...)
+     all_args1[[arg]] <- as.numeric(all_args1[[arg]] + epsilon)
+     all_args2[[arg]] <- as.numeric(all_args2[[arg]] - epsilon)
+     (do.call(FUN, all_args1)@price -
+             do.call(FUN, all_args2)@price) / (2 * epsilon)
+ }
> x <- seq(10, 200, length = 200)
> delta <- vega <- theta <- rho <- rep(0, 200)
> for(i in 1:200){
+     delta[i] <- GetGreeks(FUN = FloatingStrikeLookbackOption,
+                           arg = 2, epsilon = 0.01, "p", x[i], 100, 1, 0.02, -0.02, 0.2)
+     vega[i] <- GetGreeks(FUN = FloatingStrikeLookbackOption,
+                          arg = 7, epsilon = 0.0005, "p", x[i], 100, 1, 0.02, -0.02,
+                          0.2)
+     theta[i] <- GetGreeks(FUN = FloatingStrikeLookbackOption,
+                           arg = 4, epsilon = 1/365, "p", x[i], 100, 1, 0.02, -0.02,
+                           0.2)
+     rho[i] <- GetGreeks(FUN = FloatingStrikeLookbackOption,
+                         arg = 5, epsilon = 0.0001, "p", x[i], 100, 1, 0.02, -0.02, 0.2)
+ }
> par(mfrow = c(2, 2))
> plot(x, delta, type = "l", xlab = "S", ylab = "", main = "Delta")
> plot(x, vega, type = "l", xlab = "S", ylab = "", main = "Vega")
> plot(x, theta, type = "l", xlab = "S", ylab = "", main = "Theta")
> plot(x, rho, type = "l", xlab = "S", ylab = "", main = "Rho")
https://mathclasstutor.blogspot.com

Post a Comment

0 Comments