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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jan 1 20:00:10 CET 2012


Author: gsee
Date: 2012-01-01 20:00:09 +0100 (Sun, 01 Jan 2012)
New Revision: 899

Added:
   pkg/FinancialInstrument/man/is.currency.name.Rd
   pkg/FinancialInstrument/man/is.instrument.name.Rd
Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/NAMESPACE
   pkg/FinancialInstrument/R/MonthCodes.R
   pkg/FinancialInstrument/R/Tick2Sec.R
   pkg/FinancialInstrument/R/buildHierarchy.R
   pkg/FinancialInstrument/R/buildSpread.R
   pkg/FinancialInstrument/R/build_symbols.R
   pkg/FinancialInstrument/R/format_id.R
   pkg/FinancialInstrument/R/instrument.R
   pkg/FinancialInstrument/R/instrument.table.R
   pkg/FinancialInstrument/R/load.instruments.R
   pkg/FinancialInstrument/R/ls_by_currency.R
   pkg/FinancialInstrument/R/ls_by_expiry.R
   pkg/FinancialInstrument/R/ls_expiries.R
   pkg/FinancialInstrument/R/ls_instruments.R
   pkg/FinancialInstrument/R/ls_instruments_by.R
   pkg/FinancialInstrument/R/ls_strikes.R
   pkg/FinancialInstrument/R/ls_underlyings.R
   pkg/FinancialInstrument/R/parse_id.R
   pkg/FinancialInstrument/R/redenominate.R
   pkg/FinancialInstrument/R/saveInstruments.R
   pkg/FinancialInstrument/R/saveSymbols.R
   pkg/FinancialInstrument/R/splice.R
   pkg/FinancialInstrument/R/splooth.R
   pkg/FinancialInstrument/R/synthetic.R
   pkg/FinancialInstrument/R/update_instruments.yahoo.R
   pkg/FinancialInstrument/R/volep.R
   pkg/FinancialInstrument/man/getSymbols.FI.Rd
   pkg/FinancialInstrument/man/is.instrument.Rd
   pkg/FinancialInstrument/man/option_series.yahoo.Rd
   pkg/FinancialInstrument/man/saveInstruments.Rd
Log:
 - Version 0.10.0
 - .instrument now lives inside FinancialInstrument instead of in .GlobalEnv
 - is.currency.name checks to see if string is the name of a currency, while is.currency checks to 
   see if an object is of class currency. (is.instrument and is.instrument.name behave analogously)
 - When calling instrument and instrument_attr with "src" arg, if "verbose" is an item in the
   the list, it will be set in the SymbolLookup and used by getSymbols.FI in spite of any local args.
   It will work best if the user does not attempt to set a default for 'verbose'
   [Please see comments on lines 156-162 of instrument.R as well as the note section of ?getSymbols.FI]
 - Copyright updated to include 2012
 - add svn keywords to newer files that didn't have them (Revision Id Date Author)
 - changed maintainer from Peter Carl to Garrett See


Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/DESCRIPTION	2012-01-01 19:00:09 UTC (rev 899)
@@ -1,6 +1,6 @@
 Copyright: (c) 2004 - 2011
 Package: FinancialInstrument
-Maintainer: Peter Carl <peter at braverock.com>
+Maintainer: Garrett See <gsee000 at gmail.com>
 License: GPL
 Title: Financial Instrument Model Infrastructure for R
 Type: Package
@@ -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.21
+Version: 0.10.0
 URL: https://r-forge.r-project.org/projects/blotter/
 Date: $Date$
 Depends:

Modified: pkg/FinancialInstrument/NAMESPACE
===================================================================
--- pkg/FinancialInstrument/NAMESPACE	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/NAMESPACE	2012-01-01 19:00:09 UTC (rev 899)
@@ -26,7 +26,9 @@
 export(instrument.auto)
 export(instrument.table)
 export(is.currency)
+export(is.currency.name)
 export(is.instrument)
+export(is.instrument.name)
 export(load.instruments)
 export(loadInstruments)
 export(ls_AUD)

Modified: pkg/FinancialInstrument/R/MonthCodes.R
===================================================================
--- pkg/FinancialInstrument/R/MonthCodes.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/MonthCodes.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -1,3 +1,16 @@
+###############################################################################
+# R (http://r-project.org/) Instrument Class Model
+#
+# Copyright (c) 2009-2012
+# 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
+#
+# $Id$
+#
+###############################################################################
 
 #' Month-to-Code and Code-to-Month
 #'


Property changes on: pkg/FinancialInstrument/R/MonthCodes.R
___________________________________________________________________
Added: svn:keywords
   + Revision Id Date Author

Modified: pkg/FinancialInstrument/R/Tick2Sec.R
===================================================================
--- pkg/FinancialInstrument/R/Tick2Sec.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/Tick2Sec.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -1,3 +1,17 @@
+###############################################################################
+# R (http://r-project.org/) Instrument Class Model
+#
+# Copyright (c) 2009-2012
+# 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
+#
+# $Id$
+#
+###############################################################################
+
 #' convert tick data to one-second data
 #'
 #' From tick data with columns: \dQuote{Price}, \dQuote{Volume}, \dQuote{Bid.Price},


Property changes on: pkg/FinancialInstrument/R/Tick2Sec.R
___________________________________________________________________
Added: svn:keywords
   + Revision Id Date Author

Modified: pkg/FinancialInstrument/R/buildHierarchy.R
===================================================================
--- pkg/FinancialInstrument/R/buildHierarchy.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/buildHierarchy.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -1,8 +1,9 @@
 ###############################################################################
 # R (http://r-project.org/) Instrument Class Model
 #
-# Copyright (c) 2009-2011
-# Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan, Joshua Ulrich and Brian G. Peterson
+# Copyright (c) 2009-2012
+# 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

Modified: pkg/FinancialInstrument/R/buildSpread.R
===================================================================
--- pkg/FinancialInstrument/R/buildSpread.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/buildSpread.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -437,7 +437,7 @@
 ###############################################################################
 # R (http://r-project.org/) Instrument Class Model
 #
-# Copyright (c) 2009-2011
+# Copyright (c) 2009-2012
 # Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan, 
 # Joshua Ulrich, Brian G. Peterson, and Garrett See
 #

Modified: pkg/FinancialInstrument/R/build_symbols.R
===================================================================
--- pkg/FinancialInstrument/R/build_symbols.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/build_symbols.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -46,11 +46,11 @@
 #' e.g. '1' for one-month spreads, '1,3' for one and three month spreads,
 #' '1,6,12' for 1, 6, and 12 month spreads, etc.  
 #' For quarterly symbols, the correct \code{contracts_ahead} may be 
-#' something like '1,2,3' for quarterly, bi-annual, and annual spreads.  
+#' something like '1,2,3' for quarterly, bi-annual, and annual spreads.  
 #'
-#' \code{active_months} is a numeric field indicating how many months including  
-#' the month of the \code{start_date} the contract is available to trade.  
-#' This number will be used as the upper limit for symbol generation.
+#' \code{active_months} is a numeric field indicating how many months including  
+#' the month of the \code{start_date} the contract is available to trade.  
+#' This number will be used as the upper limit for symbol generation.
 #'
 #' One of \code{data} or \code{file} must be populated for input data.
 #'
@@ -58,7 +58,7 @@
 #' @param file if not NULL, will read input data from the file named by this argument, in the same folrmat as \code{data}, above
 #' @param outputfile if not NULL, will write out put to this file as a CSV
 #' @param start_date date to start building from, of type \code{Date} or an ISO-8601 date string, defaults to \code{\link{Sys.Date}}
-#' @author Ilya Kipnis <Ilya.Kipnis<at>gmail.com>
+#' @author Ilya Kipnis <Ilya.Kipnis<at>gmail.com>
 #' @seealso
 #' \code{\link{load.instruments}}
 #' \code{\link{build_series_symbols}}
@@ -68,7 +68,7 @@
         if(!is.null(data)) {
                 Data<-data
         } else if(!is.null(file)) {
-                Data<-read.csv(file,header=TRUE,stringsAsFactors=FALSE)
+                Data<-read.csv(file,header=TRUE,stringsAsFactors=FALSE)
         } else {
                 stop("you must either pass a data.frame as the 'data' parameter or pass the 'file' parameter")
         }
@@ -114,9 +114,9 @@
                         newCalMonthLetter<-contractTable[monthIndex,1]
                         newCalYearNumber<-workingContractYearNum+yearsAhead%%10
                         contractName<-makeNameCal(Data$primary_id[i],workingContractMonthLet,workingContractYearNum,newCalMonthLetter,newCalYearNumber)
-                        calRow<-cbind(contractName,dataRow$type[1])
-                        #Other data would be added here.  Take in a row from root contracts, add other details (EG timezone, currency, etc...)
-                        calFrame<-rbind(calFrame,calRow)
+                        calRow<-cbind(contractName,dataRow$type[1])
+                        #Other data would be added here.  Take in a row from root contracts, add other details (EG timezone, currency, etc...)
+                        calFrame<-rbind(calFrame,calRow)
                 }
                 return(calFrame)
         }
@@ -179,7 +179,7 @@
     colnames(contractFrame)<-c("symbol","type")
 
     if(!is.null(outputfile)){
-            write.csv(contractFrame,outputfile) 
+            write.csv(contractFrame,outputfile) 
     } else {
             return(contractFrame)
     }
@@ -188,13 +188,14 @@
 ###############################################################################
 # R (http://r-project.org/) Instrument Class Model
 #
-# Copyright (c) 2009-2011
-# Peter Carl, Lance Levenson, Brian G. Peterson
+# Copyright (c) 2009-2012
+# Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan, 
+# Joshua Ulrich, Brian G. Peterson, and Garrett See
 #
 # This code is distributed under the terms of the GNU Public License (GPL)
 # for full details see the file COPYING
 #
-# $Id$
+# $Id$
 #
 ###############################################################################
-
+


Property changes on: pkg/FinancialInstrument/R/build_symbols.R
___________________________________________________________________
Modified: svn:keywords
   - Id Revision Date Author
   + Revision Id Date Author

Modified: pkg/FinancialInstrument/R/format_id.R
===================================================================
--- pkg/FinancialInstrument/R/format_id.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/format_id.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -1,3 +1,16 @@
+###############################################################################
+# R (http://r-project.org/) Instrument Class Model
+#
+# Copyright (c) 2009-2012
+# 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
+#
+# $Id$
+#
+###############################################################################
 
 #' format an id
 #' 


Property changes on: pkg/FinancialInstrument/R/format_id.R
___________________________________________________________________
Added: svn:keywords
   + Revision Id Date Author

Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/instrument.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -1,7 +1,7 @@
 ###############################################################################
 # R (http://r-project.org/) Instrument Class Model
 #
-# Copyright (c) 2009-2011
+# Copyright (c) 2009-2012
 # Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan, 
 # Joshua Ulrich, Brian G. Peterson, and Garrett See
 #
@@ -12,18 +12,49 @@
 #
 ###############################################################################
 
-.onLoad <- function(lib, pkg) {
-    if(!exists('.instrument'))
-        .instrument <<- new.env(hash=TRUE)
-}
+#.onLoad <- function(lib, pkg) {
+#    if(!exists('.instrument'))
+#        .instrument <<- new.env(hash=TRUE)
+#}
 
+.instrument <- new.env(parent=emptyenv())
+
+
 #' class test for object supposedly of type 'instrument'
-#' @param x object or primary_id of instrument to test for type
+#' @param x object to test for type
 #' @export
 is.instrument <- function( x ) {
   inherits( x, "instrument" )
 }
 
+
+#' test to see if a string is the name of a \code{\link{instrument}}
+#' @param x object
+#' @export
+is.instrument.name <- function(x) {
+  x <- suppressWarnings(getInstrument(x, silent=TRUE))
+  inherits(x, 'instrument')
+}
+
+
+#' class test for object supposedly of type 'currency'
+#' @param x object to test for type
+#' @export
+is.currency <- function( x ) {
+#  x<-getInstrument(x, silent=TRUE) # Please use is.currency.name if x is character
+  inherits( x, "currency" )
+}
+
+
+#' test to see if a string is the name of a \code{\link{currency}}
+#' @param x character string to test.
+#' @export
+is.currency.name <- function( x ) {
+  x <- suppressWarnings(getInstrument(x, type='currency', silent=TRUE))
+  inherits( x, "currency" )
+}
+
+
 #' instrument class constructors
 #' 
 #' All 'currency' instruments must be defined before instruments of other types may be defined.
@@ -93,7 +124,7 @@
   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) || is.null(currency) || (!missing(currency) && !is.currency(currency)))
+  if(missing(currency) || is.null(currency) || (!missing(currency) && !is.currency.name(currency)))
     stop("currency ",currency," must be defined first")
 
   if(!hasArg(identifiers) || is.null(identifiers)) identifiers = list()
@@ -115,16 +146,28 @@
       }
   }
   if (!is.null(arg$src)) {
-      # Clear out anything stored in SymbolLookupTable
+      # Clear out anything stored in SymbolLookupTable for this instrument
       eval(parse(text=paste('setSymbolLookup(', primary_id, '=', 'NULL', ')', sep="")))
 
       sarg <- list()
       if (length(arg$src) == 1) {
           sarg[[primary_id]] <- arg$src
       }  else {
-          sarg[[primary_id]] <- arg$src$src
+          #FIXME: @quantmod developers: getSymbols should not have a "verbose" argument.
+          # The 'verbose' arg belongs in the methods because the user may want to verbose=TRUE
+          # for some getSymbols methods, but verbose=FALSE for other ones. For now, I will
+          # store the "verbose" value in the SymbolLookup table so that the user can set different
+          # defaults for different methods, but that means that local args will be ignored.
+          # i.e. if you call stock("SPY", currency("USD"), src=list(src='FI', verbose=TRUE)), then
+          # if you call getSymbols("SPY", verbose=FALSE), it will use verbose=TRUE.
+          sarg[[primary_id]] <- if (is.null(arg$src$verbose)) {
+              arg$src$src
+          } else {
+              arg$src[c('src', 'verbose')]
+          }
           tmparg <- arg
           tmparg$src$src <- NULL
+          #tmparg$src$verbose <- NULL #make NULL if we decide to only use verbose arg of getSymbols
           do.call(setDefaults, c("getSymbols.FI", tmparg$src))
       }
       setSymbolLookup(sarg)
@@ -158,7 +201,7 @@
   class(tmpinstr)<-tclass
   
   if(assign_i)  {
-      assign(primary_id, tmpinstr, envir=as.environment(.instrument) )
+      assign(primary_id, tmpinstr, envir=as.environment(FinancialInstrument:::.instrument) )
       return(primary_id)  
   } else return(tmpinstr) 
 }
@@ -195,7 +238,7 @@
     if(is.null(underlying_id)) {
         warning("underlying_id should only be NULL for cash-settled futures")
     } else {
-        if(!exists(underlying_id, where=.instrument,inherits=TRUE)) warning("underlying_id not found") # assumes that we know where to look
+        if(!exists(underlying_id, where=FinancialInstrument:::.instrument,inherits=TRUE)) warning("underlying_id not found") # assumes that we know where to look
         if (primary_id == underlying_id) {
             primary_id <- paste("..",primary_id,sep="")
             warning(paste('primary_id is the same as underlying_id,',
@@ -304,7 +347,7 @@
       message("updating existing first_traded and expires for ",primary_id)
       temp_series$first_traded<-unique(c(temp_series$first_traded,first_traded))
       temp_series$expires<-unique(c(temp_series$expires,expires))
-      assign(primary_id, temp_series, envir=as.environment(.instrument))
+      assign(primary_id, temp_series, envir=as.environment(FinancialInstrument:::.instrument))
       primary_id
   } else {
       args <- list()
@@ -359,7 +402,7 @@
   if(is.null(underlying_id)) {
       warning("underlying_id should only be NULL for cash-settled options")
   } else {
-      if(!exists(underlying_id, where=.instrument,inherits=TRUE)) warning("underlying_id not found") # assumes that we know where to look
+      if(!exists(underlying_id, where=FinancialInstrument:::.instrument,inherits=TRUE)) warning("underlying_id not found") # assumes that we know where to look
       if (primary_id == underlying_id) {
           primary_id <- paste(".",primary_id,sep="")
           warning(paste('primary_id is the same as underlying_id,',
@@ -430,7 +473,7 @@
         message("updating existing first_traded and expires for ", primary_id)
         temp_series$first_traded<-unique(c(temp_series$first_traded,first_traded))
         temp_series$expires<-unique(c(temp_series$expires,expires))
-        assign(primary_id, temp_series, envir=as.environment(.instrument))
+        assign(primary_id, temp_series, envir=as.environment(FinancialInstrument:::.instrument))
         primary_id
     } else {
         dargs <- list(...)
@@ -480,7 +523,7 @@
 #' \dontrun{
 #' option_series.yahoo('SPY') #only nearby calls and puts
 #' option_series.yahoo('DIA', Exp=NULL) #all chains
-#' ls(.instrument, all.names=TRUE)
+#' ls_instruments()
 #' }
 #' @export
 option_series.yahoo <- function(symbol, Exp, currency="USD", multiplier=100, first_traded=NULL, tick_size=NULL) {
@@ -576,20 +619,12 @@
     }        
     class(ccy)<-c("currency","instrument")
     if (assign_i) {
-        assign(primary_id, ccy, pos=as.environment(.instrument) )
+        assign(primary_id, ccy, pos=as.environment(FinancialInstrument:::.instrument) )
         return(primary_id)
     }
     ccy
 }
 
-#' class test for object supposedly of type 'currency'
-#' @param x object to test for type
-#' @export
-is.currency <- function( x ) {
-#FIXME: This should not get instrument, but it will break everyone's code if I change it. -Garrett
-  x<-getInstrument(x, silent=TRUE)
-  inherits( x, "currency" )
-}
 
 #' constructor for spot exchange rate instruments
 #' 
@@ -623,8 +658,8 @@
   
   if (is.null(currency)) currency <- substr(primary_id,4,6)
   if (is.null(counter_currency)) counter_currency <- substr(primary_id,1,3)
-  if(!exists(currency, where=.instrument,inherits=TRUE)) warning(paste("currency",currency,"not found")) # assumes that we know where to look
-  if(!exists(counter_currency, where=.instrument,inherits=TRUE)) warning(paste("counter_currency",counter_currency,"not found")) # assumes that we know where to look
+  if(!exists(currency, where=FinancialInstrument:::.instrument,inherits=TRUE)) warning(paste("currency",currency,"not found")) # assumes that we know where to look
+  if(!exists(counter_currency, where=FinancialInstrument:::.instrument,inherits=TRUE)) warning(paste("counter_currency",counter_currency,"not found")) # assumes that we know where to look
 
   ## now structure and return
   instrument(primary_id=primary_id , currency=currency , multiplier=1 , tick_size=.01, identifiers = identifiers, ..., counter_currency=counter_currency, type=c("exchange_rate","currency"), assign_i=assign_i)
@@ -656,7 +691,7 @@
         message("updating existing first_traded and maturity for ",id)
         temp_series$first_traded<-c(temp_series$first_traded,first_traded)
         temp_series$maturity<-c(temp_series$maturity,maturity)
-        assign(id, temp_series, envir=as.environment(.instrument))
+        assign(id, temp_series, envir=as.environment(FinancialInstrument:::.instrument))
     } else {
         dargs<-list(...)
         dargs$currency=NULL
@@ -737,7 +772,7 @@
                             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)) {
+    if (!is.null(currency) && !is.currency.name(currency)) {
         if (nchar(currency) != 3 || currency != toupper(currency))
             stop(paste(currency, "is not defined,",
                 "and it will not be auto defined because it does not appear to be valid."))
@@ -918,12 +953,12 @@
 #' @export
 #' @rdname getInstrument
 getInstrument <- function(x, Dates=NULL, silent=FALSE, type='instrument'){
-    tmp_instr <- try(get(x,pos=.instrument),silent=TRUE) #removed inherits=TRUE
+    tmp_instr <- try(get(x,pos=FinancialInstrument:::.instrument),silent=TRUE) #removed inherits=TRUE
     if(inherits(tmp_instr,"try-error") || !inherits(tmp_instr, type)){
         #first search
-        instr_list <- ls(pos=.instrument, all.names=TRUE)
+        instr_list <- ls(pos=FinancialInstrument:::.instrument, all.names=TRUE)
         for (instr in instr_list){
-            tmp_instr <- try(get(instr, pos=.instrument), silent=TRUE)
+            tmp_instr <- try(get(instr, pos=FinancialInstrument:::.instrument), silent=TRUE)
             if(inherits(tmp_instr, type) && (x %in% tmp_instr$identifiers || x %in% make.names(tmp_instr$identifiers))) {
                 return(tmp_instr)
             }
@@ -931,11 +966,11 @@
         #If not found, see if it begins with dots (future or option root)
         #strip out the dots and add them back 1 at a time to the beginning of id
         x <- gsub("\\.", "", x) 
-        tmp_instr<-try(get(x,pos=.instrument),silent=TRUE)
+        tmp_instr<-try(get(x,pos=FinancialInstrument:::.instrument),silent=TRUE)
         if(!inherits(tmp_instr,type)) {
-            tmp_instr<-try(get(paste(".",x,sep=""),pos=.instrument),silent=TRUE)
+            tmp_instr<-try(get(paste(".",x,sep=""),pos=FinancialInstrument:::.instrument),silent=TRUE)
             if(!inherits(tmp_instr,type)) {
-                tmp_instr<-try(get(paste("..",x,sep=""),pos=.instrument),silent=TRUE)
+                tmp_instr<-try(get(paste("..",x,sep=""),pos=FinancialInstrument:::.instrument),silent=TRUE)
             }
         }
         if (!inherits(tmp_instr,'try-error') && inherits(tmp_instr, type)) return(tmp_instr)
@@ -990,7 +1025,7 @@
     if (inherits(instr, 'try-error') || !is.instrument(instr))
         stop(paste('instrument ',primary_id,' must be defined first.',sep=''))
     instr[[attr]] <- value
-    if (attr == 'primary_id') rm(list = primary_id, pos = .instrument)
+    if (attr == 'primary_id') rm(list = primary_id, pos = FinancialInstrument:::.instrument)
     if (attr == 'currency' && !is.instrument(getInstrument(value,type='currency',silent=TRUE)))
         stop("currency ", value, " must be an object of type 'currency'")
     if (attr == 'multiplier' && (!is.numeric(value) || length(value) > 1))
@@ -1012,20 +1047,31 @@
     if (attr == 'src') {
       # Clear out anything stored in SymbolLookupTable
       eval(parse(text=paste('setSymbolLookup(', primary_id, '=', 'NULL', ')', sep="")))
-
       sarg <- list()
       if (length(value) == 1) {
           sarg[[primary_id]] <- value
       }  else {
-          sarg[[primary_id]] <- value$src
+          #FIXME: @quantmod developers: getSymbols should not have a "verbose" argument.
+          # The 'verbose' arg belongs in the methods because the user may want to verbose=TRUE
+          # for some getSymbols methods, but verbose=FALSE for other ones. For now, I will
+          # store the "verbose" value in the SymbolLookup table so that the user can set different
+          # defaults for different methods, but that means that local args will be ignored.
+          # i.e. if you call instrument_attr("SPY", "src", list(src='FI', verbose=TRUE)), then
+          # if you call getSymbols("SPY", verbose=FALSE), it will use verbose=TRUE.
+          sarg[[primary_id]] <- if (is.null(value$verbose)) {
+              value$src
+          } else {
+              value[c('src', 'verbose')]
+          }
           value$src <- NULL
+          #value$verbose <- NULL
           do.call(setDefaults, c("getSymbols.FI", value))
       }
       setSymbolLookup(sarg)
       #arg[["src"]]<-NULL
   }
 
-    assign(instr$primary_id, instr, pos=.instrument)
+    assign(instr$primary_id, instr, pos=FinancialInstrument:::.instrument)
 }
 
 #' instrument class print method


Property changes on: pkg/FinancialInstrument/R/instrument.R
___________________________________________________________________
Modified: svn:keywords
   - Id Revision Date Author
   + Revision Id Date Author

Modified: pkg/FinancialInstrument/R/instrument.table.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.table.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/instrument.table.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -1,3 +1,17 @@
+###############################################################################
+# R (http://r-project.org/) Instrument Class Model
+#
+# Copyright (c) 2009-2012
+# 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
+#
+# $Id$
+#
+###############################################################################
+
 #' Create data.frame with attributes of all instruments
 #' 
 #' A wrapper for \code{\link{buildHierarchy}}, that defaults to returning all attributes.


Property changes on: pkg/FinancialInstrument/R/instrument.table.R
___________________________________________________________________
Added: svn:keywords
   + Revision Id Date Author

Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/load.instruments.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -1,9 +1,9 @@
 ###############################################################################
 # R (http://r-project.org/) Instrument Class Model
 #
-# Copyright (c) 2009-2011
-# Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan, Joshua Ulrich, Brian G. Peterson 
-# and Garrett See
+# Copyright (c) 2009-2012
+# 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
@@ -82,7 +82,7 @@
             dotargs$type <- NULL        
         }
     }
-    if (!is.null(dotargs$currency) && !is.currency(dotargs$currency)) currency(dotargs$currency)
+    if (!is.null(dotargs$currency) && !is.currency.name(dotargs$currency)) currency(dotargs$currency)
     
     #now process the data
     for(rn in 1:nrow(filedata)){
@@ -171,7 +171,7 @@
 
     #load all instrument names
     instr_names <- if(missing(Symbols)) {
-        ls_non_currencies(ls(pos=.instrument)) #if roots begin with a dot, this will filter out roots and currencies
+        ls_non_currencies(ls(pos=FinancialInstrument:::.instrument)) #if roots begin with a dot, this will filter out roots and currencies
     } else Symbols
     
     #TODO add check to make sure that src is actually the name of a getSymbols function
@@ -259,6 +259,11 @@
 #' However, if you were to call \code{getSymbols.FI} directly (which is \emph{NOT} recommended) 
 #' with \code{auto.assign=FALSE} and more than one Symbol, a list would be returned.
 #' 
+#' @note getSymbols and getSymbols.FI both have a \code{verbose} argument.  If a value has been
+#' set for \code{verbose} in the SymbolLookup table, it will be used in spite of any local args.
+#' If you want to change it, you will have to change it with a call to \code{instrument_attr} 
+#' or \code{setSymbolLookup}.  If you call either of those with \code{verbose=NULL}, the \code{verbose}
+#' arg will be unset and local arguments will again be respected.
 #' @param Symbols a character vector specifying the names of each symbol to be loaded
 #' @param from Retrieve data no earlier than this date. Default '2010-01-01'.
 #' @param to Retrieve data through this date. Default Sys.Date().

Modified: pkg/FinancialInstrument/R/ls_by_currency.R
===================================================================
--- pkg/FinancialInstrument/R/ls_by_currency.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/ls_by_currency.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -1,3 +1,17 @@
+###############################################################################
+# R (http://r-project.org/) Instrument Class Model
+#
+# Copyright (c) 2009-2012
+# 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
+#
+# $Id$
+#
+###############################################################################
+
 #' shows or removes instruments of given currency denomination(s)
 #' 
 #' ls_ functions get names of instruments denominated in a given currency (or
@@ -57,17 +71,17 @@
 	}
 
     if (!is.null(pattern) && match) {   #there's a pattern and match is TRUE
-        symbols <- ls(.instrument, all.names=TRUE)
+        symbols <- ls_instruments()
         symbols <- symbols[match(pattern,symbols)]
     } else if (!match && length(pattern) == 1) { # pattern is length(1) and match is FALSE
-        symbols <- ls(.instrument, all.names=TRUE, pattern=pattern)
+        symbols <- ls_instruments(pattern=pattern)
     } else if (is.null(pattern)) {  #no pattern
-        symbols <- ls(.instrument, all.names=TRUE)
+        symbols <- ls_instruments()
     } # else pattern length > 1 & don't match
         
     tmp_symbols <- NULL            
     for (symbol in symbols) {
-        tmp_instr <- try(get(symbol, pos = .instrument),silent=TRUE)
+        tmp_instr <- try(get(symbol, pos = FinancialInstrument:::.instrument),silent=TRUE)
         if (is.instrument(tmp_instr) && 
           tmp_instr$currency == currency ){    
             tmp_symbols <- c(tmp_symbols,symbol)
@@ -87,7 +101,7 @@
     if (missing(x)) {
         x <- ls_by_currency(currency,show.currencies=sc)
     } else x <- ls_by_currency(currency,pattern=x,show.currencies=sc)
-    rm(list=x,pos=.instrument)
+    rm(list=x,pos=FinancialInstrument:::.instrument)
 }
 
 #AUD GBP CAD EUR JPY CHF HKD SEK NZD


Property changes on: pkg/FinancialInstrument/R/ls_by_currency.R
___________________________________________________________________
Added: svn:keywords
   + Revision Id Date Author

Modified: pkg/FinancialInstrument/R/ls_by_expiry.R
===================================================================
--- pkg/FinancialInstrument/R/ls_by_expiry.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/ls_by_expiry.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -1,3 +1,17 @@
+###############################################################################
+# R (http://r-project.org/) Instrument Class Model
+#
+# Copyright (c) 2009-2012
+# 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
+#
+# $Id$
+#
+###############################################################################
+
 #' list or remove instruments by expiration date
 #' 
 #' show names of or remove instruments that expire on a given date
@@ -36,18 +50,18 @@
     }    
 
     if (!is.null(pattern) && match) {   #there's a pattern and match is TRUE
-        symbols <- ls(.instrument, all.names=TRUE)
+        symbols <- ls_instruments()
         symbols <- symbols[match(pattern,symbols)]
     } else if (!match && length(pattern) == 1) { # pattern is length(1) and match is FALSE
-        symbols <- ls(.instrument, all.names=TRUE, pattern=pattern)
+        symbols <- ls_instruments(pattern=pattern)
     } else if (is.null(pattern)) {  #no pattern
-        symbols <- ls(.instrument, all.names=TRUE)
+        symbols <- ls_instruments()
     } # else pattern length > 1 & don't match
 
     expiry <- gsub("-", "", expiry)
     tmp_symbols <- NULL            
     for (symbol in symbols) {
-        tmp_instr <- try(get(symbol, pos = .instrument),silent=TRUE)
+        tmp_instr <- try(get(symbol, pos = FinancialInstrument:::.instrument),silent=TRUE)
         if (is.instrument(tmp_instr) ) {
             if ((!is.null(tmp_instr$expires) && any(gsub("-", "", tmp_instr$expires) == expiry)) ||
                 (!is.null(tmp_instr$expiry) && any(gsub("-", "", tmp_instr$expiry) == expiry)) ) {
@@ -64,7 +78,7 @@
     if (missing(x)) {
         x <- ls_by_expiry(expiry)
     } else x <- ls_by_expiry(expiry,pattern=x)
-    rm(list=x,pos=.instrument)
+    rm(list=x,pos=FinancialInstrument:::.instrument)
 }
 #rm_by_expiry(ls_options(),'20130119')
 


Property changes on: pkg/FinancialInstrument/R/ls_by_expiry.R
___________________________________________________________________
Added: svn:keywords
   + Revision Id Date Author

Modified: pkg/FinancialInstrument/R/ls_expiries.R
===================================================================
--- pkg/FinancialInstrument/R/ls_expiries.R	2011-12-30 17:16:06 UTC (rev 898)
+++ pkg/FinancialInstrument/R/ls_expiries.R	2012-01-01 19:00:09 UTC (rev 899)
@@ -1,3 +1,18 @@
+###############################################################################
+# R (http://r-project.org/) Instrument Class Model
+#
+# Copyright (c) 2009-2012
+# 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
+#
+# $Id$
+#
+###############################################################################
+
+
 #' show unique expiration dates of instruments
 #' 
 #' show unique expiration dates of instruments
@@ -41,7 +56,7 @@
     dates <- NULL   
     underlyings <- NULL
     for (symbol in symbols) { 
-        tmp_instr <- try(get(symbol,pos=.instrument),silent=TRUE)
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/blotter -r 899


More information about the Blotter-commits mailing list