我正在尝试使用投资组合分析优化来最大化主动收益和最小化主动风险。使用此软件包有可能吗?我正在尝试最小化有效体重。.所以Min(Portw -Benchw)* Cov。有没有一种方法可以增加工作台重量作为目标函数的一部分?
这是我目前的代码。任何帮助将不胜感激!谢谢。
#this dataframe is the current benchmark weightings. i would like to
#specify my objective function so that i am minimizing the active risk, not
#total risk. is there a way to feed the benchmark weights into the
#add.objective function?
BenchWeight <- arrange(BenchWeight,Product)%>%
spread(Product,Weight)
#CovMatrix is a dataframe turned into xts object with 120 daily returns on
#various bond market sectors.
CovMatrix <- select(ExcessReturns, Date,Product,Excess_Returns_Daily)%>%
spread(Product,Excess_Returns_Daily)%>%
select(-Universal)%>%
arrange(desc(Date))%>%
slice(1:120)
optimdata <- xts(CovMatrix[,-1], order.by = CovMatrix[,1])
optimweight <- portfolio.spec(colnames(optimdata))
optimweight <- add.constraint(optimweight, type= "weight_sum", min_sum=0,
max_sum=1)
optimweight <- add.constraint(optimweight, type = "long_only")
optimweight <- add.objective(optimweight, type="return", name = "mean")
optimweight <- add.objective(optimweight, type = "risk",name = "StdDev",
target = 0.5)
optimweight1 <- optimize.portfolio(optimdata,optimweight, optimize_method
= "ROI")