R投资组合分析-二次效用最大化

时间:2018-06-25 14:07:54

标签: r-portfolioanalytics

我正在通过最大化通用二次效用函数(开始的风险厌恶度为2)来找到最佳投资组合。代码是:

library(PortfolioAnalytics)
library(ROI)
library(ROI.plugin.quadprog)
library(ROI.plugin.glpk)

pf1.1.1 <- portfolio.spec(assets = norm_tickers)
pf1.1.1 <- add.constraint(portfolio = pf1.1.1, type = "full_investment")
pf1.1.1 <- add.objective(portfolio = pf1.1.1, type = "quadratic_utility", risk_aversion = 2)
maxQU.opt.pf1.1.1 <- optimize.portfolio(R = pf1, portfolio = pf1.1.1, optimize_method = "ROI", trace = TRUE)
meanvar.ef.1.1.1 <- create.EfficientFrontier(R= pf1, portfolio = pf1.1.1, type = "mean-StdDev", risk_aversion = c(3,4,5))

最后一个代码返回错误:

Error in dimnames(x) <- dn : 
  length of 'dimnames' [2] not equal to array extent

我的问题是:如何通过追踪风险规避来找到有效的边界?

下面是pf1norm_tickers的一部分。我是R的新手,所以对这个问题的任何混乱表示很抱歉。

> dput(norm_tickers)
c("ASM", "BVH", "CII", "HBC", "HNG", "HPG", "HQC", "HSG", "PVD", 
"ROS")
>dput(head(pf1,3))
    new("timeSeries", .Data = structure(c(-0.0314499782077803, -0.0129856215312747, 
    0.00657823321247908, -0.0243902439024392, -0.00833333333333319, 
    0.00840336134453779, 0.00706747528771312, -0.00350893830907106, 
    -0.00352129431358561, 0.0106407283721972, 0.00350635858168036, 
    -0.017480120975666, -0.0571428571428572, 0.0454545454545456, 
    -0.0144927536231885, -0.00943524557333197, 0.00714479170242877, 
    0.0401860451023022, -0.0377358490566038, 0, 0.0196078431372551, 
    0.0227243188796646, -0.0199994440186334, -0.00906913697314515, 
    0.0155624703067552, 0.0383141923927932, -0.0147585299919633, 
    0.0634848577439828, 0.0671652205321007, 0.0699302313059131), .Dim = c(3L, 
    10L), .Dimnames = list(NULL, c("ASM", "BVH", "CII", "HBC", "HNG", 
    "HPG", "HQC", "HSG", "PVD", "ROS"))), units = c("ASM", "BVH", 
    "CII", "HBC", "HNG", "HPG", "HQC", "HSG", "PVD", "ROS"), positions = c(1473033600, 
    1473120000, 1473206400), format = "%Y-%m-%d", FinCenter = "GMT", 
        recordIDs = structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame"), 
        title = "Time Series Object", documentation = "Mon Jun 25 20:42:16 2018")

0 个答案:

没有答案