[Blotter-commits] r192 - in pkg/blotter: . R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jan 20 13:22:46 CET 2010
Author: braverock
Date: 2010-01-20 13:22:46 +0100 (Wed, 20 Jan 2010)
New Revision: 192
Modified:
pkg/blotter/NAMESPACE
pkg/blotter/R/synthetic.R
Log:
- add exchange rate conversions to buildSpread
- export buildSpread
Modified: pkg/blotter/NAMESPACE
===================================================================
--- pkg/blotter/NAMESPACE 2010-01-19 22:51:27 UTC (rev 191)
+++ pkg/blotter/NAMESPACE 2010-01-20 12:22:46 UTC (rev 192)
@@ -9,3 +9,4 @@
export(updateEndEq)
export(updatePortf)
#export(updatePosPL)
+export(buildSpread)
\ No newline at end of file
Modified: pkg/blotter/R/synthetic.R
===================================================================
--- pkg/blotter/R/synthetic.R 2010-01-19 22:51:27 UTC (rev 191)
+++ pkg/blotter/R/synthetic.R 2010-01-20 12:22:46 UTC (rev 192)
@@ -4,6 +4,8 @@
stop(paste("Instrument",tmp_instr," not found, please create it first."))
}
if(!inherits(tmp_instr,"spread")) stop (paste("Instrument",primary_id," is not a spread, please use the primary_id of a spread."))
+ tmp_currency<-tmp_instr$currency
+ stopifnot(is.currency(tmp_currency))
primary_instr<-getInstrument(tmp_instr$memberlist$members[1])
if(inherits(primary_instr,"try-error") | !is.instrument(primary_instr)){
@@ -35,6 +37,15 @@
spreadlevel<- (primary*primary_mult*primary_ratio)-(secondary*secondary_mult*secondary_ratio*exchange_rate)
if(onelot) spreadlevel = spreadlevel/primary_ratio
+ if(!all.equal(tmp_currency,primary_currency)){
+ #convert to the currency of the spread
+ spr_exch_rate <- try(get(paste(tmp_currency,primary_currency,sep='')))
+ if(inherits(spr_exch_rate,"try-error")){
+ stop(paste("Exchange Rate",paste(tmp_currency, primary_currency,sep=''),"not found."))
+ } else {
+ spreadlevel<-spreadlevel*exchange_rate
+ }
+ }
return(spreadlevel)
}
More information about the Blotter-commits
mailing list