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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 26 20:53:51 CEST 2011


Author: gsee
Date: 2011-09-26 20:53:50 +0200 (Mon, 26 Sep 2011)
New Revision: 794

Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/R/instrument.R
   pkg/FinancialInstrument/R/parse_id.R
   pkg/FinancialInstrument/man/instrument.auto.Rd
Log:
 - parse_id and instrument.auto now support yahoo index symbols (e.g. ^GSPC)
 - update docs


Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2011-09-26 17:37:25 UTC (rev 793)
+++ pkg/FinancialInstrument/DESCRIPTION	2011-09-26 18:53:50 UTC (rev 794)
@@ -11,7 +11,7 @@
     meta-data and relationships. Provides support for
     multi-asset class and multi-currency portfolios.  
     Still in heavy development.
-Version: 0.6.6
+Version: 0.6.7
 URL: https://r-forge.r-project.org/projects/blotter/
 Date: $Date$
 Depends:

Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R	2011-09-26 17:37:25 UTC (rev 793)
+++ pkg/FinancialInstrument/R/instrument.R	2011-09-26 18:53:50 UTC (rev 794)
@@ -644,13 +644,25 @@
 #'
 #' If \code{primary_id} is 6 uppercase letters and \code{default_type} is not provided, 
 #' it will be assumed that it is the primary_id of an \code{\link{exchange_rate}}, in which case, 
-#' the 1st and/or 2nd half of \code{primary_id} will be defined as \code{\link{currency}} if not 
+#' the 1st and 2nd half of \code{primary_id} will be defined as \code{\link{currency}}s if not 
 #' the names of already defined \code{\link{instrument}}s.
+#' If the \code{primary_id} begins with a \dQuote{^} it will be assumed that it is a yahoo symbol and
+#' that the instrument is an index (synthetic), and the \sQuote{src} will be set to \dQuote{yahoo}. 
+#' (see \code{\link{setSymbolLookup}})
+#'
+#' If it is not clear from the \code{primary_id} what type of instrument to create, an instrument of type 
+#' \code{default_type} will be created (which is 'NULL' by default).
+#' This will happen when \code{primary_id} is that of a \code{\link{stock}} \code{\link{future}} 
+#' \code{\link{option}} or \code{\link{bond}}.  This may also happen if \code{primary_id} is that of a 
+#' \code{\link{future_series}} or \code{\link{option_series}} but the corresponding \code{future} or 
+#' \code{option} cannot be found.  In this case, the instrument type would be \code{default_type}, but a lot
+#' of things would be filled in as if it were a valid series instrument (e.g. \sQuote{expires}, \sQuote{strike}, 
+#' \sQuote{suffix_id}, etc.)
 #' @param primary_id charater primary identifier of instrument to be created
 #' @param currency character name of currency that instrument will be denominated it. Default=\dQuote{USD}
 #' @param multiplier numeric product multiplier
 #' @param silent TRUE/FALSE. silence warnings?
-#' @param default_type What type of instrument to make if it is not clear from the primary_id. ("stock", "future", etc.)
+#' @param default_type What type of instrument to make if it is not clear from the primary_id. ("stock", "future", etc.) Default is NULL.
 #' @param ... other passthrough parameters
 #' @return Primarily called for its side-effect, but will return the name of the instrument that was created
 #' @note This is not intended to be used to create instruments of type \code{stock}, \code{future}, \code{option},
@@ -745,7 +757,9 @@
         return(exchange_rate(primary_id, defined.by='auto', ...))
     }
     if (any(pid$type == 'synthetic')) {
-        return(synthetic(members=strsplit(primary_id,"\\.")[[1]], currency=currency, defined.by='auto', ...) )
+        if (!is.na(pid$format) && pid$format == 'yahooIndex') {
+            return(synthetic(gsub("\\^","",primary_id), currency=currency, src=list(src='yahoo',name=primary_id), defined_by='auto', ...))
+        } else return(synthetic(members=strsplit(primary_id,"\\.")[[1]], currency=currency, defined.by='auto', ...) )
     } 
     dargs$primary_id <- primary_id
     dargs$currency <- currency

Modified: pkg/FinancialInstrument/R/parse_id.R
===================================================================
--- pkg/FinancialInstrument/R/parse_id.R	2011-09-26 17:37:25 UTC (rev 793)
+++ pkg/FinancialInstrument/R/parse_id.R	2011-09-26 18:53:50 UTC (rev 794)
@@ -26,6 +26,7 @@
 #' @export
 parse_id <- function(x, silent=TRUE, root=NULL) {
     sufftype <- TRUE #will we use the type given by parse_suffix, or overwrite it with e.g. 'exchange_rate', or 'synthetic'
+    suffformat <- TRUE #If x begins with "^" this will be set to FALSE, and we'll overwrite parse_suffix(...)$format with yahooIndex" 
     if (!is.null(root)) {
         suffix <- gsub(root,"",x) #turns ESU1 into U1, or ES_U11 into _U11 
         suffix <- gsub("_","",suffix) #take out the underscore if there is one
@@ -53,10 +54,15 @@
             root <- x
             type <- 'synthetic'
             sufftype <- FALSE
-        } else {
+        } else { #no dots, no numbers
             root <- x
             suffix <- ""
-            if (nchar(x) == 6) {
+            if (substr(x,1,1) == "^") {
+                type <- c('synthetic','root')
+                format <- 'yahooIndex'
+                sufftype <- FALSE
+                suffformat <- FALSE
+            } else if (nchar(x) == 6) {
                 if (is.instrument(getInstrument(substr(x,1,3),silent=TRUE)) 
                     && is.instrument(getInstrument(substr(x,4,6),silent=TRUE))) {
                     type <- c('exchange_rate', 'root')
@@ -136,9 +142,10 @@
     }
     suff <- parse_suffix(suffix, silent=silent)
     if (sufftype) type <- suff$type
+    if (suffformat) format <- suff$format
     structure(list(root=root, suffix=suffix, type=type, month=suff$month, 
                     year=suff$year, strike=suff$strike, right=suff$right, 
-                    cm=suff$cm, cc=suff$cc, format=suff$format),class='id.list')
+                    cm=suff$cm, cc=suff$cc, format=format),class='id.list')
 }
 
 #' parse a suffix_id

Modified: pkg/FinancialInstrument/man/instrument.auto.Rd
===================================================================
--- pkg/FinancialInstrument/man/instrument.auto.Rd	2011-09-26 17:37:25 UTC (rev 793)
+++ pkg/FinancialInstrument/man/instrument.auto.Rd	2011-09-26 18:53:50 UTC (rev 794)
@@ -18,7 +18,7 @@
 
   \item{default_type}{What type of instrument to make if it
   is not clear from the primary_id. ("stock", "future",
-  etc.)}
+  etc.) Default is NULL.}
 
   \item{...}{other passthrough parameters}
 }
@@ -41,11 +41,30 @@
   If \code{primary_id} is 6 uppercase letters and
   \code{default_type} is not provided, it will be assumed
   that it is the primary_id of an
-  \code{\link{exchange_rate}}, in which case, the 1st
-  and/or 2nd half of \code{primary_id} will be defined as
-  \code{\link{currency}} if not the names of already
-  defined \code{\link{instrument}}s.
+  \code{\link{exchange_rate}}, in which case, the 1st and
+  2nd half of \code{primary_id} will be defined as
+  \code{\link{currency}}s if not the names of already
+  defined \code{\link{instrument}}s. If the
+  \code{primary_id} begins with a \dQuote{^} it will be
+  assumed that it is a yahoo symbol and that the instrument
+  is an index (synthetic), and the \sQuote{src} will be set
+  to \dQuote{yahoo}. (see \code{\link{setSymbolLookup}})
 
+  If it is not clear from the \code{primary_id} what type
+  of instrument to create, an instrument of type
+  \code{default_type} will be created (which is 'NULL' by
+  default). This will happen when \code{primary_id} is that
+  of a \code{\link{stock}} \code{\link{future}}
+  \code{\link{option}} or \code{\link{bond}}.  This may
+  also happen if \code{primary_id} is that of a
+  \code{\link{future_series}} or
+  \code{\link{option_series}} but the corresponding
+  \code{future} or \code{option} cannot be found.  In this
+  case, the instrument type would be \code{default_type},
+  but a lot of things would be filled in as if it were a
+  valid series instrument (e.g. \sQuote{expires},
+  \sQuote{strike}, \sQuote{suffix_id}, etc.)
+
   This is not intended to be used to create instruments of
   type \code{stock}, \code{future}, \code{option}, or
   \code{bond} although it may be updated in the future.



More information about the Blotter-commits mailing list