运行交易统计信息时Quantstrat/Blotter变暗错误

运行交易统计信息时Quantstrat/Blotter变暗错误,r,quantstrat,blotter,R,Quantstrat,Blotter,有一个从txt文件生成的xts对象。它包含5行:打开、高、低、关闭、S_Base。S_基是一个二进制信号,当低=关闭时为真(等于1)。被认为是55行的最小可复制示例。它有4个真实信号 下面的quantstrat代码在信号为真时输入long,在信号为假时变为平坦。这导致系统在开盘后的一段时间内关闭该头寸。 系统生成4个往返行程。它很好用。但是,吸墨纸包函数perTradeStats给出以下错误: Error in NextMethod(.Generic) : dims [product 2] d

有一个从txt文件生成的xts对象。它包含5行:打开、高、低、关闭、S_Base。S_基是一个二进制信号,当低=关闭时为真(等于1)。被认为是55行的最小可复制示例。它有4个真实信号

下面的quantstrat代码在信号为真时输入long,在信号为假时变为平坦。这导致系统在开盘后的一段时间内关闭该头寸。 系统生成4个往返行程。它很好用。但是,吸墨纸包函数
perTradeStats
给出以下错误:

Error in NextMethod(.Generic) : 
dims [product 2] do not match the length of object [0] 
如果我将相同的代码应用于从谷歌下载股票代码生成的xts(使用一些简单的SMA交叉作为信号),就不会有错误。我不明白为什么。下面是最小可再现示例的代码。提前感谢您的帮助

# Install Packages
#install.packages("devtools")
#require(devtools)
#install_github("braverock/FinancialInstrument")
#install_github("joshuaulrich/xts") #needed as latest version on repository is older
#install_github("braverock/blotter")
#install.packages("quantstrat", repos="http://R-Forge.R-project.org")
#install_github("braverock/PerformanceAnalytics")

# Libraries
library(quantstrat)   
library(knitr)        

# Data
DTT3 <- structure(c(126.33, 126.37, 126.42, 126.3, 126.31, 126.31, 126.31,126.37, 126.41, 126.42, 126.38, 126.33, 126.38, 126.38, 126.36, 126.39, 126.42, 126.42, 126.43, 126.43, 126.42, 126.39, 126.47, 126.56, 126.53, 126.5, 126.43, 126.45, 126.5, 126.42, 126.39, 126.39, 126.37, 126.24, 126.21, 126.15, 126.21, 126.24, 126.24, 126.25, 126.25, 126.2, 126.18, 126.21, 126.15, 126.16, 126.03, 125.94, 125.97, 125.97, 125.7, 125.73, 125.73, 125.55, 126.38, 126.47, 126.43, 126.35, 126.32, 126.37, 126.37, 126.43, 126.44, 126.43, 126.39, 126.39, 126.42, 126.38, 126.38, 126.44, 126.44, 126.44, 126.44, 126.44, 126.42, 126.5, 126.56, 126.57, 126.55, 126.52, 126.56, 126.5, 126.52, 126.44, 126.43, 126.42, 126.41, 126.29, 126.22, 126.29, 126.24, 126.3, 126.25, 126.27, 126.3, 126.2, 126.25, 126.21, 126.2, 126.17, 126.03, 126.04, 126.02, 125.97, 126.04, 125.89, 125.81, 125.6, 126.32, 126.36, 126.3, 126.25, 126.26, 126.29, 126.29, 126.36, 126.4, 126.37, 126.32, 126.28, 126.36, 126.34, 126.36, 126.39, 126.36, 126.37, 126.41, 126.41, 126.35, 126.39, 126.43, 126.52, 126.48, 126.42, 126.4, 126.41, 126.36, 126.34, 126.35, 126.3, 126.22, 126.2, 126.14, 126.15, 126.15, 126.22, 126.18, 126.23, 126.15, 126.14, 126.15, 126.15, 126.09, 125.91, 125.87, 125.94, 125.9, 125.7, 125.67, 125.63, 125.54, 125.35, 126.37, 126.42, 126.3, 126.32, 126.3, 126.32, 126.36, 126.41, 126.42, 126.38, 126.33, 126.39, 126.38, 126.36, 126.38, 126.42, 126.44, 126.42, 126.44, 126.41, 126.4, 126.47, 126.55, 126.53, 126.5, 126.43, 126.45, 126.49, 126.42, 126.39, 126.38, 126.36, 126.25, 126.22, 126.16, 126.21, 126.23, 126.24, 126.25, 126.26, 126.21, 126.18, 126.2, 126.15, 126.16, 126.02, 125.95, 125.98, 125.97, 125.7, 125.73, 125.72, 125.55, 125.38, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), .indexCLASS = c("POSIXct", "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", class = c("xts", "zoo"), index = structure(c(1403483400, 1403484300, 1403485200, 1403486100, 1403487000, 1403487900, 1403488800, 1403489700, 1403490600, 1403491500, 1403492400, 1403493300, 1403494200, 1403495100, 1403496000, 1403496900, 1403497800, 1403498700, 1403499600, 1403500500, 1403501400, 1403502300, 1403503200, 1403504100, 1403505000, 1403505900, 1403506800, 1403507700, 1403508600, 1403509500, 1403510400, 1403511300, 1403512200, 1403513100, 1403514000, 1403514900, 1403515800, 1403516700, 1403517600, 1403518500, 1403519400, 1403520300, 1403521200, 1403522100, 1403523000, 1403523900, 1403524800, 1403525700, 1403526600, 1403527500, 1403528400, 1403529300, 1403530200, 1403531100), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(54L, 5L), .Dimnames = list(NULL, c("Open", "High", "Low", "Close", "S_Base")))

# Basics
Sys.setenv(TZ = "UTC")      
currency("USD")               
initeq <- 30000

# Symbols
basic_symbols <- function() {symbols <- c("DTT3")}
symbols <- basic_symbols()
future(symbols, currency = "USD", multiplier = 1000)

# Strategy/Portfolio/Account
strategy.st <- "basicstrat"
portfolio.st <- "basicstrat"
account.st <- "basicstrat"
rm.strat(strategy.st)
rm.strat(portfolio.st)
initPortf(portfolio.st, symbols = symbols)
initAcct(account.st, portfolios = portfolio.st, initEq = initeq)
initOrders(portfolio.st, symbols = symbols)
strategy(strategy.st, store = TRUE)

# Enter Long Signal
add.signal(strategy.st, name = "sigThreshold",
           arguments = list(column = "S_Base",
                            threshold = 0,
                            relationship = "gt",     
                            cross = TRUE),           
           label = "longsig")

# Go Flat Signal
add.signal(strategy.st, name = "sigThreshold",
           arguments = list(column = "S_Base",
                            threshold = 0,
                            relationship = "eq",
                            cross = TRUE),
           label = "flatsig")

# Enter Long Rule
add.rule(strategy.st, name = "ruleSignal",
         arguments = list(sigcol = "longsig",
                          sigval = TRUE,              
                          ordertype = "market",
                          prefer = "Open",            
                          orderside = "long",
                          orderqty = 1,
                          replace = FALSE),
         type = "enter")

# Go Flat Rule
add.rule(strategy.st, name = "ruleSignal",
         arguments = list(sigcol = "flatsig",
                          sigval = TRUE,
                          ordertype = "market",
                          prefer = "Open",            
                          orderside = "long",
                          orderqty = "all",
                          replace = TRUE),        
         type = "exit")

# Apply Strategy
applyStrategy(strategy.st, portfolio.st)
updatePortf(portfolio.st)
updateAcct(account.st)
updateEndEq(account.st)

# Table: Summary Trade Stats
tstats <- tradeStats(portfolio.st)
kable(t(tstats))

### NO ERRORS ABOVE - FOLLOWING CODE PRODUCES THE ERROR/ERRORS ###

# Table: Per Trade Stats               
for(symbol in symbols) {
  pts <- perTradeStats(portfolio.st, Symbol = "DTT3")
  kable(pts, booktabs = TRUE, caption = symbol)}
kable(pts)

#Chart: Maximum Adverse Excursion 
for(symbol in symbols) {
  chart.ME(Portfolio = portfolio.st, Symbol = symbol, type = "MAE", 
           scale = "percent")}
#安装软件包
#安装包(“devtools”)
#需要(devtools)
#安装github(“Braverrock/FinancialInstrument”)
#安装所需的github(“joshuaulrich/xts”)#因为存储库上的最新版本较旧
#安装github(“braverock/blotter”)
#安装包(“quantstrat”,repos=”http://R-Forge.R-project.org")
#安装github(“braverock/PerformanceAnalytics”)
#图书馆
图书馆(quantstrat)
图书馆(knitr)
#资料

DTT3当我像本例一样运行此代码时,没有得到任何错误。我正在使用最新版本的quantstrat
install\u github(“braverock/quantstrat”)
,这可能就是答案。我使用的是
quantstrat\u 0.9.1739
,您的版本是
0.10.2
。我现在不知道,因为在用
install\u github(“braverock/quantstrat”)
更新
quantstrat
后,软件包将不再加载,并收到错误消息。将作为不同的问题单独处理。非常感谢。