[Uwgarp-commits] r198 - in pkg/GARPFRM: R man sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 30 01:41:30 CEST 2014


Author: rossbennett34
Date: 2014-06-30 01:41:29 +0200 (Mon, 30 Jun 2014)
New Revision: 198

Modified:
   pkg/GARPFRM/R/options.R
   pkg/GARPFRM/man/computeGreeks.Rd
   pkg/GARPFRM/man/optionSpec.Rd
   pkg/GARPFRM/man/optionValue.Rd
   pkg/GARPFRM/sandbox/test_options.R
Log:
Revising man files and adding examples to option functions

Modified: pkg/GARPFRM/R/options.R
===================================================================
--- pkg/GARPFRM/R/options.R	2014-06-29 22:39:31 UTC (rev 197)
+++ pkg/GARPFRM/R/options.R	2014-06-29 23:41:29 UTC (rev 198)
@@ -16,6 +16,9 @@
 #' currencies
 #' @return an object of class "option" with the parameters that specify the option
 #' @author Ross Bennett
+#' @examples
+#' am.call <- optionSpec(style="american", type="call")
+#' euro.call <- optionSpec(style="european", type="call", S0=30, K=30, maturity=1, r=0.05, volatility=0.25, q=0)
 #' @export
 optionSpec <- function(style=c("european", "american"), 
                        type=c("call", "put"), 
@@ -58,6 +61,11 @@
 #' @param \dots any other passthrough parameters
 #' @return the estimated value of the option
 #' @author Ross Bennett
+#' @examples
+#' am.call <- optionSpec(style="american", type="call")
+#' am.call.val <- optionValue(am.call, N=4)
+#' euro.call <- optionSpec(style="european", type="call", S0=30, K=30, maturity=1, r=0.05, volatility=0.25, q=0)
+#' euro.call.val.bs <- optionValue(euro.call, method="Black-Scholes")
 #' @export
 optionValue <- function(option, method=c("Binomial", "Black-Scholes"), N=20, ...){
   if(!is.option(option)) stop("option must be of class 'option'")
@@ -296,6 +304,18 @@
 #' @param plot TRUE/FALSE to plot the greek value as the underlying price and/ time to maturity vary
 #' @param \dots passthrough parameters to \code{\link{plot}}
 #' @author Ross Bennett
+#' @examples
+#' euro.call <- optionSpec(style="european", type="call", S0=30, K=30, maturity=1, r=0.05, volatility=0.25, q=0)
+#' # European call greeks
+#' computeGreeks(euro.call, greek = "delta")
+#' computeGreeks(euro.call, greek = "gamma")
+#' computeGreeks(euro.call, greek = "theta")
+#' computeGreeks(euro.call, greek = "vega")
+#' computeGreeks(euro.call, greek = "rho")
+#' 
+#' # Plotting
+#' computeGreeks(euro.call, "delta", prices = seq(20, 40, 1), plot = TRUE)
+#' computeGreeks(euro.call, "delta", maturities = seq(0.5, 0.01, -0.01), plot = TRUE)
 #' @export
 computeGreeks <- function(option, 
                           greek=c("delta", "theta", "gamma", "rho", "vega"), 
@@ -332,9 +352,7 @@
     if(plot){
       par(mfrow=c(2,1))
       plot(x = prices, y = out[[1]], type="l", ylab=greek, xlab="price", ...=...)
-      plot(x = maturities, y = out[[2]], type="l", xaxt="n", ylab=greek, xlab="time to maturity", ...=...)
-      axis(side = 1, at=maturities, labels = as.character(rev(maturities)))
-      layout(matrix(1,1,1), widths = 1, heights = 1)
+      plot(x = maturities, y = out[[2]], type="l", ylab=greek, xlab="time to maturity", ...=...)
       par(mfrow=c(1,1))
     }
     # return the list
@@ -364,14 +382,11 @@
              type = option$type)
   if(plot){
     if(!is.null(maturities)){
-      xlabels <- as.character(rev(xs))
       xlab <- "time to maturity"
     } else {
-      xlabels <- xs
       xlab <- "price"
     }
-    plot(x = xs, y = out, type="l", ylab=greek, xaxt="n", xlab=xlab, ...=...)
-    axis(side = 1, at=xs, labels = xlabels)
+    plot(x = xs, y = out, type="l", ylab=greek, xlab=xlab, ...=...)
   }
   return(out)
 }

Modified: pkg/GARPFRM/man/computeGreeks.Rd
===================================================================
--- pkg/GARPFRM/man/computeGreeks.Rd	2014-06-29 22:39:31 UTC (rev 197)
+++ pkg/GARPFRM/man/computeGreeks.Rd	2014-06-29 23:41:29 UTC (rev 198)
@@ -3,8 +3,8 @@
 \alias{computeGreeks}
 \title{Option Greeks}
 \usage{
-computeGreeks(option, greek = "delta", prices = NULL, maturities = NULL,
-  plot = FALSE, ...)
+computeGreeks(option, greek = c("delta", "theta", "gamma", "rho", "vega"),
+  prices = NULL, maturities = NULL, plot = FALSE, ...)
 }
 \arguments{
 \item{option}{an \code{option} object created with \code{\link{optionSpec}}}
@@ -24,6 +24,19 @@
 \description{
 Compute the greeks of an option using the Black-Scholes-Merton framework
 }
+\examples{
+euro.call <- optionSpec(style="european", type="call", S0=30, K=30, maturity=1, r=0.05, volatility=0.25, q=0)
+# European call greeks
+computeGreeks(euro.call, greek = "delta")
+computeGreeks(euro.call, greek = "gamma")
+computeGreeks(euro.call, greek = "theta")
+computeGreeks(euro.call, greek = "vega")
+computeGreeks(euro.call, greek = "rho")
+
+# Plotting
+computeGreeks(euro.call, "delta", prices = seq(20, 40, 1), plot = TRUE)
+computeGreeks(euro.call, "delta", maturities = seq(0.5, 0.01, -0.01), plot = TRUE)
+}
 \author{
 Ross Bennett
 }

Modified: pkg/GARPFRM/man/optionSpec.Rd
===================================================================
--- pkg/GARPFRM/man/optionSpec.Rd	2014-06-29 22:39:31 UTC (rev 197)
+++ pkg/GARPFRM/man/optionSpec.Rd	2014-06-29 23:41:29 UTC (rev 198)
@@ -32,6 +32,10 @@
 \description{
 Specify parameters of an option
 }
+\examples{
+am.call <- optionSpec(style="american", type="call")
+euro.call <- optionSpec(style="european", type="call", S0=30, K=30, maturity=1, r=0.05, volatility=0.25, q=0)
+}
 \author{
 Ross Bennett
 }

Modified: pkg/GARPFRM/man/optionValue.Rd
===================================================================
--- pkg/GARPFRM/man/optionValue.Rd	2014-06-29 22:39:31 UTC (rev 197)
+++ pkg/GARPFRM/man/optionValue.Rd	2014-06-29 23:41:29 UTC (rev 198)
@@ -20,6 +20,12 @@
 \description{
 Estimate the value of an option
 }
+\examples{
+am.call <- optionSpec(style="american", type="call")
+am.call.val <- optionValue(am.call, N=4)
+euro.call <- optionSpec(style="european", type="call", S0=30, K=30, maturity=1, r=0.05, volatility=0.25, q=0)
+euro.call.val.bs <- optionValue(euro.call, method="Black-Scholes")
+}
 \author{
 Ross Bennett
 }

Modified: pkg/GARPFRM/sandbox/test_options.R
===================================================================
--- pkg/GARPFRM/sandbox/test_options.R	2014-06-29 22:39:31 UTC (rev 197)
+++ pkg/GARPFRM/sandbox/test_options.R	2014-06-29 23:41:29 UTC (rev 198)
@@ -19,7 +19,7 @@
 euro.put.val.bs <- optionValue(euro.put, method="Black-Scholes") 
 euro.put.val.bin <- optionValue(euro.put, method="Binomial") 
 
-
+# European call greeks
 computeGreeks(euro.call, greek = "delta")
 computeGreeks(euro.call, greek = "gamma")
 computeGreeks(euro.call, greek = "theta")
@@ -27,8 +27,8 @@
 computeGreeks(euro.call, greek = "rho")
 
 # delta
-computeGreeks(euro.call, prices = seq(20, 40, 1), plot = TRUE)
-computeGreeks(euro.call, maturities = seq(0.5, 0.01, -0.01), plot = TRUE)
+computeGreeks(euro.call, "delta", prices = seq(20, 40, 1), plot = TRUE)
+computeGreeks(euro.call, "delta", maturities = seq(0.5, 0.01, -0.01), plot = TRUE)
 computeGreeks(euro.call, prices = seq(20, 40, 1), maturities = seq(0.5, 0.01, -0.01), plot = TRUE)
 
 # theta
@@ -47,10 +47,7 @@
 computeGreeks(euro.call, "rho", prices = seq(20, 40, 1), plot = TRUE)
 computeGreeks(euro.call, "rho", maturities = seq(0.5, 0.01, -0.01), plot = TRUE)
 
-deltaBS(S0 = 109, K = 100, r = 0.05, q = 0, vol = 0.2, ttm = 1, type = "call")
-deltaBS(S0 = 100:110, K = 100, r = 0.05, q = 0, vol = 0.2, ttm = 1, type = "call")
 
 
 
 
-



More information about the Uwgarp-commits mailing list