[Blotter-commits] r734 - in pkg/FinancialInstrument: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Aug 22 23:32:10 CEST 2011
Author: gsee
Date: 2011-08-22 23:32:09 +0200 (Mon, 22 Aug 2011)
New Revision: 734
Modified:
pkg/FinancialInstrument/R/load.instruments.R
pkg/FinancialInstrument/man/getSymbols.FI.Rd
Log:
getSymbols.FI can now be called without first calling setSymbolLookup.FI
Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R 2011-08-21 11:59:22 UTC (rev 733)
+++ pkg/FinancialInstrument/R/load.instruments.R 2011-08-22 21:32:09 UTC (rev 734)
@@ -208,6 +208,8 @@
#' @param dir if not specified in getSymbolLookup, directory string to use. default ""
#' @param return.class only "xts" is currently supported
#' @param extension file extension, default "rda"
+#' @param split_method string specifying the method used to split the files, currently \sQuote{days} or \sQuote{common}, see \code{\link{setSymbolLookup.FI}}
+#' @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 auto.assign TRUE/FALSE
@@ -226,6 +228,8 @@
dir="",
return.class="xts",
extension="rda",
+ split_method = c("days", "common"),
+ use_identifier,
date_format=NULL,
verbose=TRUE,
auto.assign=TRUE
@@ -241,12 +245,30 @@
default.return.class <- return.class
default.dir <- dir
default.extension <- extension
+ default.split_method <- split_method
for(i in 1:length(Symbols)) {
return.class <- getSymbolLookup()[[Symbols[[i]]]]$return.class
return.class <- ifelse(is.null(return.class),default.return.class, return.class)
dir <- getSymbolLookup()[[Symbols[[i]]]]$dir
dir <- ifelse(is.null(dir),default.dir, dir)
+ #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
+ instr_str <- NA
+ if(!missing(use_identifier)) {
+ tmp_instr <- try(getInstrument(Symbols[[i]], silent=FALSE))
+ if (inherits(tmp_instr,'try-error') || !is.instrument(tmp_instr))
+ stop("must define instrument first to call with 'use_identifier'")
+ if (!use_identifier=='primary_id') {
+ instr_str<-make.names(tmp_instr$identifiers[[use_identifier]])
+ } else instr_str <- make.names(tmp_instr[[use_identifier]])
+ }
+ symbol <- ifelse(is.na(instr_str), make.names(Symbols[[i]]), instr_str)
+ ndc<-nchar(dir)
+ if(substr(dir,ndc,ndc)=='/') dir <- substr(dir,1,ndc-1) #remove trailing forward slash
+ ssd <- strsplit(dir,"/")[[1]]
+ if (ssd[length(ssd)] != symbol) dir <- paste(dir,symbol,sep="/")
+
if(!dir=="" && !file.exists(dir)) {
cat("\ndirectory ",dir," does not exist, skipping\n")
next
@@ -254,7 +276,10 @@
extension <- getSymbolLookup()[[Symbols[[i]]]]$extension
extension <- ifelse(is.null(extension),default.extension, extension)
if(verbose) cat("loading ",Symbols[[i]],".....")
- switch(getSymbolLookup()[[Symbols[[i]]]]$split_method,
+ split_method <- getSymbolLookup()[[Symbols[[i]]]]$split_method
+ split_method <- ifelse(is.null(split_method), default.split_method, split_method)
+
+ switch(split_method,
days={
fr<-NULL
StartDate <- as.Date(from)
Modified: pkg/FinancialInstrument/man/getSymbols.FI.Rd
===================================================================
--- pkg/FinancialInstrument/man/getSymbols.FI.Rd 2011-08-21 11:59:22 UTC (rev 733)
+++ pkg/FinancialInstrument/man/getSymbols.FI.Rd 2011-08-22 21:32:09 UTC (rev 734)
@@ -4,7 +4,8 @@
\usage{
getSymbols.FI(Symbols, from = "2010-01-01", to =
Sys.Date(), ..., env, dir = "", return.class = "xts",
- extension = "rda", date_format = NULL, verbose = TRUE,
+ extension = "rda", split_method = c("days", "common"),
+ use_identifier, date_format = NULL, verbose = TRUE,
auto.assign = TRUE)
}
\arguments{
@@ -28,6 +29,15 @@
\item{extension}{file extension, default "rda"}
+ \item{split_method}{string specifying the method used to
+ split the files, currently \sQuote{days} or
+ \sQuote{common}, see \code{\link{setSymbolLookup.FI}}}
+
+ \item{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}}}
+
\item{date_format}{format as per the
\code{\link{strptime}}, see Details}
More information about the Blotter-commits
mailing list