[Blotter-commits] r147 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jan 13 23:37:02 CET 2010
Author: braverock
Date: 2010-01-13 23:37:01 +0100 (Wed, 13 Jan 2010)
New Revision: 147
Modified:
pkg/blotter/R/chart.Posn.R
Log:
- add align.time to Prices and Trades to try to line things up so that irregular trades print on the bars
alignment still seems off, need to work on fixing
Modified: pkg/blotter/R/chart.Posn.R
===================================================================
--- pkg/blotter/R/chart.Posn.R 2010-01-12 20:01:01 UTC (rev 146)
+++ pkg/blotter/R/chart.Posn.R 2010-01-13 22:37:01 UTC (rev 147)
@@ -24,10 +24,19 @@
# TODO: check that Portfolio is a Portfolio object
# TODO: add date scoping
Prices=get(Symbol)
-
+ freq = periodicity(Prices)
+ switch(freq$scale,
+ seconds = { mult=1 },
+ minute = { mult=60 },
+ hourly = { mult=3600 },
+ daily = { mult=86400 },
+ {mult=86400}
+ )
+ n=round(freq$frequency/mult,0)*mult
+ Prices=align.time(Prices,n)
Trades = Portfolio[[Symbol]]$txn$Txn.Price*Portfolio[[Symbol]]$txn$Txn.Qty
- Buys = Portfolio[[Symbol]]$txn$Txn.Price[which(Trades>0)]
- Sells = Portfolio[[Symbol]]$txn$Txn.Price[which(Trades<0)]
+ Buys = align.time(Portfolio[[Symbol]]$txn$Txn.Price[which(Trades>0)],n)
+ Sells = align.time(Portfolio[[Symbol]]$txn$Txn.Price[which(Trades<0)],n)
#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