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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Dec 22 06:08:02 CET 2011


Author: gsee
Date: 2011-12-22 06:08:00 +0100 (Thu, 22 Dec 2011)
New Revision: 882

Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/R/instrument.R
   pkg/FinancialInstrument/R/load.instruments.R
   pkg/FinancialInstrument/man/getSymbols.FI.Rd
   pkg/FinancialInstrument/man/instrument.auto.Rd
Log:
 - add "days_to_omit" arg to getSymbols.FI. If NULL, weekend data will be included
 - if instrument is called with currency=NULL, give less ambiguous error message
 - changed default value for instrument.auto arg default_type from "NULL" to "unknown" 
   to make them findable with ls_instruments_by 



Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2011-12-18 02:51:54 UTC (rev 881)
+++ pkg/FinancialInstrument/DESCRIPTION	2011-12-22 05:08:00 UTC (rev 882)
@@ -11,7 +11,7 @@
     meta-data and relationships. Provides support for
     multi-asset class and multi-currency portfolios. Still
     in heavy development.
-Version: 0.9.13
+Version: 0.9.14
 URL: https://r-forge.r-project.org/projects/blotter/
 Date: $Date$
 Depends:

Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R	2011-12-18 02:51:54 UTC (rev 881)
+++ pkg/FinancialInstrument/R/instrument.R	2011-12-22 05:08:00 UTC (rev 882)
@@ -93,8 +93,8 @@
   if(substr(primary_id,1,1)==1) primary_id <- substr(primary_id,2,nchar(primary_id))
   primary_id<-make.names(primary_id)
   
-  if(missing(currency) || (!missing(currency) && !is.currency(currency)))
-    stop("currency ",currency," must be an object of type 'currency'")
+  if(missing(currency) || is.null(currency) || (!missing(currency) && !is.currency(currency)))
+    stop("currency ",currency," must be defined first")
 
   if(!hasArg(identifiers) || is.null(identifiers)) identifiers = list()
   if(!is.list(identifiers)) {
@@ -723,7 +723,8 @@
 #' getInstrument("VX_H11") #made a future_series
 #' }
 #' @export
-instrument.auto <- function(primary_id, currency=NULL, multiplier=1, silent=FALSE, default_type='NULL', root=NULL, assign_i=TRUE, ...) {
+instrument.auto <- function(primary_id, currency=NULL, multiplier=1, silent=FALSE, 
+                            default_type='unknown', root=NULL, assign_i=TRUE, ...) {
 ##TODO: check formals against dots and remove duplicates from dots before calling constructors to avoid
 # 'formal argument "multiplier" matched by multiple actual arguments'
     if (!is.null(currency) && !is.currency(currency)) {
@@ -845,7 +846,8 @@
     }
     if (!silent && !warned) 
         warning(paste(primary_id, 'is not of an unambiguous format.', 
-                'Creating basic instrument with multiplier 1.'))
+                'Creating _unknown_ instrument with multiplier 1.'))
+    dargs$type <- 'unknown'
     do.call(instrument, dargs)
 }
 

Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R	2011-12-18 02:51:54 UTC (rev 881)
+++ pkg/FinancialInstrument/R/load.instruments.R	2011-12-22 05:08:00 UTC (rev 882)
@@ -2,7 +2,8 @@
 # R (http://r-project.org/) Instrument Class Model
 #
 # Copyright (c) 2009-2011
-# Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan, Joshua Ulrich and Brian G. Peterson
+# Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan, Joshua Ulrich, Brian G. Peterson 
+# and Garrett See
 #
 # This library is distributed under the terms of the GNU Public License (GPL)
 # for full details see the file COPYING
@@ -233,6 +234,9 @@
 #' @param use_identifier optional. identifier used to construct the \code{primary_id} of the instrument. If you use this, you must have previously defined the \code{\link{instrument}} 
 #' @param date_format format as per the \code{\link{strptime}}, see Details
 #' @param verbose TRUE/FALSE
+#' @param days_to_omit character vector of names of weekdays that should not be loaded.  
+#'      Default is \code{c("Saturday", "Sunday")}.  Use \code{NULL} to attempt to load data 
+#'      for all days of the week.
 #' @seealso 
 #' \code{\link{saveSymbols.days}}
 #' \code{\link{instrument}}
@@ -250,11 +254,13 @@
                             split_method = c("days", "common"),
                             use_identifier,
                             date_format=NULL,
-                            verbose=TRUE
+                            verbose=TRUE,
+                            days_to_omit=c("Saturday", "Sunday")
                          ) 
 {
     if (missing(use_identifier)) use_identifier <- NA
     if (is.null(date_format)) date_format <- "%Y.%m.%d"
+    if (is.null(days_to_omit)) days_to_omit <- 'NULL'
     importDefaults("getSymbols.FI")
     this.env <- environment()
     for(var in names(list(...))) {
@@ -286,6 +292,7 @@
     default.use_identifier <- use_identifier
     default.date_format <- date_format
     default.verbose <- verbose
+    default.days_to_omit <- days_to_omit
     # quantmod:::getSymbols will provide auto.assign and env
     # so the next 2 if statements should always be TRUE
     auto.assign <- if(hasArg(auto.assign)) {auto.assign} else TRUE
@@ -310,6 +317,8 @@
         date_format <- ifelse(is.null(date_format), default.date_format, date_format)
         verbose <- getSymbolLookup()[[Symbols[[i]]]]$verbose
         verbose <- ifelse(is.null(verbose), default.verbose, verbose)
+        days_to_omit <- getSymbolLookup()[[Symbols[[i]]]]$days_to_omit
+        days_to_omit <- ifelse(is.null(days_to_omit), default.days_to_omit, days_to_omit)
   
         # if 'dir' is actually the 'base_dir' then we'll paste the instrument name (Symbol) to the end of it.
         # First, find out what the instrument name is
@@ -337,7 +346,7 @@
                         StartDate <- as.Date(from) 
                         EndDate <- as.Date(to) 
                         date.vec <- as.Date(StartDate:EndDate)
-                        date.vec <- date.vec[weekdays(date.vec) != 'Saturday' & weekdays(date.vec) != 'Sunday']
+                        date.vec <- date.vec[!weekdays(date.vec) %in% days_to_omit]  
                         date.vec <- format(date.vec, format=date_format)
                         sym.files <- paste(date.vec, Symbol, extension, sep=".")
                         if (dir != "") sym.files <- file.path(dir, sym.files)

Modified: pkg/FinancialInstrument/man/getSymbols.FI.Rd
===================================================================
--- pkg/FinancialInstrument/man/getSymbols.FI.Rd	2011-12-18 02:51:54 UTC (rev 881)
+++ pkg/FinancialInstrument/man/getSymbols.FI.Rd	2011-12-22 05:08:00 UTC (rev 882)
@@ -5,7 +5,8 @@
   getSymbols.FI(Symbols, from = "2010-01-01",
     to = Sys.Date(), ..., dir = "", return.class = "xts",
     extension = "rda", split_method = c("days", "common"),
-    use_identifier, date_format = NULL, verbose = TRUE)
+    use_identifier, date_format = NULL, verbose = TRUE,
+    days_to_omit = c("Saturday", "Sunday"))
 }
 \arguments{
   \item{Symbols}{a character vector specifying the names of
@@ -39,6 +40,11 @@
   \code{\link{strptime}}, see Details}
 
   \item{verbose}{TRUE/FALSE}
+
+  \item{days_to_omit}{character vector of names of weekdays
+  that should not be loaded.  Default is
+  \code{c("Saturday", "Sunday")}.  Use \code{NULL} to
+  attempt to load data for all days of the week.}
 }
 \description{
   This function should probably get folded back into

Modified: pkg/FinancialInstrument/man/instrument.auto.Rd
===================================================================
--- pkg/FinancialInstrument/man/instrument.auto.Rd	2011-12-18 02:51:54 UTC (rev 881)
+++ pkg/FinancialInstrument/man/instrument.auto.Rd	2011-12-22 05:08:00 UTC (rev 882)
@@ -3,8 +3,9 @@
 \title{Create an instrument based on name alone}
 \usage{
   instrument.auto(primary_id, currency = NULL,
-    multiplier = 1, silent = FALSE, default_type = "NULL",
-    root = NULL, assign_i = TRUE, ...)
+    multiplier = 1, silent = FALSE,
+    default_type = "unknown", root = NULL, assign_i = TRUE,
+    ...)
 }
 \arguments{
   \item{primary_id}{charater primary identifier of



More information about the Blotter-commits mailing list