R 错误:初始化端口子赋值问题



我在运行此代码时不断收到以下错误,有人知道如何解决它吗?

library(blotter)
getSymbols('BP;AAPL')
symbols <- c(BP, AAPL)
initDate = "1990-01-01"
portfolio.st <- "mas"
initPortf(portfolio.st, symbols = symbols, initDate = initDate, currency = "USD")
Error in initPortf(portfolio.st, symbols = symbols, initDate = initDate,  : 
wrong args for environment subassignment

我相信所有变量都已正确定义...

未正确定义所有变量。 ?initPortfsymbols应该是"投资组合中包含的那些工具的工具标识符列表"(着重号是加的)。

查看您的symbols对象:

> str(symbols)
An ‘xts’ object on 2007-01-03/2016-01-15 containing:
  Data: num [1:4552, 1:6] 67.3 86.3 65.7 84.1 64.9 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:6] "BP.Open" "BP.High" "BP.Low" "BP.Close" ...
  Indexed by objects of class: [Date] TZ: UTC
  xts Attributes:  
List of 2
 $ src    : chr "yahoo"
 $ updated: POSIXct[1:1], format: "2016-01-18 16:25:34"

您需要这样做:

library(blotter)
symbols <- c("BP", "AAPL")
getSymbols(symbols)
#initDate = "1990-01-01"  # You do not need to set initDate
portfolio.st <- "mas"
initPortf(portfolio.st, symbols = symbols, currency = "USD")

如果您看过吸墨纸附带的一些演示,那就很清楚了。例如,"amzn_test":

require(blotter)
# Remove portfolio and account data if run previously
try(rm("portfolio.amzn_port","account.amzn_acct",pos=.blotter), silent = TRUE)
# load the example data
data("amzn")
currency("USD")
stock("amzn",currency="USD",multiplier=1)
# Initialize the Portfolio
initPortf("amzn_port",symbols="amzn",initDate="2010-01-14")
initAcct("amzn_acct",portfolios="amzn_port",initDate="2010-01-14", initEq=10000)
# look at the transactions data
amzn.trades
# Add the transactions to the portfolio
blotter::addTxns("amzn_port","amzn",TxnData=amzn.trades,verbose=TRUE)
# update the portfolio stats
updatePortf("amzn_port",Dates="2010-01-14")
# update the account P&L
updateAcct("amzn_acct",Dates="2010-01-14")
# and look at it
chart.Posn("amzn_port","amzn",Dates="2010-01-14")

相关内容

  • 没有找到相关文章

最新更新