编辑(1):这是 sessionInfo():
> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils
[5] datasets methods base
other attached packages:
[1] FSVBackTest_0.0.0.9000
[2] blotter_0.14.2
[3] FSVTradingRules_0.0.0.9000
[4] FinancialInstrument_1.2.0
[5] quantmod_0.4-13.1
[6] FSVIndicators_0.0.0.9000
[7] roxygen2_6.0.1
[8] dlm_1.1-4
[9] PerformanceAnalytics_1.4.3541
[10] xts_0.10-2.1
[11] zoo_1.8-2
[12] TTR_0.23-2
[13] FSVPositionSizing_0.0.0.9000
[14] FSVDataCheck_0.0.0.9000
[15] RevoUtils_10.0.6
[16] RevoUtilsMath_10.0.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.13 xml2_1.1.1
[3] magrittr_1.5 rtvs_1.0.0.0
[5] lattice_0.20-35 R6_2.2.0
[7] foreach_1.4.4 stringr_1.2.0
[9] tools_3.4.2 grid_3.4.2
[11] iterators_1.0.8 commonmark_1.4
[13] codetools_0.2-15 curl_3.0
[15] stringi_1.1.5 compiler_3.4.2
[17] boot_1.3-20
编辑(2):为了使这完全可重现(希望如此),我创建了一个新库(称为 DUMMY),添加 xts(0.10-2.1) 作为唯一的依赖项,将来自 github butter repo 的 IBM.RData 文件添加为唯一文件(.R、.Rdata、.Rda 或其他),重新启动 R,仅将该库加载到全局环境中,我得到以下 sessionInfo():
> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] DUMMY_0.0.0.9000 xts_0.10-2.1 zoo_1.8-2
[4] RevoUtils_10.0.6 RevoUtilsMath_10.0.1
loaded via a namespace (and not attached):
[1] compiler_3.4.2 grid_3.4.2 rtvs_1.0.0.0
[4] lattice_0.20-35
我的说明文件如下所示:
Package: DUMMY
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "first.last@example.com", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: R (>= 3.4.2),
xts (>= 0.10-2.1)
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
现在,当我调用 IBM xts 对象的特定行时,我得到
> class(IBM)
[1] "xts" "zoo"
> IBM[1,]
IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
> IBM[21,]
IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
> IBM[20,]
IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
> IBM[2,]
IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
原始问题:
突然之间,我似乎观察到 xts 对象的奇怪行为,它导致吸墨纸(和 quantstrat)功能不再正常工作。即使演示也失败了。作为参考,我使用的是 xts_0.10-2.1、blotter_0.14.2 和 zoo_1.8-2。如果我使用 IBM 记事本中的内部数据,引用 IBM 的第一行会产生列名,而不是 IBM 价格数据的第一行。
> IBM[1,]
IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume
IBM.Adjusted
以供参考,
> dim(IBM)
[1] 21 6
要获取 IBM 价格数据的第一行,我需要引用 xts 对象的前两行。
> IBM[1:2,]
IBM.Open IBM.High IBM.Low IBM.Close
2007-01-03 22:00:00 97.25 98.79 96.88 98.31
IBM.Volume IBM.Adjusted
2007-01-03 22:00:00 10524500 94.76
当我尝试引用 IBM 数据的最后一行时,我得到
> IBM[nrow(IBM), ]
IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume
IBM.Adjusted
如果我尝试引用最后两行 IBM 数据
> IBM[20:21,]
IBM.Open IBM.High IBM.Low IBM.Close
2007-01-31 22:00:00 98.97 99.18 97.96 99
IBM.Volume IBM.Adjusted
2007-01-31 22:00:00 6610700 95.43
如果我尝试使用尾巴,
> tail(IBM, 2)
IBM.Open IBM.High IBM.Low IBM.Close
2007-01-31 22:00:00 98.97 99.18 97.96 99
IBM.Volume IBM.Adjusted
2007-01-31 22:00:00 6610700 95.43
当我尝试从吸墨纸运行 amzn_test 演示时,
> demo(package = "blotter")
> demo("amzn_test")
Type <Return> to start :
demo(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")
[1] "USD"
> stock("amzn",currency="USD",multiplier=1)
[1] "amzn"
> # Initialize the Portfolio
> initPortf("amzn_port",symbols="amzn",initDate="2010-01-14")
[1] "amzn_port"
> initAcct("amzn_acct",portfolios="amzn_port",initDate="2010-01-14", initEq=10000)
[1] "amzn_acct"
> # look at the transactions data
> amzn.trades
TxnPrice TxnQty
2010-01-14 07:18:50 127.49 -400
2010-01-14 07:18:53 127.49 400
2010-01-14 07:21:50 127.26 -300
2010-01-14 07:21:53 127.26 300
2010-01-14 07:23:07 127.17 100
2010-01-14 07:23:10 127.19 -100
2010-01-14 07:37:56 127.12 -400
2010-01-14 07:37:59 127.12 400
2010-01-14 07:38:32 127.23 -500
2010-01-14 07:38:35 127.23 500
2010-01-14 07:38:37 127.27 300
2010-01-14 07:38:40 127.30 -300
2010-01-14 07:46:08 126.95 -1300
2010-01-14 07:46:11 126.95 1300
> # Add the transactions to the portfolio
> blotter:::addTxns("amzn_port","amzn",TxnData=amzn.trades,verbose=TRUE)
Error in if (TxnDate < lastTxnDate) { : argument is of length zero
In addition: Warning messages:
1: In rm("portfolio.amzn_port", "account.amzn_acct", pos = .blotter) :
object 'portfolio.amzn_port' not found
2: In rm("portfolio.amzn_port", "account.amzn_acct", pos = .blotter) :
object 'account.amzn_acct' not found
>
我假设发生此错误是因为引用最后一行数据(lastTxnDate 来自哪里)会产生列名而不是最后一行数据,index() 将从该数据行中为我们提供日期。有没有其他人看过这个?它刚刚开始在过去几天发生,所以最近的问题。谢谢您的帮助!