[Blotter-commits] r145 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jan 12 20:47:21 CET 2010
Author: braverock
Date: 2010-01-12 20:47:21 +0100 (Tue, 12 Jan 2010)
New Revision: 145
Modified:
pkg/blotter/R/chart.Posn.R
Log:
-update chart.Posn to better handle irregular/intraday time series and match them top periodicity of price data
Modified: pkg/blotter/R/chart.Posn.R
===================================================================
--- pkg/blotter/R/chart.Posn.R 2010-01-12 18:13:25 UTC (rev 144)
+++ pkg/blotter/R/chart.Posn.R 2010-01-12 19:47:21 UTC (rev 145)
@@ -25,9 +25,12 @@
# TODO: add date scoping
Prices=get(Symbol)
- Buys = Portfolio[[Symbol]]$txn$Txn.Price*(Portfolio[[Symbol]]$txn$Txn.Qty>0)
- Sells = Portfolio[[Symbol]]$txn$Txn.Price*(Portfolio[[Symbol]]$txn$Txn.Qty<0)
- Position = Portfolio[[Symbol]]$posPL$Pos.Qty
+ 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)]
+ #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)))
CumPL = cumsum(Portfolio[[Symbol]]$posPL$Trading.PL)
# # These aren't quite right, as abs(Pos.Qty) should be less than prior abs(Pos.Qty)
# SellCover = Portfolio[[Symbol]]$txn$Txn.Price * (Portfolio[[Symbol]]$txn$Txn.Qty<0) * (Portfolio[[Symbol]]$txn$Pos.Qty==0)
More information about the Blotter-commits
mailing list