[Blotter-commits] r878 - in pkg/FinancialInstrument: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Dec 15 19:09:01 CET 2011


Author: gsee
Date: 2011-12-15 19:09:00 +0100 (Thu, 15 Dec 2011)
New Revision: 878

Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/R/instrument.R
   pkg/FinancialInstrument/R/synthetic.R
   pkg/FinancialInstrument/man/currencies.Rd
   pkg/FinancialInstrument/man/instrument.auto.Rd
   pkg/FinancialInstrument/man/root_contracts.Rd
Log:
 - instrument.auto will warn when it does not know which currency to use
 - synthetics will try to use currency of member; USD if members are not defined


Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2011-12-14 16:03:38 UTC (rev 877)
+++ pkg/FinancialInstrument/DESCRIPTION	2011-12-15 18:09:00 UTC (rev 878)
@@ -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.11
+Version: 0.9.12
 URL: https://r-forge.r-project.org/projects/blotter/
 Date: $Date$
 Depends:

Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R	2011-12-14 16:03:38 UTC (rev 877)
+++ pkg/FinancialInstrument/R/instrument.R	2011-12-15 18:09:00 UTC (rev 878)
@@ -723,10 +723,10 @@
 #' getInstrument("VX_H11") #made a future_series
 #' }
 #' @export
-instrument.auto <- function(primary_id, currency='USD', multiplier=1, silent=FALSE, default_type='NULL', root=NULL, assign_i=TRUE, ...) {
+instrument.auto <- function(primary_id, currency=NULL, multiplier=1, silent=FALSE, default_type='NULL', root=NULL, assign_i=TRUE, ...) {
 ##TODO: check formals against dots and remove duplicates from dots before calling constructors to avoid
 # 'formal argument "multiplier" matched by multiple actual arguments'
-    if (!is.currency(currency)) {
+    if (!is.null(currency) && !is.currency(currency)) {
         if (nchar(currency) != 3 || currency != toupper(currency))
             stop(paste(currency, "is not defined,",
                 "and it will not be auto defined because it does not appear to be valid."))
@@ -815,6 +815,10 @@
     }
     if (any(pid$type == 'synthetic')) {
         if (!is.na(pid$format) && pid$format == 'yahooIndex') {
+            if (is.null(currency)) {
+                warning('currency will be assumed to be USD because NULL is not a currency.')
+                currency <- 'USD'
+            }
             return(synthetic(gsub("\\^","",primary_id), currency=currency, identifiers=list(yahoo=primary_id), 
                             src=list(src='yahoo',name=primary_id), defined_by='auto', assign_i=assign_i, ...))
         } else return(synthetic(members=strsplit(primary_id,"\\.")[[1]], currency=currency, defined.by='auto', assign_i=assign_i, ...) )
@@ -823,7 +827,7 @@
     ss <- ss[!ss %in% ""]
     if (length(ss) == 2) primary_id <- paste(ss,collapse="_")
     dargs$primary_id <- primary_id
-    dargs$currency <- currency
+    dargs$currency <- if (!is.null(currency)) { currency } else { warning('using USD as the currency'); "USD" }
     dargs$multiplier <- multiplier
     dargs$defined.by='auto'
     dargs$assign_i <- assign_i

Modified: pkg/FinancialInstrument/R/synthetic.R
===================================================================
--- pkg/FinancialInstrument/R/synthetic.R	2011-12-14 16:03:38 UTC (rev 877)
+++ pkg/FinancialInstrument/R/synthetic.R	2011-12-15 18:09:00 UTC (rev 878)
@@ -195,26 +195,35 @@
 {
 ##TODO: butterfly can refer to expirations (futures) or strikes (options)
 ##TODO: A butterfly could either have 3 members that are outrights, or 2 members that are spreads
-  if (missing(members)) {  
-    pid <- parse_id(primary_id)
-    root_id <- pid$root
-    suffix_id <- pid$suffix
-    #synthetic flies will have a root_id that looks like "
-    if (suffix_id == "")
-        members <- unlist(strsplit(root_id, "[-;:,\\.]"))
-    else members <- paste(root_id, unlist(strsplit(suffix_id, "[-;:_,\\.]")), sep="_")
-  }
+    if (missing(members)) {  
+        pid <- parse_id(primary_id)
+        root_id <- pid$root
+        suffix_id <- pid$suffix
+        #synthetic flies will have a root_id that looks like "
+        if (suffix_id == "")
+            members <- unlist(strsplit(root_id, "[-;:,\\.]"))
+        else members <- paste(root_id, unlist(strsplit(suffix_id, "[-;:_,\\.]")), sep="_")
+    }
 
-  if (length(members) == 3) {
-    synthetic.instrument(primary_id=primary_id,currency=currency,members=members,
-	    memberratio=c(1,-2,1), multiplier=1, tick_size=tick_size,
-	    identifiers=NULL, assign_i=assign_i, ...=..., type = c('butterfly','spread','synthetic.instrument',
-	    'synthetic','instrument'))
-  } else if (length(members) == 2) {
-      stop('butterfly currently only supports 3 leg spreads (i.e. no spread of spreads yet.)')
-
-  } else stop('A butterfly must either have 3 outright legs or 2 spread legs') 
-  
+    if (length(members) == 3) {
+        if (is.null(currency)) {
+            m1 <- getInstrument(members[[1]],silent=TRUE)
+            if (!is.instrument(m1)) m1 <- getInstrument(members[[2]], silent=TRUE)
+            if (!is.instrument(m1)) m1 <- getInstrument(members[[3]], silent=TRUE)
+            if (is.instrument(m1)) {
+                currency <- m1$currency
+            } else {
+                warning('currency is NULL and spread members are not defined. Using currency of USD')
+                currency <- 'USD'
+            }
+        }
+        synthetic.instrument(primary_id=primary_id,currency=currency,members=members,
+            memberratio=c(1,-2,1), multiplier=1, tick_size=tick_size,
+            identifiers=NULL, assign_i=assign_i, ...=..., type = c('butterfly','spread','synthetic.instrument',
+            'synthetic','instrument'))
+    } else if (length(members) == 2) {
+        stop('butterfly currently only supports 3 leg spreads (i.e. no spread of spreads yet.)')
+    } else stop('A butterfly must either have 3 outright legs or 2 spread legs')
 }
 
 
@@ -260,8 +269,13 @@
         }
         if (is.null(currency)) {
             m1 <- getInstrument(members[[1]],silent=TRUE)
-            if (is.instrument(m1))
+            if (!is.instrument(m1)) m1 <- getInstrument(members[[2]], silent=TRUE)
+            if (is.instrument(m1)) {
                 currency <- m1$currency
+            } else {
+                warning('currency is NULL and spread members are not defined. Using currency of USD')
+                currency <- 'USD'
+            }
         }
     }
 	

Modified: pkg/FinancialInstrument/man/currencies.Rd
===================================================================
--- pkg/FinancialInstrument/man/currencies.Rd	2011-12-14 16:03:38 UTC (rev 877)
+++ pkg/FinancialInstrument/man/currencies.Rd	2011-12-15 18:09:00 UTC (rev 878)
@@ -7,5 +7,5 @@
   \code{\link{load.instruments}}
 }
 \keyword{data}
-\keyword{dataset}
+\keyword{datasets}
 

Modified: pkg/FinancialInstrument/man/instrument.auto.Rd
===================================================================
--- pkg/FinancialInstrument/man/instrument.auto.Rd	2011-12-14 16:03:38 UTC (rev 877)
+++ pkg/FinancialInstrument/man/instrument.auto.Rd	2011-12-15 18:09:00 UTC (rev 878)
@@ -2,7 +2,7 @@
 \alias{instrument.auto}
 \title{Create an instrument based on name alone}
 \usage{
-  instrument.auto(primary_id, currency = "USD",
+  instrument.auto(primary_id, currency = NULL,
     multiplier = 1, silent = FALSE, default_type = "NULL",
     root = NULL, assign_i = TRUE, ...)
 }

Modified: pkg/FinancialInstrument/man/root_contracts.Rd
===================================================================
--- pkg/FinancialInstrument/man/root_contracts.Rd	2011-12-14 16:03:38 UTC (rev 877)
+++ pkg/FinancialInstrument/man/root_contracts.Rd	2011-12-15 18:09:00 UTC (rev 878)
@@ -7,5 +7,5 @@
   \code{\link{load.instruments}}
 }
 \keyword{data}
-\keyword{dataset}
+\keyword{datasets}
 



More information about the Blotter-commits mailing list