我目前正在创建一个最小方差投资组合,并决定使用 PortfolioAnalytics 包的函数 optimize.portfolio。不幸的是,在提取权重时,它们都是 NA,尽管我的回报中没有任何 NA 值,这将是(从我的角度来看)导致结果权重为 NA 的唯一原因。我的数据集由多个资产 (+5000) 组成,每个资产有 60 个观察值(每月)。
library(PortfolioAnalytics)
library(ROI)
#index returns is an xts object consisting of 3800 stock Ids(columns) and 60 observations in
# monthly interval: To exemplifiy my problem, I set all values in index_returns to 1, to make
# sure that no NA values exist.
index_returns
any(is.na(index_returns)) # --> evaluates to FALSE
port_spec <- portfolio.spec(assets =colnames(index_returns) )
# Add a full investment constraint such that the weights sum to 1
port_spec <- add.constraint(portfolio = port_spec, type = "full_investment")
# Add a long only constraint such that the weight of an asset is between 0 and 1
port_spec <- add.constraint(portfolio = port_spec, type = "long_only")
# Add an objective to min portfolio variance
port_spec <- add.objective(portfolio = port_spec, type = "risk", name = "var")
# Solve the optimization problem
opt <- optimize.portfolio(R = index_returns, trace=TRUE, portfolio = port_spec,optimize_method = "ROI")
extractWeights(opt) #evaluates to NA for all assets
有谁知道为什么会发生这种情况并有任何建议如何处理这个问题。我知道这个优化问题很可能由于列多于行而面临可逆性问题,但除了这个概念之外,我正在努力解决我的问题。
我非常感谢任何帮助!提前致谢