我对R中的投资组合优化有疑问。我是R的新手,曾尝试研究并寻找答案,但不确定是否正确。我希望有人可以在这里帮助我。
我已经使用计量经济学模型从资产建模中获得了协方差矩阵(在这里,我使用DCC GARCH对资产收益进行建模)。进行预测后,我将获得协方差矩阵。那么,现在,如何使用fPortfolio软件包将此协方差矩阵用于投资组合优化?我发现的大多数示例仅使用资产收益来进行投资组合优化。但是,如果我们使用资产收益率的预测均值和方差-协方差来创建最佳资产分配模型,那又如何呢?
我有以下可复制的代码。
library(zoo) library(rugarch) library(rmgarch) data("EuStockMarkets") EuStockLevel <- as.zoo(EuStockMarkets)[,c("DAX","CAC","FTSE")] EuStockRet <- diff(log(EuStockLevel)) ## GARCH-DCC uspec = ugarchspec(mean.model = list(armaOrder = c(0,0)), variance.model = list(garchOrder = c(1,1), model = "sGARCH"), distribution.model = "norm") spec1 = dccspec(uspec = multispec( replicate(3, uspec) ), dccOrder = c(1,1), distribution = "mvnorm") fit1 = dccfit(spec1, data = EuStockRet, fit.control = list(eval.se=T)) #Forecasting dcc.focast=dccforecast(fit1, n.ahead = 1, n.roll = 0) print(dcc.focast) covmat.focast = rcov(dcc.focast) covmat = covmat.focast$`1975-02-03`[,,1] ##The Covariance matrix DAX CAC FTSE DAX 0.0002332114 0.0001624446 0.0001321865 CAC 0.0001624446 0.0001799988 0.0001139339 FTSE 0.0001321865 0.0001139339 0.0001372812
因此,现在我想将我获得的协方差应用于投资组合优化。
##Optimization (Use the forecasted variance covariance matrix!!!) ##You must convert your dataset into "timeSeries" object for R to be able to read it in fportfolio. library(fPortfolio) ##To compute efficient portfolio All.Data <- as.timeSeries(100* EuStockRet) ##Equal weight portfolio ewPortfolio <- feasiblePortfolio(data = All.Data,spec = ewSpec,constraints = "LongOnly") print(ewPortfolio) ##Minimum risk efficient portfolio minriskSpec <- portfolioSpec() targetReturn <- getTargetReturn(ewPortfolio@portfolio)["mean"] setTargetReturn(minriskSpec) <- targetReturn #Now, we optimize the portfolio for the specified target return :- minriskPortfolio <- efficientPortfolio(data = All.Data,spec = minriskSpec,constraints = "LongOnly") print(minriskPortfolio)
那么,实际上我们在哪里输入协方差矩阵?我做的正确吗?感谢任何人都可以在这里为我提供帮助。
谢谢!