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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Dec 11 00:59:50 CET 2011


Author: gsee
Date: 2011-12-11 00:59:49 +0100 (Sun, 11 Dec 2011)
New Revision: 870

Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/R/parse_id.R
   pkg/FinancialInstrument/R/synthetic.R
   pkg/FinancialInstrument/man/parse_suffix.Rd
Log:
 - If any member of a synthetic.instrument has a value for expires, synthetic will inherit expires 
   of the first-to-expire member
 - parse_id now recognizes X.RICs for ICS


Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2011-12-10 20:43:41 UTC (rev 869)
+++ pkg/FinancialInstrument/DESCRIPTION	2011-12-10 23:59:49 UTC (rev 870)
@@ -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.9
+Version: 0.9.10
 URL: https://r-forge.r-project.org/projects/blotter/
 Date: $Date$
 Depends:

Modified: pkg/FinancialInstrument/R/parse_id.R
===================================================================
--- pkg/FinancialInstrument/R/parse_id.R	2011-12-10 20:43:41 UTC (rev 869)
+++ pkg/FinancialInstrument/R/parse_id.R	2011-12-10 23:59:49 UTC (rev 870)
@@ -198,10 +198,15 @@
 #' cc.Vol (continuous contract roll when Volumn rolls),
 #' cc.Exp.1 (continuous contract rolled 1 day before Expiration)
 #'
-#' Synthetics only return a value for the $type slot:
-#' U1.Z1 --> type == calendar, spread; 
-#' U11.Z11 --> type == calendar, spread; 
+#' Synthetics and spreads:
+#'
 #' SPY.DIA --> type == synthetic; 
+#'
+#' U1.Z1 or U11.Z11 --> type == "calendar", "spread"; month == 'SEP', year == 2011
+#'
+#' U1.0302 --> type == "ICS", "spread"; month == 'SEP', year == 2011
+#'
+#'
 #' 110917C125.110917P125 --> type == option_spread, spread
 #' @param x the suffix_id to be parsed
 #' @param silent silence warnings? (warning will usually be about inferring a 4 digit year from a 1 or 2 digit year)
@@ -210,7 +215,7 @@
 #' \sQuote{right} of option (\dQuote{C} or \dQuote{P}), \sQuote{cm} (maturity in days of a constant maturity contract),
 #' \sQuote{cc} (method for calculating a continuous contract), \sQuote{format} (string that indicates the format of the unparsed id).
 #' @author Garrett See
-#' @seealso \code{\link{parse_id}}
+#' @seealso \code{\link{parse_id}}, \code{\link{format_id}}, \code
 #' @examples
 #' parse_suffix("U11")
 #' parse_suffix("110917C125")
@@ -270,7 +275,7 @@
         } else type <- c("option_spread","spread")
     } else if (!identical(gsub("\\.","",x),x)) { #has a dot. U1.Z1, U11.Z11, SPY.DIA, 
         if (identical(all.equal(nchar(x) - nchar( gsub("\\.","",x)),1), TRUE)) { #only 1 dot, so it's not a fly
-            #U1.Z1, U11.Z11, SPY.DIA, EUR.USD
+            #U1.Z1, U11.Z11, SPY.DIA, EUR.USD, H2.0302
             s <- strsplit(x,"\\.")[[1]]
             s1 <- try(parse_suffix(s[1],silent=TRUE),silent=TRUE)
             s2 <- try(parse_suffix(s[2],silent=TRUE),silent=TRUE)
@@ -283,8 +288,17 @@
             
             if (all(c(s1$type,s2$type) == 'root')) {
                 type='synthetic'
-            } else { 
-                type=c('calendar','spread')
+            } else {
+                type <- if (!is.na(s1$format) 
+                         && !is.na(s2$format)
+                         && !s1$format %in% c("opt2", "opt4", "NNNN")
+                         && (s2$format == "NNNN")) {
+                         #H2.0302 (e.g. suffix of March 12 FYT ICS)
+                            c("ICS", "spread")
+                        } else c("calendar", "spread")
+                month <- s1$month
+                year <- s1$year                
+                format <- paste(s1$format, s2$format, sep=".")
             }
         } else if (identical(all.equal(nchar(x) - nchar(gsub("\\.","",x)),2), TRUE)) { #2 dots; it's a fly
             #U1.Z1.H2, U11.Z11.H12, SPY.DIA.QQQ

Modified: pkg/FinancialInstrument/R/synthetic.R
===================================================================
--- pkg/FinancialInstrument/R/synthetic.R	2011-12-10 20:43:41 UTC (rev 869)
+++ pkg/FinancialInstrument/R/synthetic.R	2011-12-10 23:59:49 UTC (rev 870)
@@ -106,8 +106,9 @@
 synthetic.instrument <- function (primary_id, currency, members, memberratio, ..., multiplier = 1, tick_size=NULL, 
     identifiers = NULL, assign_i=TRUE, type = c("synthetic.instrument", "synthetic")) 
 {
+    dargs <- list(...)
     if (!is.list(members)) {
-        if (length(members) != length(memberratio) | length(members) < 2) {
+        if (length(members) != length(memberratio) || length(members) < 2) {
             stop("length of members and memberratio must be equal, and contain two or more instruments")
         }
         memberlist <- list(members = members, memberratio = memberratio, 
@@ -125,6 +126,17 @@
                 memberlist$currencies[member] <- tmp_instr$currency
             }
         }
+
+        # expires will be whichever member expires first.
+        if (is.character(members)) {
+            ids <- sort_ids(members) #sort chronologically by expiry
+            expires <- try(getInstrument(ids[1], silent=TRUE)$expires)
+            if (!is.null(expires) && 
+                !inherits(expires, "try-error") && 
+                is.null(dargs$expires)) {
+                    dargs$expires <- expires
+            }
+        }
     }
     else {
         warning("passing in members as a list not fully tested")
@@ -153,8 +165,8 @@
         currency <- as.character(memberlist$currencies[1])
 	
     synthetic(primary_id = primary_id, currency = currency, multiplier = multiplier, 
-        identifiers = identifiers, memberlist = memberlist, memberratio = memberratio, tick_size=tick_size,
-        ... = ..., members = members, type = type)
+        identifiers = identifiers, assign_i=assign_i, memberlist = memberlist, memberratio = memberratio, tick_size=tick_size,
+        ... = dargs, members = members, type = type)
 }
 
 

Modified: pkg/FinancialInstrument/man/parse_suffix.Rd
===================================================================
--- pkg/FinancialInstrument/man/parse_suffix.Rd	2011-12-10 20:43:41 UTC (rev 869)
+++ pkg/FinancialInstrument/man/parse_suffix.Rd	2011-12-10 23:59:49 UTC (rev 870)
@@ -40,9 +40,16 @@
   contract roll when Volumn rolls), cc.Exp.1 (continuous
   contract rolled 1 day before Expiration)
 
-  Synthetics only return a value for the $type slot: U1.Z1
-  --> type == calendar, spread; U11.Z11 --> type ==
-  calendar, spread; SPY.DIA --> type == synthetic;
+  Synthetics and spreads:
+
+  SPY.DIA --> type == synthetic;
+
+  U1.Z1 or U11.Z11 --> type == "calendar", "spread"; month
+  == 'SEP', year == 2011
+
+  U1.0302 --> type == "ICS", "spread"; month == 'SEP', year
+  == 2011
+
   110917C125.110917P125 --> type == option_spread, spread
 }
 \examples{
@@ -53,6 +60,6 @@
   Garrett See
 }
 \seealso{
-  \code{\link{parse_id}}
+  \code{\link{parse_id}}, \code{\link{format_id}}, \code
 }
 



More information about the Blotter-commits mailing list