[Blotter-commits] r791 - in pkg/FinancialInstrument: . R man sandbox
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Sep 26 01:22:11 CEST 2011
Author: gsee
Date: 2011-09-26 01:22:11 +0200 (Mon, 26 Sep 2011)
New Revision: 791
Modified:
pkg/FinancialInstrument/DESCRIPTION
pkg/FinancialInstrument/R/instrument.R
pkg/FinancialInstrument/man/instrument.auto.Rd
pkg/FinancialInstrument/man/load.instruments.Rd
pkg/FinancialInstrument/sandbox/ISO.currencies.wiki.R
Log:
- instrument.auto will make exchange_rate if id is 6 uppercase letters unless default_type is given
- update docs
- copy/paste error in future_series
- add defined.by 'slot' to currency defined with sandbox fun define_currencies.wiki
Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION 2011-09-25 18:26:39 UTC (rev 790)
+++ pkg/FinancialInstrument/DESCRIPTION 2011-09-25 23:22:11 UTC (rev 791)
@@ -11,7 +11,7 @@
meta-data and relationships. Provides support for
multi-asset class and multi-currency portfolios.
Still in heavy development.
-Version: 0.6.5
+Version: 0.6.6
URL: https://r-forge.r-project.org/projects/blotter/
Date: $Date$
Depends:
Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R 2011-09-25 18:26:39 UTC (rev 790)
+++ pkg/FinancialInstrument/R/instrument.R 2011-09-25 23:22:11 UTC (rev 791)
@@ -269,8 +269,8 @@
} else if (is.null(suffix_id) && parse_id(primary_id)$type == 'root') {
#primary_id is actually a root_id, and suffix_id is NULL. we need to build suffix_id
#using expires so that we can build a new primary_id. Call recursively to handle this.
- return(option_series(root_id=primary_id, first_traded=first_traded, expires=expires,
- callput=callput, strike=strike, identifiers=identifiers, ...=...))
+ return(future_series(root_id=primary_id, first_traded=first_traded, expires=expires,
+ identifiers=identifiers, ...=...))
}
pid <- parse_id(primary_id)
@@ -639,7 +639,12 @@
#'
#' @note If \code{currency} is not already defined, it will be defined (unless it is not 3 uppercase characters).
#' The default value for \code{currency} is \dQuote{USD}. If you do not provide a value for \code{currency},
-#' \dQuote{USD} will be defined and used to create the instrument.
+#' \dQuote{USD} will be defined and used to create the instrument.
+#'
+#' If \code{primary_id} is 6 uppercase letters and \code{default_type} is not provided,
+#' it will be assumed that it is the primary_id of an \code{\link{exchange_rate}}, in which case,
+#' the 1st and/or 2nd half of \code{primary_id} will be defined as \code{\link{currency}} if not
+#' the names of already defined \code{\link{instrument}}s.
#' @param primary_id charater primary identifier of instrument to be created
#' @param currency character name of currency that instrument will be denominated it. Default=\dQuote{USD}
#' @param multiplier numeric product multiplier
@@ -677,7 +682,7 @@
stop(paste(currency, "is not defined,",
"and it will not be auto defined because it does not appear to be valid."))
currency(currency)
- if (!silent) warning(paste('Created currency', currency,'because it was not defined.'))
+ if (!silent) cat(paste('Created currency', currency,'because it was not defined.\n'))
}
warned <- FALSE
pid <- parse_id(primary_id)
@@ -712,13 +717,25 @@
}
if (any(pid$type == 'exchange_rate'))
return(exchange_rate(primary_id, defined.by='auto', ...))
+ #if we weren't given a default_type, then if it's 6 uppercase letters, make an exchange rate
+ if (default_type == 'NULL' && nchar(primary_id) == 6 && sum(attr(gregexpr("[A-Z]",primary_id)[[1]],"match.length")) == 6) {
+ if (!is.instrument(getInstrument(substr(primary_id,1,3), silent=TRUE))) {
+ ccy.st <- currency(substr(primary_id,1,3), defined.by='auto')
+ if (!silent) cat("Created currency", ccy.st, "because it was not defined.\n")
+ }
+ if (!is.instrument(getInstrument(substr(primary_id,4,6), silent=TRUE))) {
+ ccy.st <- currency(substr(primary_id,4,6), defined.by='auto')
+ if (!silent) cat("Created currency", ccy.st, "because it was not defined.\n")
+ }
+ return(exchange_rate(primary_id, defined.by='auto', ...))
+ }
if (any(pid$type == 'synthetic')) {
return(synthetic(members=strsplit(primary_id,"\\.")[[1]], currency=currency, defined.by='auto', ...) )
}
if(is.function(try(match.fun(default_type),silent=TRUE))) {
if (!silent && !warned)
warning('Creating a _', default_type, '_ instrument because ',
- primary_id, ' is not of an unambiguous format.')
+ primary_id, ' is of an ambiguous format.')
dargs <- list(...)
dargs$primary_id <- primary_id
dargs$currency <- currency
Modified: pkg/FinancialInstrument/man/instrument.auto.Rd
===================================================================
--- pkg/FinancialInstrument/man/instrument.auto.Rd 2011-09-25 18:26:39 UTC (rev 790)
+++ pkg/FinancialInstrument/man/instrument.auto.Rd 2011-09-25 23:22:11 UTC (rev 791)
@@ -38,6 +38,14 @@
\dQuote{USD} will be defined and used to create the
instrument.
+ If \code{primary_id} is 6 uppercase letters and
+ \code{default_type} is not provided, it will be assumed
+ that it is the primary_id of an
+ \code{\link{exchange_rate}}, in which case, the 1st
+ and/or 2nd half of \code{primary_id} will be defined as
+ \code{\link{currency}} if not the names of already
+ defined \code{\link{instrument}}s.
+
This is not intended to be used to create instruments of
type \code{stock}, \code{future}, \code{option}, or
\code{bond} although it may be updated in the future.
Modified: pkg/FinancialInstrument/man/load.instruments.Rd
===================================================================
--- pkg/FinancialInstrument/man/load.instruments.Rd 2011-09-25 18:26:39 UTC (rev 790)
+++ pkg/FinancialInstrument/man/load.instruments.Rd 2011-09-25 23:22:11 UTC (rev 791)
@@ -58,6 +58,7 @@
load.instruments(system.file('data/currencies.csv',package='FinancialInstrument'))
load.instruments(system.file('data/root_contracts.csv',package='FinancialInstrument'))
load.instruments(system.file('data/future_series.csv',package='FinancialInstrument'))
+
}
}
\seealso{
Modified: pkg/FinancialInstrument/sandbox/ISO.currencies.wiki.R
===================================================================
--- pkg/FinancialInstrument/sandbox/ISO.currencies.wiki.R 2011-09-25 18:26:39 UTC (rev 790)
+++ pkg/FinancialInstrument/sandbox/ISO.currencies.wiki.R 2011-09-25 23:22:11 UTC (rev 791)
@@ -27,14 +27,14 @@
ccy <- rbind(ccy, x[[3]]) #add non-ISO... things like Bitcoin
ccy <- ccy[ccy$Code %in% Symbols,]
} else Symbols <- NULL
- out <- unname(apply(ccy, 1, function(xx) currency(xx[1], description=xx[4], country=xx[5])))
+ out <- unname(apply(ccy, 1, function(xx) currency(xx[1], description=xx[4], country=xx[5], defined.by='wiki')))
if (!is.null(Symbols) && !identical(character(0), Symbols[!Symbols %in% ccy$Code])) {
if (!silent) warning(paste("The following are historical,",
- "and are not longer active:", Symbols[!Symbols %in% ccy$Code]))
+ "and are no longer active:", Symbols[!Symbols %in% ccy$Code]))
hccy <- x[[4]]
hccy <- hccy[hccy$Code %in% Symbols,]
out <- c(out, unname(apply(hccy, 1, function(xx) {
- currency(xx[1], description=xx[4], used.from=xx[5], used.until=xx[6], replaced.by=xx[7])
+ currency(xx[1], description=xx[4], used.from=xx[5], used.until=xx[6], replaced.by=xx[7], defined.by='wiki')
})))
}
out
More information about the Blotter-commits
mailing list