[Blotter-commits] r785 - pkg/FinancialInstrument/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Sep 22 16:23:35 CEST 2011
Author: gsee
Date: 2011-09-22 16:23:34 +0200 (Thu, 22 Sep 2011)
New Revision: 785
Modified:
pkg/FinancialInstrument/R/instrument.R
pkg/FinancialInstrument/R/synthetic.R
Log:
better error message when you forget to provide currency
Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R 2011-09-22 13:15:22 UTC (rev 784)
+++ pkg/FinancialInstrument/R/instrument.R 2011-09-22 14:23:34 UTC (rev 785)
@@ -92,7 +92,8 @@
if(substr(primary_id,1,1)==1) primary_id <- substr(primary_id,2,nchar(primary_id))
primary_id<-make.names(primary_id)
- if(!is.currency(currency)) stop("currency ",currency," must be an object of type 'currency'")
+ if(missing(currency) || (!missing(currency) && !is.currency(currency)))
+ stop("currency ",currency," must be an object of type 'currency'")
if(!hasArg(identifiers) || is.null(identifiers)) identifiers = list()
if(!is.list(identifiers)) {
Modified: pkg/FinancialInstrument/R/synthetic.R
===================================================================
--- pkg/FinancialInstrument/R/synthetic.R 2011-09-22 13:15:22 UTC (rev 784)
+++ pkg/FinancialInstrument/R/synthetic.R 2011-09-22 14:23:34 UTC (rev 785)
@@ -16,7 +16,12 @@
synthetic <- function(primary_id=NULL, currency=NULL, multiplier=1, identifiers = NULL, ..., members=NULL, type="synthetic")
{
if (missing(primary_id) || (is.null(primary_id))) primary_id <- make_spread_id(members)
- if (missing(currency) || (is.null(currency))) currency <- getInstrument(members[[1]])$currency
+ if (missing(currency) || (is.null(currency))) {
+ if (is.null(members)) stop("'currency' is a required argument")
+ } else {
+ instr <- try(getInstrument(members[[1]],silent=TRUE))
+ if (is.instrument(instr)) currency <- instr$currency
+ }
instrument(primary_id=primary_id , currency=currency , multiplier=multiplier , identifiers = identifiers, ...=..., type=type, members=members, assign_i=TRUE )
}
More information about the Blotter-commits
mailing list