[Blotter-commits] r700 - pkg/FinancialInstrument/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 25 21:12:10 CEST 2011


Author: gsee
Date: 2011-07-25 21:12:08 +0200 (Mon, 25 Jul 2011)
New Revision: 700

Modified:
   pkg/FinancialInstrument/R/buildSpread.R
Log:
 fixed subsetting of spread

Modified: pkg/FinancialInstrument/R/buildSpread.R
===================================================================
--- pkg/FinancialInstrument/R/buildSpread.R	2011-07-25 18:26:51 UTC (rev 699)
+++ pkg/FinancialInstrument/R/buildSpread.R	2011-07-25 19:12:08 UTC (rev 700)
@@ -58,7 +58,6 @@
       from <- times$first.time
       to <- times$last.time
     }
-    last.to <- Sys.time()
     spreadseries <- NULL
     for (i in 1:length(spread_instr$members)) {
         instr <- try(getInstrument(as.character(spread_instr$members[i])))
@@ -108,13 +107,17 @@
         instr_norm <- instr_prices * instr_mult * instr_ratio
         colnames(instr_norm) <- paste(as.character(spread_instr$members[i]), 
             prefer, sep = ".")
-        if (is.null(spreadseries)) 
+        if (is.null(spreadseries)) {
             spreadseries <- instr_norm
-        else spreadseries = merge(spreadseries, instr_norm)
-        first.from <- max(first.from, start(spreadseries))
-        last.to <- min(last.to, end(spreadseries))
+            last.from <- start(spreadseries)
+            first.to <- end(spreadseries)        
+        } else {
+            spreadseries = merge(spreadseries, instr_norm)
+            last.from <- max(last.from, start(instr_norm)) 
+            first.to <- min(first.to, end(instr_norm))
+        }    
     }
-    spreadseries <- spreadseries[paste(first.from,last.to,sep="/")]
+    spreadseries <- spreadseries[paste(last.from, first.to, sep="/")]
     spreadseries <- na.locf(spreadseries,na.rm=TRUE)
     spreadlevel = xts(rowSums(spreadseries),order.by=index(spreadseries)) #assumes negative memberratio values for shorts in 'memberratio'
     if (onelot) 



More information about the Blotter-commits mailing list