简体   繁体   中英

Extract portfolio weights from fPortfolio output

I'm trying to extract/save the value of the portfolio weights which I have obtained in R. Below is my reproducible code:-

# 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) 

I will get the following result:-

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 

How do I extract or save the portfolio weights from the output?

You can simpy do getWeights(globminPortflio) or getPortfolio(globminPortfolio)$weights . The second methods also gives you access to some other portfolio information.

I found some documentation here but it is sparse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM