[Blotter-commits] r180 - pkg/blotter/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jan 18 19:29:49 CET 2010


Author: braverock
Date: 2010-01-18 19:29:49 +0100 (Mon, 18 Jan 2010)
New Revision: 180

Modified:
   pkg/blotter/R/chart.Posn.R
Log:
- more error handling at the edges of aligning Trades and Price bars

Modified: pkg/blotter/R/chart.Posn.R
===================================================================
--- pkg/blotter/R/chart.Posn.R	2010-01-18 18:13:40 UTC (rev 179)
+++ pkg/blotter/R/chart.Posn.R	2010-01-18 18:29:49 UTC (rev 180)
@@ -32,17 +32,17 @@
             daily = { mult=86400 },
             {mult=86400}
     )
-    n=round(freq$frequency,0)*mult
-    if(!all.equal(freq$frequency*mult,round(freq$frequency,0)*mult)) { 
+    if(!isTRUE(freq$frequency*mult == round(freq$frequency,0)*mult)) { 
         # if the equality
-        Prices=align.time(Prices,n) 
-    }
+        n=round((freq$frequency/mult),0)*mult
+    } else { n=mult }
+    Prices=align.time(Prices,n) 
     tzero = xts(0,order.by=index(Prices[1,]))
     Trades = Portfolio[[Symbol]]$txn$Txn.Price*Portfolio[[Symbol]]$txn$Txn.Qty
     Buys = Portfolio[[Symbol]]$txn$Txn.Price[which(Trades>0)]
-    Buys = align.time(rbind(Buys,tzero),n)
+    Buys = align.time(rbind(Buys,tzero),mult)[-1]
     Sells = Portfolio[[Symbol]]$txn$Txn.Price[which(Trades<0)]
-    Sells = align.time(rbind(Sells,tzero),n)
+    Sells = align.time(rbind(Sells,tzero),mult)[-1]
     #Position = Portfolio[[Symbol]]$posPL$Pos.Qty # use $txn instead, and make it match the prices index
     Position = Portfolio[[Symbol]]$txn$Pos.Qty
     Position = na.locf(merge(Position,index(Prices)))



More information about the Blotter-commits mailing list