错误讯息"错误:下标越界“
来自包 fPortfolio
的 backtest 功能不幸的是,您最多只能阅读73列。否则
"错误:索引越界"
我已经阅读了几个记录(列数),它对74列(资产)等更为重要。
如果可以避免这种情况,可能会对用户进行故意限制吗?
你可以绕过这些限制吗?是否可以处理更多资产(数据)?如果我只拿走73个资产,我得到正确的输出,但是如果74个资产和更多(不是你成为"错误:下标超出界限":
library(cluster)
library(fMultivar)
library(fPortfolio)
library(mvoutlier)
library(pastecs)
library(timeSeries)
library(tseries)
SUP_USD.RET<- readSeries(file.choose(), format = "%Y-%m-%d", sep = ",")
manager.RET<-as.timeSeries(SUP_USD.RET)
managerData <- 100 * manager.RET
managerSpec <- portfolioSpec()
scenarios <- dim(manager.RET)[1]
assetsmitBenchmark <- dim(manager.RET)[2]
assetsmitBenchmark
assets <- (dim(manager.RET)[2]-1)
scenarios
assets
managerConstraints <- c('minW[1:assets]=0', 'maxW[1:assets]=0.10')
managerBacktest <- portfolioBacktest()
setWindowsHorizon(managerBacktest) <- "12m"
setSmootherLambda(managerBacktest) <- "3m"
colnames(manager.RET)
dim(manager.RET)
colnames(manager.RET[,1])
colnames(manager.RET[,2:73])
#473 Assets gesamt
bench1<-colnames(manager.RET[,1])
bench2<-colnames(manager.RET[,2:73])
#473 Assets gesamt
as.formula(paste("SUP500_TR~ ",paste(bench2, collapse= "+")))
managerFormula<-(as.formula(paste("SUP500_TR~",paste(bench2, collapse= "+"))))
managerPortfolios <- portfolioBacktesting(formula = managerFormula,
data = managerData, spec = managerSpec, constraints = managerConstraints,
backtest = managerBacktest, trace = FALSE)
如果我只拿走73个资产,我会得到正确的输出:
Portfolio Backtesting:
Assets: AA01 AA02 AA03 AA04 AA05 AA06 AA07 AA08 AA09 AA10 AA11 AA12 AA13 AA14 AA15 AA16 AA17 AA18 AA19 AA20 AA21 AA22 AA23 AA24 AA25 AA26 AA27 AA28 AA29 AA30 AA31 AA32 AA33 AA34 AA35 AA36 AA37 AA38 AA39 AA40 AA41 AA42 AA43 AA44 AA45 AA46 AA47 AA48 AA49 AA50 AA51 AA52 AA53 AA54 AA55 AA56 AA57 AA58 AA59 AA60 AA61 AA62 AA63 AA64 AA65 AA66 AA67 AA68 AA69 AA70
Benchmark: SUP500_TR
Start Series: 2010-12-28
End Series: 2017-09-14
Type: MV
Cov Estimator: covEstimator
Solver: solveRquadprog
Portfolio Windows: equidistWindows
Horizon: 12m
Portfolio Strategy: tangencyStrategy
Portfolio Smoother: emaSmoother
doubleSmoothing: TRUE
Lambda: 3m
Portfolio Optimization:
Optimization Period Target Benchmark Weights
2010-12-01 2011-11-30 0.138 0.014 0 0.1 0 0 0 0 0 0 0.088 0 0 0 0 0 0 0 0 0.1 0 0.026 0.1 0.1 0 0 0.1 0 0.07 0 0 0 0 0 0.1 0 0 0 0 0 0 0 0 0 0 0 0 0 0.016 0 0 0 0 0 0 0 0 0.1 0 0 0 0 0 0 0 0 0 0 0 0.1 0 0 * 1
2011-01-01 2011-12-31 0.127 0.014 0 0.1 0 0 0 0 0 0 0.03 0 0 0 0 0 0 0 0 0.1 0 0 0.1 0.1 0 0 0.1 0 0 0 0.1 0 0 0 0.1 0 0 0.007 0 0 0 0 0 0 0 0 0 0 0.062 0 0 0 0 0 0 0 0 0.1 0 0 0 0 0 0 0 0 0 0 0 0.1 0 0 * 1
2011-02-01 2012-01-31 0.145 0.023 0 0.1 0 0 0 0 0.058 0 0 0 0 0 0 0 0 0 0 0.1 0 0 0.1 0.042 0 0 0.1 0 0 0 0 0 0 0 0.1 0 0 0.1 0 0 0 0 0 0 0 0 0 0 0.1 0 0 0 0 0 0 0 0 0.1 0 0 0 0 0 0 0 0 0 0 0 0.1 0 0 * 1
2011-03-01 2012-02-29 0.152 0.038 0 0.1 0 0 0 0 0.1 0 0 0 0 0 0 0 0 0 0 0.1 0 0 0.1 0 0 0 0.1 0 0 0 0 0 0 0 0.1 0 0 0.1 0 0 0 0 0 0 0 0 0 0 0.1 0 0 0 0 0 0 0 0 0.1 0 0 0 0 0 0 0 0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