[Blotter-commits] r305 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Mar 26 15:28:57 CET 2010
Author: peter_carl
Date: 2010-03-26 15:28:57 +0100 (Fri, 26 Mar 2010)
New Revision: 305
Modified:
pkg/blotter/R/addTxn.R
pkg/blotter/R/calcPosAvgCost.R
pkg/blotter/R/initTxn.R
pkg/blotter/R/updatePosPL.R
Log:
- applies fixes to Realized.PL in posPL table
Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R 2010-03-26 10:29:05 UTC (rev 304)
+++ pkg/blotter/R/addTxn.R 2010-03-26 14:28:57 UTC (rev 305)
@@ -114,7 +114,7 @@
if(row==1){
NewTxns <- NewTxn
- colnames(NewTxns) = c('Txn.Qty', 'Txn.Price', 'Txn.Fees', 'Txn.Value', 'Txn.Avg.Cost', 'Pos.Qty', 'Pos.Avg.Cost', 'Realized.PL', 'Con.Mult')
+ colnames(NewTxns) = c('Txn.Qty', 'Txn.Price', 'Txn.Fees', 'Txn.Value', 'Txn.Avg.Cost', 'Pos.Qty', 'Pos.Avg.Cost', 'Txn.Realized.PL', 'Con.Mult')
} else {
NewTxns<-rbind(NewTxns, NewTxn)
}
Modified: pkg/blotter/R/calcPosAvgCost.R
===================================================================
--- pkg/blotter/R/calcPosAvgCost.R 2010-03-26 10:29:05 UTC (rev 304)
+++ pkg/blotter/R/calcPosAvgCost.R 2010-03-26 14:28:57 UTC (rev 305)
@@ -18,7 +18,7 @@
if(PosQty == 0)
PosAvgCost = 0
else {
- PosAvgCost = (PrevPosQty * PrevPosAvgCost * ConMult + TxnValue)/(PosQty*ConMult)
+ PosAvgCost = abs((PrevPosQty * PrevPosAvgCost * ConMult + TxnValue)/(PosQty*ConMult))
}
return(PosAvgCost)
}
Modified: pkg/blotter/R/initTxn.R
===================================================================
--- pkg/blotter/R/initTxn.R 2010-03-26 10:29:05 UTC (rev 304)
+++ pkg/blotter/R/initTxn.R 2010-03-26 14:28:57 UTC (rev 305)
@@ -17,7 +17,7 @@
## TODO: Add 'Txn.Type' column
## TODO: DIVIDEND Txn.Type creates a realized gain
txn <- xts( as.matrix(t(c(0,0,0,0,0,initPosQty,0,0,0))), order.by=as.POSIXct(initDate) )
- colnames(txn) <- c('Txn.Qty', 'Txn.Price', 'Txn.Fees', 'Txn.Value', 'Txn.Avg.Cost', 'Pos.Qty', 'Pos.Avg.Cost', 'Realized.PL','Con.Mult')
+ colnames(txn) <- c('Txn.Qty', 'Txn.Price', 'Txn.Fees', 'Txn.Value', 'Txn.Avg.Cost', 'Pos.Qty', 'Pos.Avg.Cost', 'Txn.Realized.PL','Con.Mult')
class(txn)<-c("transactions",class(txn))
return(txn)
}
Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R 2010-03-26 10:29:05 UTC (rev 304)
+++ pkg/blotter/R/updatePosPL.R 2010-03-26 14:28:57 UTC (rev 305)
@@ -88,11 +88,13 @@
PrevClosePrice = as.numeric(Cl(Prices)[as.character(PrevDate)])
PrevPosValue = calcPosValue(PrevPosQty, PrevClosePrice, ConMult) ### @TODO: PrevConMult?
- TradingPL = calcTradingPL(PosValue, PrevPosValue, TxnValue)
- RealizedPL = getRealizedPL(pname, Symbol, CurrentSpan)
- #$unrealized_gl = $end_return['calc_position'] * ($end_return['last_price'] - $end_return['average_cost']);
+ TradingPL = PosValue - PrevPosValue - TxnValue
+
UnrealizedPL = PosQty*(ClosePrice-getPosAvgCost(Portfolio=pname, Symbol, CurrentDate))*ConMult
+ RealizedPL = round(TradingPL - UnrealizedPL,2)
+ #$unrealized_gl = $end_return['calc_position'] * ($end_return['last_price'] - $end_return['average_cost']);
+
NewPeriod = as.xts(t(c(PosQty, ConMult, CcyMult, PosValue, TxnValue, TxnFees, RealizedPL, UnrealizedPL, TradingPL)), order.by=as.POSIXct(CurrentDate)) #, format=tformat
colnames(NewPeriod) = c('Pos.Qty', 'Con.Mult', 'Ccy.Mult', 'Pos.Value', 'Txn.Value', 'Txn.Fees', 'Realized.PL', 'Unrealized.PL', 'Trading.PL')
Portfolio[[Symbol]]$posPL <- rbind(Portfolio[[Symbol]]$posPL, NewPeriod)
More information about the Blotter-commits
mailing list