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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Apr 15 15:21:59 CEST 2012


Author: gsee
Date: 2012-04-15 15:21:59 +0200 (Sun, 15 Apr 2012)
New Revision: 1004

Added:
   pkg/FinancialInstrument/man/add.defined.by.Rd
Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/NAMESPACE
   pkg/FinancialInstrument/R/instrument.R
   pkg/FinancialInstrument/R/load.instruments.R
   pkg/FinancialInstrument/man/getSymbols.FI.Rd
Log:
 - add add.defined.by function
 - fix link in getSymbols.FI docs

Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2012-04-13 02:11:39 UTC (rev 1003)
+++ pkg/FinancialInstrument/DESCRIPTION	2012-04-15 13:21:59 UTC (rev 1004)
@@ -11,7 +11,7 @@
     meta-data and relationships. Provides support for
     multi-asset class and multi-currency portfolios. Still
     in heavy development.
-Version: 0.14.1
+Version: 0.14.2
 URL: https://r-forge.r-project.org/projects/blotter/
 Date: $Date$
 Depends:

Modified: pkg/FinancialInstrument/NAMESPACE
===================================================================
--- pkg/FinancialInstrument/NAMESPACE	2012-04-13 02:11:39 UTC (rev 1003)
+++ pkg/FinancialInstrument/NAMESPACE	2012-04-15 13:21:59 UTC (rev 1004)
@@ -1,4 +1,5 @@
 export(.to_daily)
+export(add.defined.by)
 export(add.identifier)
 export(bond_series)
 export(bond)

Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R	2012-04-13 02:11:39 UTC (rev 1003)
+++ pkg/FinancialInstrument/R/instrument.R	2012-04-15 13:21:59 UTC (rev 1004)
@@ -1128,6 +1128,48 @@
 }
 
 
+#' add a source to the defined.by field of an \code{instrument}
+#' 
+#' concatenate a string or strings (passed through dots) to the defined.by 
+#' field of an instrument (separated by semi-colons).  Any duplicates will be
+#' removed.  See Details.
+#' 
+#' If there is already a value for the \code{defined.by} attribute of the 
+#' \code{primary_id} instrument, that string will be split on semi-colons and
+#' converted to a character vector.  That will be \code{c}ombined with any new 
+#' strings (in \code{...}).  The unique value of this new vector will then
+#' be converted into a semi-colon delimited string that will be assigned to 
+#' the \code{defined.by} attribute of the \code{primary_ids}' instruments
+#' 
+#' Many functions that create or update instrument definitions will also add or
+#' update the value of the defined.by attribute of that instrument.  If an 
+#' instrument has been updated by more than one function, it's \code{defined.by}
+#' attribute will likely be a semi-colon delimited string (e.g. 
+#' \dQuote{TTR;yahoo}).  
+#' @param primary_ids character vector of primary_ids of 
+#'   \code{\link{instrument}}s
+#' @param ... strings, or character vector, or semi-colon delimited string.
+#' @return called for side-effect
+#' @author Garrett See
+#' @seealso \code{\link{add.identifier}}, \code{\link{instrument_attr}}
+#' @examples
+#' \dontrun{
+#' update_instruments.TTR("GS")
+#' getInstrument("GS")$defined.by #TTR
+#' add.defined.by("GS", "gsee", "demo")
+#' add.defined.by("GS", "gsee;demo") #same
+#' }
+#' @export
+add.defined.by <- function(primary_ids, ...) {
+    for(id in primary_ids) {
+        db <- getInstrument(id)[["defined.by"]]
+        instrument_attr(id, "defined.by", 
+            paste(unique(c(unlist(strsplit(db, ";")), 
+                unlist(strsplit(unlist(list(...)), ";")))), collapse=";"))
+    }
+}
+
+
 #' instrument class print method
 #' 
 #' @method print instrument

Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R	2012-04-13 02:11:39 UTC (rev 1003)
+++ pkg/FinancialInstrument/R/load.instruments.R	2012-04-15 13:21:59 UTC (rev 1004)
@@ -236,7 +236,7 @@
 #' a value for an argument, but there is a value for that argument for the 
 #' given \code{Symbol} in the Symbol Lookup Table (see 
 #' \code{\link{setSymbolLookup.FI}}), that value will be used.  Otherwise,
-#' if \code{\link[quantmod]{setDefaults}} has been applied to this function 
+#' if \code{\link[Defaults]{setDefaults}} has been applied to this function 
 #' (\code{getSymbols.FI}) for the argument, the value that was set with 
 #' \code{setDefaults} will be used.  Finally, if none of the above are true,
 #' the formal defaults will be used.

Added: pkg/FinancialInstrument/man/add.defined.by.Rd
===================================================================
--- pkg/FinancialInstrument/man/add.defined.by.Rd	                        (rev 0)
+++ pkg/FinancialInstrument/man/add.defined.by.Rd	2012-04-15 13:21:59 UTC (rev 1004)
@@ -0,0 +1,56 @@
+\name{add.defined.by}
+\alias{add.defined.by}
+\title{add a source to the defined.by field of an \code{instrument}}
+\usage{
+  add.defined.by(primary_ids, ...)
+}
+\arguments{
+  \item{primary_ids}{character vector of primary_ids of
+  \code{\link{instrument}}s}
+
+  \item{...}{strings, or character vector, or semi-colon
+  delimited string.}
+}
+\value{
+  called for side-effect
+}
+\description{
+  concatenate a string or strings (passed through dots) to
+  the defined.by field of an instrument (separated by
+  semi-colons).  Any duplicates will be removed.  See
+  Details.
+}
+\details{
+  If there is already a value for the \code{defined.by}
+  attribute of the \code{primary_id} instrument, that
+  string will be split on semi-colons and converted to a
+  character vector.  That will be \code{c}ombined with any
+  new strings (in \code{...}).  The unique value of this
+  new vector will then be converted into a semi-colon
+  delimited string that will be assigned to the
+  \code{defined.by} attribute of the \code{primary_ids}'
+  instruments
+
+  Many functions that create or update instrument
+  definitions will also add or update the value of the
+  defined.by attribute of that instrument.  If an
+  instrument has been updated by more than one function,
+  it's \code{defined.by} attribute will likely be a
+  semi-colon delimited string (e.g. \dQuote{TTR;yahoo}).
+}
+\examples{
+\dontrun{
+update_instruments.TTR("GS")
+getInstrument("GS")$defined.by #TTR
+add.defined.by("GS", "gsee", "demo")
+add.defined.by("GS", "gsee;demo") #same
+}
+}
+\author{
+  Garrett See
+}
+\seealso{
+  \code{\link{add.identifier}},
+  \code{\link{instrument_attr}}
+}
+

Modified: pkg/FinancialInstrument/man/getSymbols.FI.Rd
===================================================================
--- pkg/FinancialInstrument/man/getSymbols.FI.Rd	2012-04-13 02:11:39 UTC (rev 1003)
+++ pkg/FinancialInstrument/man/getSymbols.FI.Rd	2012-04-15 13:21:59 UTC (rev 1004)
@@ -84,7 +84,7 @@
   argument, but there is a value for that argument for the
   given \code{Symbol} in the Symbol Lookup Table (see
   \code{\link{setSymbolLookup.FI}}), that value will be
-  used.  Otherwise, if \code{\link[quantmod]{setDefaults}}
+  used.  Otherwise, if \code{\link[Defaults]{setDefaults}}
   has been applied to this function (\code{getSymbols.FI})
   for the argument, the value that was set with
   \code{setDefaults} will be used.  Finally, if none of the



More information about the Blotter-commits mailing list