R blotter包initPosQty用法

时间:2016-02-28 23:57:33

标签: algorithmic-trading blotter

在下面的简单示例中,投资组合在01-02的初始空头头寸为50股IBM,该头寸在01-04涵盖。吸墨纸显示实现的pnl为-4855。这是出乎意料的。看起来好像吸墨纸假设最初的50股IBM在价格0处被卖空了。关于如何使这个最小的例子工作的任何想法?如何将初始位置的成本转移到吸墨纸上?

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

0 个答案:

没有答案