0

In the following simple example, the portfolio has an initial short position of 50 shares of IBM on 01-02, the position is covered on 01-04. blotter showed a realized pnl of -4855. This is unexpected. It looks like blotter assumes the initial 50 shares of IBM was shorted at price 0. Any ideas about how to make this minimal example work? How to pass in the cost of the initial position to blotter?

library(blotter)
try(rm("portfolio.p",pos=.blotter), silent = TRUE)
Sys.setenv(TZ="UTC") # this is critical
currency("USD")
stock('IBM', currency="USD", multiplier=1)
getSymbols('IBM', from='2007-01-01', to='2007-01-05', src='yahoo')
initPortf('p', symbols=symbols,initPosQty=-50, initDate='2007-01-02',currency="USD")
addTxn("p", "IBM", '2007-01-04', 50, 97.1, TxnFees = 0)
updatePortf(Portfolio="p",Dates='2007-01')
.blotter$portfolio.p$symbols$IBM$posPL
#            Pos.Qty Con.Mult Ccy.Mult Pos.Value Pos.Avg.Cost Txn.Value
# 2007-01-02     -50        1        1         0            0         0
# 2007-01-02     -50        0        1         0            0         0
# 2007-01-03     -50        0        1         0            0         0
# 2007-01-04       0        1        1         0            0      4855
# 2007-01-05       0        1        1         0            0         0
#            Period.Realized.PL Period.Unrealized.PL Gross.Trading.PL
# 2007-01-02                  0                    0                0
# 2007-01-02                  0                    0                0
# 2007-01-03                  0                    0                0
# 2007-01-04              -4855                    0            -4855
# 2007-01-05                  0                    0                0
#            Txn.Fees Net.Trading.PL
# 2007-01-02        0              0
# 2007-01-02        0              0
# 2007-01-03        0              0
# 2007-01-04        0          -4855
# 2007-01-05        0              0
Jim Green
  • 261
  • 4
  • 10
  • 1
    initPortf with initPosQty = 0 and then add additional transaction with -50 qty on 2007-01-02 with your price. It seems initPortf does not have initPrice parameter which is probably a mistake. – Ignas Mar 08 '16 at 21:34
  • Thanks, this would work.I agree initPosQty doesn't really work in the current blotter code. – Jim Green Mar 09 '16 at 01:44

0 Answers0