[Blotter-commits] r770 - in pkg/FinancialInstrument: . R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Sep 11 20:18:00 CEST 2011
Author: gsee
Date: 2011-09-11 20:18:00 +0200 (Sun, 11 Sep 2011)
New Revision: 770
Modified:
pkg/FinancialInstrument/DESCRIPTION
pkg/FinancialInstrument/R/parse_id.R
Log:
change where length is checked in an if block
Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION 2011-09-11 17:55:23 UTC (rev 769)
+++ pkg/FinancialInstrument/DESCRIPTION 2011-09-11 18:18:00 UTC (rev 770)
@@ -11,7 +11,7 @@
meta-data and relationships. Provides support for
multi-asset class and multi-currency portfolios.
Still in heavy development.
-Version: 0.6.3
+Version: 0.6.4
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-09-11 17:55:23 UTC (rev 769)
+++ pkg/FinancialInstrument/R/parse_id.R 2011-09-11 18:18:00 UTC (rev 770)
@@ -100,38 +100,39 @@
has.und <- function(x) { #TRUE if it has an underscore
sapply(x, FUN=function(x) !identical(x, gsub('_','',x)))
}
- if (all(has.und(ss))) { #all parts have an underscore.
- #e.g. CL_N1.HO_M1 --> "CL_N1" "HO_M1"
- #or CL_N1.CL_M1
- ssu <- strsplit(ss,"_")
- tmprt <- ssu[[1]][1]
- if (all(sapply(ssu, FUN=function(x) x[1] == tmprt))) {
- #all share a root_id
- return(parse_id(make_spread_id(ss)))
- } else {
- #all parts have an underscore, but they don't share a root.
- #e.g. "CL_N1.HO_M1"
- root <- x
+ if (length(ss) > 1) {
+ if (all(has.und(ss))) { #all parts have an underscore.
+ #e.g. CL_N1.HO_M1 --> "CL_N1" "HO_M1"
+ #or CL_N1.CL_M1
+ ssu <- strsplit(ss,"_")
+ tmprt <- ssu[[1]][1]
+ if (all(sapply(ssu, FUN=function(x) x[1] == tmprt))) {
+ #all share a root_id
+ return(parse_id(make_spread_id(ss)))
+ } else {
+ #all parts have an underscore, but they don't share a root.
+ #e.g. "CL_N1.HO_M1"
+ root <- x
+ suffix <- ""
+ type <- 'synthetic'
+ sufftype <- FALSE
+ }
+ } else if (has.und(ss[1]) && !has.und(ss[2])) {
+ #First part has underscore, but second doesn't. e.g. CL_H1.M1 --> "CL_H1" "M1"
+ spl.und <- strsplit(x,"_")[[1]]
+ root <- spl.und[1]
+ suffix <- paste(spl.und[2:length(spl.und)],collapse=".")
+
+ } else {
suffix <- ""
- type <- 'synthetic'
- sufftype <- FALSE
- }
- } else if (has.und(ss[1]) && !has.und(ss[2])) {
- #First part has underscore, but second doesn't. e.g. CL_H1.M1 --> "CL_H1" "M1"
- spl.und <- strsplit(x,"_")[[1]]
- root <- spl.und[1]
- suffix <- paste(spl.und[2:length(spl.und)],collapse=".")
- } else {
- if (length(ss) > 1) {
- suffix <- ""
root <- x
type <- 'synthetic'
sufftype <- FALSE
- } else { #ES_U1, ES_U1M1,
- root <- strsplit(x,"_")[[1]][1]
- suffix <- strsplit(x,"_")[[1]][2]
- }
- }
+ }
+ } else { #ES_U1, ES_U1M1,
+ root <- strsplit(x,"_")[[1]][1]
+ suffix <- strsplit(x,"_")[[1]][2]
+ }
}
suff <- parse_suffix(suffix, silent=silent)
if (sufftype) type <- suff$type
More information about the Blotter-commits
mailing list