[Blotter-commits] r217 - pkg/FinancialInstrument/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jan 29 19:10:53 CET 2010
Author: braverock
Date: 2010-01-29 19:10:53 +0100 (Fri, 29 Jan 2010)
New Revision: 217
Modified:
pkg/FinancialInstrument/R/buildSpread.R
pkg/FinancialInstrument/R/instrument.R
pkg/FinancialInstrument/R/synthetic.R
Log:
- add more robust error handling and environment lookup
Modified: pkg/FinancialInstrument/R/buildSpread.R
===================================================================
--- pkg/FinancialInstrument/R/buildSpread.R 2010-01-29 04:11:44 UTC (rev 216)
+++ pkg/FinancialInstrument/R/buildSpread.R 2010-01-29 18:10:53 UTC (rev 217)
@@ -17,6 +17,7 @@
if(inherits(instr,"try-error") | !is.instrument(instr)){
stop(paste("Instrument",instr," not found, please create it first."))
} else {
+ #TODO check to see if instrument is a 'root symbol' instrument like a future or option
instr_currency<-instr$currency
if(i==1) primary_currency=instr_currency
stopifnot(is.currency(instr_currency))
Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R 2010-01-29 04:11:44 UTC (rev 216)
+++ pkg/FinancialInstrument/R/instrument.R 2010-01-29 18:10:53 UTC (rev 217)
@@ -217,7 +217,13 @@
-getInstrument <- function(x){
- get(x,pos=.instrument) #removed inherits=TRUE
- #TODO add Date support to instrument, to get the proper value given a specific date
+getInstrument <- function(x, Dates=NULL){
+ tmp_instr<-get(x,pos=.instrument) #removed inherits=TRUE
+ if(inherits(tmp_instr,"try-error") | !is.instrument(tmp_instr)){
+ warning(paste("Instrument",x," not found, please create it first."))
+ return(FALSE)
+ } else{
+ return(tmp_instr)
+ }
+ #TODO add Date support to instrument, to get the proper value given a specific date
}
Modified: pkg/FinancialInstrument/R/synthetic.R
===================================================================
--- pkg/FinancialInstrument/R/synthetic.R 2010-01-29 04:11:44 UTC (rev 216)
+++ pkg/FinancialInstrument/R/synthetic.R 2010-01-29 18:10:53 UTC (rev 217)
@@ -64,7 +64,7 @@
),
class=cl
), # end structure
- envir=.instrument,inherits=TRUE
+ envir=as.environment(.instrument)
)
}
More information about the Blotter-commits
mailing list