[R-SIG-Finance] Possible bug in blotter

Wolfgang Wu wobwu22 at yahoo.de
Tue Dec 21 15:19:29 CET 2010


Consider the following example. Initialise portfolio on day 1 with 100 USD, buy 
stock ABC on day 2 at a price of 100, sell stock ABC on day 3 at a price of 100. 
Now the End.Eq in getAccount is showing 200 USD. 


library(blotter)
currency('USD')
stock('ABC', currency='USD', multiplier=1)
initPortf('portA', symbols="ABC", initDate='2010-01-01');
initAcct('accA',portfolios='portA', initDate='2010-01-01', initEq=100);
#Buy on day 2
addTxn("portA", Symbol='ABC', TxnDate='2010-01-02', TxnPrice=100, TxnQty = 1, 
TxnFees=0, verbose=TRUE)
currentPrice <- xts(100, order.by=as.Date('2010-01-02'))
updatePortf('portA', Dates = '2010-01-02', Prices=currentPrice)
updateAcct('accA', Dates = '2010-01-02')
updateEndEq('accA', Dates = '2010-01-02')
#Sell on day 3
addTxn("portA", Symbol='ABC', TxnDate='2010-01-03', TxnPrice=100, TxnQty = -1, 
TxnFees=0, verbose=TRUE)
currentPrice <- xts(100, order.by=as.Date('2010-01-03'))
updatePortf('portA', Dates = '2010-01-03', Prices=currentPrice)
updateAcct('accA', Dates = '2010-01-03')
updateEndEq('accA', Dates = '2010-01-03')
#Equity wrong?
getPortfolio('portA')
getAccount('accA') 

Wolfgang Wu






More information about the R-SIG-Finance mailing list