#===> obtain data <===#
data(stock99)
data(stock94Info)
mgm <- stockModel(stock99, drop=25, model='MGM', industry=stock94Info$industry)
#===> build optimal portfolios <===#
opMgm1 <- optimalPort(mgm)
opMgm2 <- optimalPort(mgm, Rf=0.004)
print(opMgm1)
summary(opMgm1)
#===> plot the optimal porfolios <===#
par(mfrow=c(1,2))
# these plots provide a "head coloring" of
# the allocation by optimalPort
plot(opMgm1)
plot(opMgm2)
#===> additional plotting 1 <===#
par(mfrow=c(1,1))
plot(opMgm1, addNames=TRUE)
#===> additional plotting 2 <===#
plot(opMgm1, optPortOnly=TRUE, colOP=2, pchOP=2)
points(opMgm2, colOP=2, pchOP=4)
#=====> Watch out -- choosing Rf too large causes errors <=====#
data(stock99)
data(stock94Info)
non <- stockModel(stock99, drop=25, model='none',
industry=stock94Info$industry)
portPossCurve(non)
opTemp <- optimalPort(non, Rf=-10^5)
points(opTemp)
## Error if Rf >= vertex (y value)
# optimalPort(non, 0.02)
# optimalPort(non, opTemp$R)
# optimalPort(non, opTemp$R+0.01)
# optimalPort(non, opTemp$R-0.01)
## May give error if Rf too close to vertex
# optimalPort(non, opTemp$R-0.0001)
Run the code above in your browser using DataLab