[Blotter-commits] r947 - in pkg/FinancialInstrument: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Feb 29 13:05:36 CET 2012


Author: gsee
Date: 2012-02-29 13:05:34 +0100 (Wed, 29 Feb 2012)
New Revision: 947

Added:
   pkg/FinancialInstrument/man/expires.spread.Rd
Modified:
   pkg/FinancialInstrument/R/expires.R
Log:
 add spread expires extraction method (expires.spread)

Modified: pkg/FinancialInstrument/R/expires.R
===================================================================
--- pkg/FinancialInstrument/R/expires.R	2012-02-24 18:01:59 UTC (rev 946)
+++ pkg/FinancialInstrument/R/expires.R	2012-02-29 12:05:34 UTC (rev 947)
@@ -103,3 +103,44 @@
         paste(pid$year, mth, sep="-")
     }
 }
+
+
+#' spread expires extraction method
+#' 
+#' \code{x$expires} will be returned if it is not \code{NULL}.  Otherwise, the 
+#' (character representation of the) exiration date of the first-to-expire of 
+#' the \code{members} will be returned.
+#' 
+#' @param Date Can be a Date or character string.  When \code{expires} is a 
+#'   vector, the retuned value will be one of the two values of \code{expires} 
+#'   that are closest to \code{Date}. (which one will be determined by the value 
+    #'   of \code{expired}).  
+#' @param expired TRUE/FALSE. This determines which date will be used when
+#'   \code{expires} is a vector.  If \code{expired} is \code{TRUE} the date 
+#'   returned will be the last one before \code{Date}.  If \code{expired} is 
+#'   \code{FALSE} the first one after \code{Date} will be returned.
+#' @method expires character
+#' @S3method expires character
+#' @seealso \code{\link{expires.instrument}}
+#' @author Garrett See
+#' @keywords internal
+expires.spread <- function(x, Date, expired=TRUE, ...) {
+    if (inherits(x, "spread")) {
+        if (!is.null(x$expires)) return(x$expires)
+        members <- if (!is.null(x$memberlist$members)) {
+            x$memberlist$members
+        } else if (!is.null(x$members)) {
+            x$members
+        } else {
+            warning(paste("Cannot determine members of x$primary_id"))
+            return(NextMethod("expires"))
+        }
+        return(expires(sort_ids(members)[1]))        
+    } else NextMethod("expires")
+}
+
+
+
+
+
+

Added: pkg/FinancialInstrument/man/expires.spread.Rd
===================================================================
--- pkg/FinancialInstrument/man/expires.spread.Rd	                        (rev 0)
+++ pkg/FinancialInstrument/man/expires.spread.Rd	2012-02-29 12:05:34 UTC (rev 947)
@@ -0,0 +1,35 @@
+\name{expires.spread}
+\alias{expires.spread}
+\title{spread expires extraction method}
+\usage{
+  \method{expires}{character} (x, Date, expired = TRUE,
+    ...)
+}
+\arguments{
+  \item{Date}{Can be a Date or character string.  When
+  \code{expires} is a vector, the retuned value will be one
+  of the two values of \code{expires} that are closest to
+  \code{Date}. (which one will be determined by the value
+  of \code{expired}).}
+
+  \item{expired}{TRUE/FALSE. This determines which date
+  will be used when \code{expires} is a vector.  If
+  \code{expired} is \code{TRUE} the date returned will be
+  the last one before \code{Date}.  If \code{expired} is
+  \code{FALSE} the first one after \code{Date} will be
+  returned.}
+}
+\description{
+  \code{x$expires} will be returned if it is not
+  \code{NULL}.  Otherwise, the (character representation of
+  the) exiration date of the first-to-expire of the
+  \code{members} will be returned.
+}
+\author{
+  Garrett See
+}
+\seealso{
+  \code{\link{expires.instrument}}
+}
+\keyword{internal}
+



More information about the Blotter-commits mailing list