我试图提取/保存我在R中获得的投资组合权重的值。以下是我可重现的代码: -
# load libraries
library(fPortfolio)
library(rmgarch)
data(dji30retw)
Dat = dji30retw[, 1:8, drop = FALSE]
All.Data <- as.timeSeries(Dat)
##Global minimum variance portfolio
globminSpec <- portfolioSpec()
globminPortfolio <- minvariancePortfolio(data = All.Data,spec = globminSpec,constraints = "LongOnly")
print(globminPortfolio)
我将得到以下结果: -
Title:
MV Minimum Variance Portfolio
Estimator: covEstimator
Solver: solveRquadprog
Optimize: minRisk
Constraints: LongOnly
Portfolio Weights:
AA AXP BA BAC C CAT CVX DD
0.0000 0.0746 0.1796 0.0346 0.0000 0.0633 0.4606 0.1873
Covariance Risk Budgets:
AA AXP BA BAC C CAT CVX DD
0.0000 0.0746 0.1796 0.0346 0.0000 0.0633 0.4606 0.1873
Target Returns and Risks:
mean Cov CVaR VaR
0.0016 0.0277 0.0648 0.0400
如何从输出中提取或保存投资组合权重?
答案 0 :(得分:1)
您可以简单地getWeights(globminPortflio)
或getPortfolio(globminPortfolio)$weights
。第二种方法还允许您访问其他一些投资组合信息。
我在这里找到some documentation,但它很稀疏。