[Blotter-commits] r759 - in pkg/FinancialInstrument: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Sep 7 20:18:45 CEST 2011
Author: gsee
Date: 2011-09-07 20:18:43 +0200 (Wed, 07 Sep 2011)
New Revision: 759
Removed:
pkg/FinancialInstrument/man/getRoot.Rd
Modified:
pkg/FinancialInstrument/R/format_id.R
pkg/FinancialInstrument/man/format_id.Rd
Log:
- add sep arg to format_id function
- remove getRoot.Rd (pertinent info is already in getInstrument.Rd)
Modified: pkg/FinancialInstrument/R/format_id.R
===================================================================
--- pkg/FinancialInstrument/R/format_id.R 2011-09-07 15:38:17 UTC (rev 758)
+++ pkg/FinancialInstrument/R/format_id.R 2011-09-07 18:18:43 UTC (rev 759)
@@ -15,6 +15,7 @@
#' @param id character. the id to be reformatted. Can be either a primary_id or a suffix_id
#' @param format character string indicating how the id should be formatted. See Details.
#' @param parse character name of parsing method to use: "id" or "suffix"
+#' @param sep character that will separate root_id and suffix_id of output if calling with \code{parse="id"}
#' @param ... parameters to pass to the parsing function
#' @return character id of the appropriate format
#' @author Garrett See
@@ -28,8 +29,9 @@
#' id3 <- c('VX_aug1','ES_U1', 'VX_U11')
#' format_id(id3,'MMMYY')
#' format_id(id3,'CYY')
+#' format_id(id3,'CY',sep="")
#' @export
-format_id <- function(id, format=NULL, parse=c('id', 'suffix'), ...) {
+format_id <- function(id, format=NULL, parse=c('id', 'suffix'), sep="_", ...) {
if (!is.null(format) && format == FALSE) format <- NULL
parse <- parse[[1]]
out <- NULL
@@ -38,24 +40,24 @@
suffix <- ifelse(parse=='id',pid$suffix, i)
if (any(!is.null(format))) {
tmp <- switch(format[[1]],
- CY=paste(pid$root,paste(M2C(pid$month),substr(pid$year,4,4),sep=""), sep="_"),
- CYY=paste(pid$root,paste(M2C(pid$month),substr(pid$year,3,4),sep=""), sep="_"),
- CYYYY=paste(pid$root,paste(M2C(pid$month),pid$year,sep=""), sep="_"),
- MMM=paste(pid$root,pid$month,sep="_"),
- MMMY=paste(pid$root, paste(pid$month,substr(pid$year,4,4), sep=""), sep="_"),
- MMMYY=paste(pid$root, paste(pid$month,substr(pid$year,3,4), sep=""), sep="_"),
- MMMYYYY=paste(pid$root, paste(pid$month,pid$year,sep=""), sep="_"),
- xxCY=paste(pid$root, paste(substr(suffix,1,2), M2C(pid$month), substr(pid$year,4,4), sep=""), sep="_"),
- xxCYY=paste(pid$root, paste(substr(suffix,1,2), M2C(pid$month), substr(pid$year,3,4), sep=""), sep="_"),
- xxCYYYY=paste(pid$root, paste(substr(suffix,1,2), M2C(pid$month), pid$year, sep=""), sep="_"),
- NNNN=paste(pid$root, sprintf("%02d", match(pid$month,toupper(month.abb))), substr(pid$year,3,4), sep="_"),
+ CY=paste(pid$root,paste(M2C(pid$month),substr(pid$year,4,4),sep=""), sep=sep),
+ CYY=paste(pid$root,paste(M2C(pid$month),substr(pid$year,3,4),sep=""), sep=sep),
+ CYYYY=paste(pid$root,paste(M2C(pid$month),pid$year,sep=""), sep=sep),
+ MMM=paste(pid$root,pid$month,sep=sep),
+ MMMY=paste(pid$root, paste(pid$month,substr(pid$year,4,4), sep=""), sep=sep),
+ MMMYY=paste(pid$root, paste(pid$month,substr(pid$year,3,4), sep=""), sep=sep),
+ MMMYYYY=paste(pid$root, paste(pid$month,pid$year,sep=""), sep=sep),
+ xxCY=paste(pid$root, paste(substr(suffix,1,2), M2C(pid$month), substr(pid$year,4,4), sep=""), sep=sep),
+ xxCYY=paste(pid$root, paste(substr(suffix,1,2), M2C(pid$month), substr(pid$year,3,4), sep=""), sep=sep),
+ xxCYYYY=paste(pid$root, paste(substr(suffix,1,2), M2C(pid$month), pid$year, sep=""), sep=sep),
+ NNNN=paste(pid$root, sprintf("%02d", match(pid$month,toupper(month.abb))), substr(pid$year,3,4), sep=sep),
opt2={
if (!any(pid$format == c("opt2","opt4"))) stop("I'm not programmed to convert non-option_series_ids to option_series_ids")
- ifelse(pid$format == "opt4", paste(pid$root, substr(suffix,3,nchar(suffix)), sep="_"), i)
+ ifelse(pid$format == "opt4", paste(pid$root, substr(suffix,3,nchar(suffix)), sep=sep), i)
},
opt4={
if (!any(pid$format == c("opt2","opt4"))) stop("I'm not programmed to convert non-option_series_ids to option_series_ids")
- ifelse(pid$format == "opt2", paste(pid$root, paste("20",suffix,sep=""), sep="_"), i)
+ ifelse(pid$format == "opt2", paste(pid$root, paste("20",suffix,sep=""), sep=sep), i)
},
i)
if (substr(tmp,1,1) == "_") tmp <- substr(tmp,2,nchar(tmp))
Modified: pkg/FinancialInstrument/man/format_id.Rd
===================================================================
--- pkg/FinancialInstrument/man/format_id.Rd 2011-09-07 15:38:17 UTC (rev 758)
+++ pkg/FinancialInstrument/man/format_id.Rd 2011-09-07 18:18:43 UTC (rev 759)
@@ -3,7 +3,7 @@
\title{format an id}
\usage{
format_id(id, format = NULL, parse = c("id", "suffix"),
- ...)
+ sep = "_", ...)
}
\arguments{
\item{id}{character. the id to be reformatted. Can be
@@ -15,6 +15,9 @@
\item{parse}{character name of parsing method to use:
"id" or "suffix"}
+ \item{sep}{character that will separate root_id and
+ suffix_id of output if calling with \code{parse="id"}}
+
\item{...}{parameters to pass to the parsing function}
}
\value{
@@ -44,6 +47,7 @@
id3 <- c('VX_aug1','ES_U1', 'VX_U11')
format_id(id3,'MMMYY')
format_id(id3,'CYY')
+format_id(id3,'CY',sep="")
}
\author{
Garrett See
Deleted: pkg/FinancialInstrument/man/getRoot.Rd
===================================================================
--- pkg/FinancialInstrument/man/getRoot.Rd 2011-09-07 15:38:17 UTC (rev 758)
+++ pkg/FinancialInstrument/man/getRoot.Rd 2011-09-07 18:18:43 UTC (rev 759)
@@ -1,52 +0,0 @@
-\name{getRoot}
-\alias{getRoot}
-\title{Get the root contract specs for an instrument}
-\usage{
- getRoot(root_id, type = c("future", "option"))
-}
-\arguments{
- \item{root_id}{string (e.g. "ES", ".ES", or "..ES" for
- e-mini S&P 500 futures)}
-
- \item{type}{character. type of instrument to look for
- ("future" or "option"). Alternatively, can be numeric: 1
- for "future" or 2 for "option"}
-}
-\value{
- an object of class \code{type}
-}
-\description{
- Get a \code{future} or \code{option} object
-}
-\details{
- \code{get_option} and \code{get_future} are wrappers, and
- they are called internally by \code{\link{future_series}}
- and \code{\link{option_series}}
-
- \code{\link{future}} and \code{\link{option}} objects may
- have a primary_id that begins with 1 or 2 dots (in order
- to avoid naming conflics). For example, the root specs
- for options (or futures) on the stock with ticker "SPY"
- may be stored with a primary_id of "SPY", ".SPY", or
- "..SPY"
-
- This function will try calling
- \code{\link{getInstrument}} using each possible
- primary_id until it finds the instrument that is of
- appropriate \code{type}.
-}
-\examples{
-\dontrun{
-option('.SPY',currency("USD"),100,underlying_id=stock("SPY","USD"))
-future("..SPY","USD", 100, underlying_id="SPY")
-getRoot("SPY", 'future')
-getRoot("SPY", 'option')
-}
-}
-\author{
- Garrett See
-}
-\seealso{
- \code{\link{getInstrument}}
-}
-
More information about the Blotter-commits
mailing list