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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Dec 15 23:42:15 CET 2011


Author: gsee
Date: 2011-12-15 23:42:14 +0100 (Thu, 15 Dec 2011)
New Revision: 879

Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/R/instrument.R
   pkg/FinancialInstrument/R/parse_id.R
Log:
parse_id and instrument.auto recognize X.RICs for NMS stocks

Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2011-12-15 18:09:00 UTC (rev 878)
+++ pkg/FinancialInstrument/DESCRIPTION	2011-12-15 22:42:14 UTC (rev 879)
@@ -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.12
+Version: 0.9.13
 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-15 18:09:00 UTC (rev 878)
+++ pkg/FinancialInstrument/R/instrument.R	2011-12-15 22:42:14 UTC (rev 879)
@@ -823,6 +823,12 @@
                             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, ...) )
     } 
+    if (any(pid$type == 'root')) {
+        if (primary_id %in% c(paste(pid$root, "O", sep="."), paste(pid$root, "OQ", sep="."))) { #X.RIC for NASDAQ stock.  e.g. AAPL.O, MSFT.OQ
+            stock(pid$root, currency=currency('USD'), identifiers=list(X.RIC=primary_id), defined.by='auto', assign_i=assign_i, ...)
+            #update_instruments.yahoo(pid$root) 
+        }
+    }
     ss <- strsplit(primary_id," ")[[1]]  #take out spaces (OSI uses spaces, but makenames would turn them into dots)
     ss <- ss[!ss %in% ""]
     if (length(ss) == 2) primary_id <- paste(ss,collapse="_")
@@ -842,8 +848,8 @@
                 'Creating basic instrument with multiplier 1.'))
     do.call(instrument, dargs)
 }
- 
-   
+
+  
 #' primary accessor function for getting objects of type 'instrument'
 #' 
 #' This function will search the \code{.instrument} environment for objects of

Modified: pkg/FinancialInstrument/R/parse_id.R
===================================================================
--- pkg/FinancialInstrument/R/parse_id.R	2011-12-15 18:09:00 UTC (rev 878)
+++ pkg/FinancialInstrument/R/parse_id.R	2011-12-15 22:42:14 UTC (rev 879)
@@ -33,8 +33,18 @@
         suffix <- sub(root,"",x) #turns ESU1 into U1, or ES_U11 into _U11 
         suffix <- gsub("_","",suffix) #take out the underscore if there is one
     } else if (identical(integer(0), grep("[0-9]",x))) { 
-        #if there are no numbers in the id, then it has no year, so it is not a recognized future or option
-        if (identical(all.equal(nchar(x) - nchar( gsub("\\.","",x)),1), TRUE)) { 
+        #if there are no numbers in the id, then it has no year, so it is not a recognized future or option        
+        if (substr(x, nchar(x)-1, nchar(x)) == ".O") {
+            #only one dot, and the id ends with ".O" -- it looks like an X.RIC for a NASDAQ stock
+            suffix <- ""
+            root <- substr(x, 1, nchar(x)-2)
+            type <- 'root'
+        } else if (substr(x, nchar(x)-2, nchar(x)) == ".OQ") {
+            # id ends with ".OQ" -- looks like an X.RIC for NMS stock
+            suffix <- ""
+            root <- substr(x, 1, nchar(x)-3)
+            type <- 'root'
+        } else if (identical(all.equal(nchar(x) - nchar( gsub("\\.","",x)),1), TRUE)) { 
             #only 1 dot, so it's not a fly
             #SPY.DIA, EUR.USD, SPY110917C122.5, T2010917P25
             if (suppressWarnings(!is.na(as.numeric(strsplit(x,"\\.")[[1]][2])))) { #probably an option with a decimal in the strike



More information about the Blotter-commits mailing list