[Blotter-commits] r896 - in pkg/FinancialInstrument: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Dec 30 07:53:22 CET 2011
Author: gsee
Date: 2011-12-30 07:53:21 +0100 (Fri, 30 Dec 2011)
New Revision: 896
Modified:
pkg/FinancialInstrument/DESCRIPTION
pkg/FinancialInstrument/R/buildSpread.R
pkg/FinancialInstrument/R/instrument.R
pkg/FinancialInstrument/R/load.instruments.R
pkg/FinancialInstrument/man/instrument_attr.Rd
Log:
- reallow using multi-currency buildSpread for multi-column exchange_rate data
- when instrument or instrument_attr are called with src arg, use setSymbolLookup on only the src, and setDefaults on the remaining items.
- add unexported setSymbolLookup.FI2 function; a possible replacement for setSymbolLookup.FI
Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION 2011-12-27 19:25:29 UTC (rev 895)
+++ pkg/FinancialInstrument/DESCRIPTION 2011-12-30 06:53:21 UTC (rev 896)
@@ -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.20
+Version: 0.9.21
URL: https://r-forge.r-project.org/projects/blotter/
Date: $Date$
Depends:
Modified: pkg/FinancialInstrument/R/buildSpread.R
===================================================================
--- pkg/FinancialInstrument/R/buildSpread.R 2011-12-27 19:25:29 UTC (rev 895)
+++ pkg/FinancialInstrument/R/buildSpread.R 2011-12-30 06:53:21 UTC (rev 896)
@@ -107,6 +107,7 @@
if (!is.logical(instr_prices) || ncol(instr_prices) > 1) instr_prices <- getPrice(instr_prices,prefer=pref)
if (instr$currency != spread_currency)
instr_prices <- redenominate(instr_prices,spread_currency,instr$currency)
+ if (NCOL(instr_prices) > 1) instr_prices <- getPrice(instr_prices, prefer=pref)
instr_norm <- instr_prices * instr_mult * instr_ratio
colnames(instr_norm) <- paste(as.character(spread_instr$members[i]),
prefer, sep = ".")
Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R 2011-12-27 19:25:29 UTC (rev 895)
+++ pkg/FinancialInstrument/R/instrument.R 2011-12-30 06:53:21 UTC (rev 896)
@@ -115,8 +115,18 @@
}
}
if (!is.null(arg$src)) {
+ # Clear out anything stored in SymbolLookupTable
+ eval(parse(text=paste('setSymbolLookup(', primary_id, '=', 'NULL', ')', sep="")))
+
sarg <- list()
- sarg[[primary_id]] <- arg$src
+ if (length(arg$src) == 1) {
+ sarg[[primary_id]] <- arg$src
+ } else {
+ sarg[[primary_id]] <- arg$src$src
+ tmparg <- arg
+ tmparg$src$src <- NULL
+ do.call(setDefaults, c("getSymbols.FI", tmparg$src))
+ }
setSymbolLookup(sarg)
#arg[["src"]]<-NULL
}
@@ -945,7 +955,9 @@
#' If the \code{attr} you are trying to change is the \dQuote{primary_id,} the instrument will be renamed.
#' (A copy of the instrument will be stored by the name of \code{value} and the old instrument will be removed.)
#' If the \code{attr} you are changing is \dQuote{type}, the instrument will be reclassed with that type.
-#' If \code{attr} is \dQuote{src}, \code{value} will be used in a call to \code{setSymbolLookup}.
+#' If \code{attr} is \dQuote{src}, \code{value} will be used in a call to \code{setSymbolLookup}. If \dQuote{src}
+#' is a list with more than 1 item, \code{setSymbolLookup} will be called with the item named \sQuote{src}, and
+#' the remaining items will be passed used in a call to \code{setDefaults} along with \code{.name='getSymbols.FI'}
#' Other checks are in place to make sure that \dQuote{currency} remains a \code{\link{currency}} object and that
#' \dQuote{multiplier} and \dQuote{tick_size} can only be changed to reasonable values.
#' @param primary_id primary_id of the instrument that will be updated
@@ -998,10 +1010,21 @@
}
}
if (attr == 'src') {
- sarg <- list()
- sarg[[instr$primary_id]] <- value
- setSymbolLookup(sarg)
- }
+ # 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
+ value$src <- NULL
+ do.call(setDefaults, c("getSymbols.FI", value))
+ }
+ setSymbolLookup(sarg)
+ #arg[["src"]]<-NULL
+ }
+
assign(instr$primary_id, instr, pos=.instrument)
}
Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R 2011-12-27 19:25:29 UTC (rev 895)
+++ pkg/FinancialInstrument/R/load.instruments.R 2011-12-30 06:53:21 UTC (rev 896)
@@ -207,6 +207,42 @@
setSymbolLookup(new.symbols)
}
+
+setSymbolLookup.FI2 <- function (Symbols, dir, from = "2010-01-01", to = Sys.Date(),
+ return.class = "xts", extension = "rda", split_method = c("days", "common"),
+ use_identifier = "primary_id", date_format = NULL, verbose = TRUE,
+ days_to_omit = c("Saturday", "Sunday"))
+{
+ # check that base_dir exists
+ if(!file.exists(dir)) stop('dir ', dir, ' does not seem to specify a valid path' )
+
+ # take split
+ split_method<-split_method[1] # only use the first value
+
+ #load all instrument names
+ Symbols <- if(missing(Symbols)) {
+ ls_non_currencies(ls(pos=.instrument)) #if roots begin with a dot, this will filter out roots and currencies
+ } else Symbols
+
+ args <- list(
+ src="FI",
+ dir=dir,
+ from=from,
+ to=to,
+ return.class=return.class,
+ extension=extension,
+ split_method=split_method,
+ use_identifier=use_identifier,
+ date_format=date_format,
+ verbose=verbose,
+ days_to_omit=days_to_omit)
+
+ for (s in Symbols) {
+ instrument_attr(s, "src", args)
+ }
+}
+
+
#' getSymbols method for loading data from split files
#'
#' This function should probably get folded back into getSymbols.rda in quantmod.
Modified: pkg/FinancialInstrument/man/instrument_attr.Rd
===================================================================
--- pkg/FinancialInstrument/man/instrument_attr.Rd 2011-12-27 19:25:29 UTC (rev 895)
+++ pkg/FinancialInstrument/man/instrument_attr.Rd 2011-12-30 06:53:21 UTC (rev 896)
@@ -29,8 +29,13 @@
the \code{attr} you are changing is \dQuote{type}, the
instrument will be reclassed with that type. If
\code{attr} is \dQuote{src}, \code{value} will be used in
- a call to \code{setSymbolLookup}. Other checks are in
- place to make sure that \dQuote{currency} remains a
+ a call to \code{setSymbolLookup}. If \dQuote{src} is a
+ list with more than 1 item, \code{setSymbolLookup} will
+ be called with the item named \sQuote{src}, and the
+ remaining items will be passed used in a call to
+ \code{setDefaults} along with
+ \code{.name='getSymbols.FI'} Other checks are in place to
+ make sure that \dQuote{currency} remains a
\code{\link{currency}} object and that
\dQuote{multiplier} and \dQuote{tick_size} can only be
changed to reasonable values.
More information about the Blotter-commits
mailing list