gpt4 book ai didi

r - R : attempt to set 'colnames' on an object with less than two dimensions中的错误消息

转载 作者:行者123 更新时间:2023-12-03 07:56:05 26 4
gpt4 key购买 nike

当我没有施加太多限制时,我的代码就会起作用。但是,我要运行大量的约束。无论如何,有没有什么可以帮助解决问题或解决此错误的方法。我正在尝试绘制一个有效的边界。谢谢。我在下面有数据时间序列的说明。

library("fPortfolio")
library('fPortfolio')
data = SPISECTOR.RET
asset = dim(data)[2]

# I'm putting a lot of constraints here. I want to do this.
# If I take away some of the constraints, the formula works.
# But I don't want to take away the constraints.
constraints <- c('minW[1:asset]=0','maxW[1:asset]=0.3', 'minsumW[c("ACWI", "ACWX", "AGED", "CEMA", "CEMG", "CMXC", "CNYA", "COMF", "CSJP", "CSKR", "CSRU", "CSUK", "DGTL", "DLTM", "ECAR", "EEM", "EFA", "EIDO", "EIRL", "EMB", "ENOR", "EPHE", "EPOL", "EUSA", "GUNR", "HEAL", "ICDU", "ICSU", "IESU", "IGAA", "IH2O", "IHCU", "IHYA", "IIND", "IISU", "IITU", "IJS", "IJT", "IMSU", "INRG", "IQLT", "IUSU", "KWEB", "LAND", "LOCK", "MGK", "OPEN", "QQQ", "RBOT", "SAUS", "SPAG", "UIFS", "UNG", "USMV", "VB", "VNQ", "VNQI", "VTV", "VUG", "WOOD", "XFVT")]=0.01', 'maxsumW[c("ACWI", "ACWX", "AGED", "CEMA", "CEMG", "CMXC", "CNYA", "COMF", "CSJP", "CSKR", "CSRU", "CSUK", "DGTL", "DLTM", "ECAR", "EEM", "EFA", "EIDO", "EIRL", "EMB", "ENOR", "EPHE", "EPOL", "EUSA", "GUNR", "HEAL", "ICDU", "ICSU", "IESU", "IGAA", "IH2O", "IHCU", "IHYA", "IIND", "IISU", "IITU", "IJS", "IJT", "IMSU", "INRG", "IQLT", "IUSU", "KWEB", "LAND", "LOCK", "MGK", "OPEN", "QQQ", "RBOT", "SAUS", "SPAG", "UIFS", "UNG", "USMV", "VB", "VNQ", "VNQI", "VTV", "VUG", "WOOD", "XFVT")]=0.3', 'minsumW[c("BND", "CBON", "CRPA", "GLD", "SLV", "SPGP", "SWAN")]=0.01', 'maxsumW[c("BND", "CBON", "CRPA", "GLD", "SLV", "SPGP", "SWAN")]=0.3', 'minsumW[c("GLTL", "GLTS", "IBGE", "IBGY", "IBGZ", "IEF", "IGLT", "SEGA", "SHY", "TIP", "TLT", "VVUILG")]=0.01', 'maxsumW[c("GLTL", "GLTS", "IBGE", "IBGY", "IBGZ", "IEF", "IGLT", "SEGA", "SHY", "TIP", "TLT", "VVUILG")]=0.3')

spec <- portfolioSpec()
setNFrontierPoints(spec) <- 25
setSolver(spec)<- "solveRquadprog"

frontier <-portfolioFrontier(data, spec, constraints)
当我运行最后一行 frontier <-portfolioFrontier(data, spec, constraints)时,出现错误:
Error in `colnames<-`(`*tmp*`, value = names(getMu(Data))) : 
attempt to set 'colnames' on an object with less than two dimensions

最佳答案

好吧,我知道了。我没有将约束加到一个,而是放入了其他库。现在一切都很好。

关于r - R : attempt to set 'colnames' on an object with less than two dimensions中的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65534512/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com