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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 29 22:49:28 CEST 2012


Author: gsee
Date: 2012-06-29 22:49:28 +0200 (Fri, 29 Jun 2012)
New Revision: 1090

Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/R/instrument.R
   pkg/FinancialInstrument/R/parse_id.R
   pkg/FinancialInstrument/R/update_instruments.iShares.R
   pkg/FinancialInstrument/man/instrument.Rd
Log:
 - A currency cannot be overwritten by an instrument of another type without 
   explicitly deleting it first (e.g. via rm_currencies()).  This makes possible
   stock("USD", currency("USD")).
 - parse_id updated to know that "USD.1" is not a calendar spread.



Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2012-06-29 20:28:42 UTC (rev 1089)
+++ pkg/FinancialInstrument/DESCRIPTION	2012-06-29 20:49:28 UTC (rev 1090)
@@ -11,7 +11,7 @@
     meta-data and relationships. Provides support for
     multi-asset class and multi-currency portfolios. Still
     in heavy development.
-Version: 0.15.0
+Version: 0.15.1
 URL: https://r-forge.r-project.org/projects/blotter/
 Date: $Date$
 Depends:

Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R	2012-06-29 20:28:42 UTC (rev 1089)
+++ pkg/FinancialInstrument/R/instrument.R	2012-06-29 20:49:28 UTC (rev 1090)
@@ -80,7 +80,13 @@
 #' 
 #' The \code{primary_id} will be coerced within reason to a valid \R variable 
 #' name by using \code{\link{make.names}}. We also remove any leading '1' digit 
-#' (a simple workaround to account for issues with the Reuters API).  
+#' (a simple workaround to account for issues with the Reuters API).  If you are
+#' defining an instrument that is not a \code{currency}, with a primary_id that
+#' already belongs to a \code{currency}, a new primary_id will be create using
+#' \code{make.names}.  For example, \code{stock("USD", currency("USD"))}, would
+#' create a stock with a primary_id of \dQuote{USD.1} instead of overwritting
+#' the \code{currency}.
+#'
 #' Please use some care to choose your primary identifiers so that R won't 
 #' complain.  If you have better regular expression code, we'd be happy to 
 #' include it.   
@@ -203,6 +209,12 @@
       tclass="instrument" 
   } else tclass = unique(c(type,"instrument"))
 
+  if (is.currency.name(primary_id)) {
+      warning(paste(primary_id, "is the name of a currency. Using", 
+          primary_id <- tail(make.names(c(ls_instruments(), primary_id), 
+                                        unique=TRUE), 1),
+          "for the primary_id of this", type))
+  }
   tmpinstr <- list(primary_id = primary_id,
                    currency = currency,
                    multiplier = multiplier,

Modified: pkg/FinancialInstrument/R/parse_id.R
===================================================================
--- pkg/FinancialInstrument/R/parse_id.R	2012-06-29 20:28:42 UTC (rev 1089)
+++ pkg/FinancialInstrument/R/parse_id.R	2012-06-29 20:49:28 UTC (rev 1090)
@@ -141,11 +141,16 @@
                 if (nchar(pidhalf$suffix) == nchar(strsplit(x, "\\.")[[1]][2])) {
                     root <- pidhalf$root
                     suffix <- gsub(root, "", x)
-                } else {
+                } else if ("outright" %in% pidhalf$type) {
                     #x <- "DIA111230P139.75"
                     root <- gsub("[0-9.-]","",x) #now it looks like DIAP, SPYC or TP
                     root <- substr(root, 1,nchar(root)-1)
                     suffix <- gsub(root,"",x) #whatever isn't the root
+                } else {
+                    #x <- "USD.1" #a stock whose symbols was created by 'make.names'
+                    suffix <- ""
+                    root <- x
+                    type <- 'root'
                 }
             } else {
                 #has a dot, has a number, and a non-number, and no underscore.  Probably a strange root (e.g. "..BL2")

Modified: pkg/FinancialInstrument/R/update_instruments.iShares.R
===================================================================
--- pkg/FinancialInstrument/R/update_instruments.iShares.R	2012-06-29 20:28:42 UTC (rev 1089)
+++ pkg/FinancialInstrument/R/update_instruments.iShares.R	2012-06-29 20:49:28 UTC (rev 1090)
@@ -34,7 +34,7 @@
   tmp <- tempfile()
   lnk <- paste0("http://us.ishares.com/product_info/fund/excel_returns.htm",
                 "?assetClassCd=EQ&ticker=&asofDt=")
-  download.file(lnk, destfile=tmp)
+  download.file(lnk, destfile=tmp, quiet=TRUE)
   fr <- read.csv(tmp, skip=3, stringsAsFactors=FALSE, header=FALSE)
   colnames(fr) <- read.delim(text=readLines(tmp, 1), sep=",", header=FALSE, 
                              stringsAsFactors=FALSE)

Modified: pkg/FinancialInstrument/man/instrument.Rd
===================================================================
--- pkg/FinancialInstrument/man/instrument.Rd	2012-06-29 20:28:42 UTC (rev 1089)
+++ pkg/FinancialInstrument/man/instrument.Rd	2012-06-29 20:49:28 UTC (rev 1090)
@@ -92,11 +92,19 @@
   The \code{primary_id} will be coerced within reason to a
   valid \R variable name by using \code{\link{make.names}}.
   We also remove any leading '1' digit (a simple workaround
-  to account for issues with the Reuters API). Please use
-  some care to choose your primary identifiers so that R
-  won't complain.  If you have better regular expression
-  code, we'd be happy to include it.
+  to account for issues with the Reuters API).  If you are
+  defining an instrument that is not a \code{currency},
+  with a primary_id that already belongs to a
+  \code{currency}, a new primary_id will be create using
+  \code{make.names}.  For example, \code{stock("USD",
+  currency("USD"))}, would create a stock with a primary_id
+  of \dQuote{USD.1} instead of overwritting the
+  \code{currency}.
 
+  Please use some care to choose your primary identifiers
+  so that R won't complain.  If you have better regular
+  expression code, we'd be happy to include it.
+
   Identifiers will also try to be discovered as regular
   named arguments passed in via \code{...}.  We currently
   match any of the following:



More information about the Blotter-commits mailing list