0

在以下简单示例中,投资组合在 01-02 初始空头头寸为 50 股 IBM,该头寸在 01-04 被补仓。吸墨纸显示实现的 pnl 为 -4855。这是出乎意料的。看起来,blotter 假设 IBM 最初的 50 股股票以 0 价被卖空。关于如何使这个最小示例起作用的任何想法?如何将初始位置的成本传递给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
4

0 回答 0