[R-SIG-Finance] Possible bug in blotter

Wolfgang Wu wobwu22 at yahoo.de
Wed Dec 22 11:30:17 CET 2010


Peter, 

thank you for the explanation. I understand this now. However consider a 
different example where the security is now a futures contract with a multiplier 
of 2. Then blotter will produce a wrong End.Eq. (See example code) I suspect the 
Con.Mult column in the first row of the portfolio object is set wrongly and is 
causing the problem.  Would you agree?


library(blotter)
currency('USD')
future('ABC', currency='USD', multiplier=2, tick_size=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)
ABC <- xts(100, order.by=as.Date('2010-01-02'))
colnames(ABC) = "Close"
updatePortf('portA', Dates = '2010-01-02')
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)
ABC <- rbind(ABC, xts(100, order.by=as.Date('2010-01-03')))
updatePortf('portA', Dates = '2010-01-03')
updateAcct('accA', Dates = '2010-01-03')
updateEndEq('accA', Dates = '2010-01-03')
#Equity wrong?
getPortfolio('portA')
getAccount('accA')


I then get the following result 

> getPortfolio('portA')
$symbols
$symbols$ABC
$symbols$ABC$txn
           Txn.Qty Txn.Price Txn.Value Txn.Avg.Cost Pos.Qty Pos.Avg.Cost
2010-01-01       0         0         0            0       0            0
2010-01-02       1       100       200          100       1          100
2010-01-03      -1       100      -200          100       0            0
           Gross.Txn.Realized.PL Txn.Fees Net.Txn.Realized.PL Con.Mult
2010-01-01                     0        0                   0        0
2010-01-02                     0        0                   0        2
2010-01-03                     0        0                   0        2

$symbols$ABC$posPL
           Pos.Qty Con.Mult Ccy.Mult Pos.Value Pos.Avg.Cost Txn.Value
2010-01-01       0        1        1         0            0         0
2010-01-02       1        2        1       200          100       200
2010-01-03       0        2        1         0            0      -200
           Period.Realized.PL Period.Unrealized.PL Gross.Trading.PL Txn.Fees
2010-01-01                  0                    0                0        0
2010-01-02                  0                    0                0        0
2010-01-03                  0                  100              100        0
           Net.Trading.PL
2010-01-01              0
2010-01-02              0
2010-01-03            100

$symbols$ABC$posPL.USD
           Pos.Qty Con.Mult Ccy.Mult Pos.Value Pos.Avg.Cost Txn.Value
2010-01-01       0        1        1         0            0         0
2010-01-02       1        2        1       200          100       200
2010-01-03       0        2        1         0            0      -200
           Period.Realized.PL Period.Unrealized.PL Gross.Trading.PL Txn.Fees
2010-01-01                  0                    0                0        0
2010-01-02                  0                    0                0        0
2010-01-03                  0                  100              100        0
           Net.Trading.PL
2010-01-01              0
2010-01-02              0
2010-01-03            100



$summary
           Long.Value Short.Value Net.Value Gross.Value Period.Realized.PL
2010-01-03          0           0         0           0                  0
           Period.Unrealized.PL Gross.Trading.PL Txn.Fees Net.Trading.PL
2010-01-03                  100              100        0            100

attr(,"class")
[1] "blotter_portfolio" "portfolio"        
attr(,"currency")
[1] "USD"
attr(,"initDate")
[1] "2010-01-01"
> getAccount('accA')
$portfolios
$portfolios$portA
           Long.Value Short.Value Net.Value Gross.Value Realized.PL
2010-01-01          0           0         0           0           0
2010-01-02        200           0       200         200           0
2010-01-03          0           0         0           0           0
           Unrealized.PL Gross.Trading.PL Txn.Fees Net.Trading.PL
2010-01-01             0                0        0              0
2010-01-02             0                0        0              0
2010-01-03           100              100        0            100


$summary
           Additions Withdrawals Realized.PL Unrealized.PL Int.Income
2010-01-01         0           0           0             0          0
2010-01-02         0           0           0             0          0
2010-01-03         0           0           0           100          0
           Gross.Trading.PL Txn.Fees Net.Trading.PL Advisory.Fees
2010-01-01                0        0              0             0
2010-01-02                0        0              0             0
2010-01-03              100        0            100             0
           Net.Performance End.Eq
2010-01-01               0    100
2010-01-02               0    100
2010-01-03             100    200

attr(,"currency")
[1] "USD"
attr(,"initEq")
[1] 100
attr(,"class")
[1] "portfolio_account" "account"          



Thank you!

Regards, Wolfgang Wu





More information about the R-SIG-Finance mailing list