#=================================================================# # Finance and Insurance Engineering using R # by Sang-Heon Lee & Hosam Ki # # https://kiandlee.blogspot.com #—————————————————————–# # Portfolio Optimization using ROI NEOS #=================================================================# graphics.off() # clear all graphs rm(list = ls()) # remove all files from your workspace library(quadprogXT) # solveQPXT library(ROI) # ROI_solve library(ROI.plugin.neos) # NEOS #—————————————————– # Michuad dataset #—————————————————– setwd(“D:/SHLEE/blog/rneos/michuad”) # dataset in Michaud and Michaud (2007) appendix df.data – read.csv(‘mu_sd_corr_michaud.csv’) head(df.data) # mean, std, correlation mu – as.vector(df.data[,1]) sd – as.vector(df.data[,2]) corr – as.matrix(df.data[,–c(1,2)]) # number of asset nvar – length(mu) var.name – colnames(df.data[,–c(1,2)]) # convert correlation to covariance matrix cov – diag(sd)%*%corr%*%diag(sd) #—————————————————– # Portfolio optimization using solveQPXT #—————————————————– n.er – 100 # number of EF points rset – seq(min(mu),max(mu),length=n.er+2) rset – rset[2:n.er+1] # given returns and unknown std and weight port1.ret – rset port1.std – rset*0 port1.wgt – matrix(0,n.er,nvar) # ith portfolio problem setting i = 10; Dmat – 2*cov dvec – rep(0,nvar) #c(0,0) Amat – t(rbind(t(rep(1,nvar)),t(mu),diag(nvar))) bvec – c(1,rset[i],rep(0,nvar)) # mean-variance optimization m–solveQPXT(Dmat,dvec,Amat,bvec,meq=2,factorized=FALSE) … Read more