*
* PORTFOLIO.RPF
* Portfolio optimization calculations.
*
* RATS User's Guide, from Section 13.2
*
open data berndt.xls
calendar(m) 1978
data(format=xls,org=columns) 1978:1 1987:12 mobil ibm weyer citcrp market rkfree
*
* Compute the covariance matrix of returns into omega. Save the means as
* mu.
*
vcv(center,matrix=omega)
# mobil ibm weyer citcrp
*
compute n=%nvar
compute mu=%meanv
compute [rect] ones=%fill(1,n,1.0)
*
* Compute the minimum variance portfolio, and its expected return. All
* the analysis is constraining portfolios to non-negative weights. If
* you want to allow short positions, add the NNEG=0 option to LQPROG.
*
lqprog(q=omega,a=ones,b=1.0,equalities=1) x
compute minr=%dot(x,mu)
*
* Choose as upper limit the highest expected return.
*
compute maxr=%maxvalue(mu)
*
* Create a grid series for expected values running from minr to maxr
*
set erets 1 101 = minr+(maxr-minr)*.01*(t-1)
set srets 1 101 = 0.0
*
* Find the minimum variance portfolio with the expected return erets(t).
* Note - the problem being solved is to min .5 x'Qx subject to the
* constraints. To get the variance (rather than .5 variance), we need to
* multiply the optimized value by 2.
*
do t=1,101
lqprog(noprint,q=omega,a=ones~~tr(mu),b=1.0~~erets(t),equal=2)
compute srets(t)=sqrt(2.0*%funcval)
end do t
scatter(style=lines,$
header="Efficient Frontier w/o Risk-Free Asset",$
vlabel="Expected Return",$
hlabel="Sigma")
# srets erets
*
* With riskfree asset. There's no longer a constraint that the weights
* on the portfolio sum to one. Instead, the expected return constraint
* is altered to weights * (mu-Rf) = target return - Rf.
*
stats(noprint) rkfree
compute rf=%mean
set sretsrf 1 101 = 0.0
compute [rect] arf=tr(mu)-rf
do t=1,101
lqprog(noprint,q=omega,a=arf,b=erets(t)-rf,equalities=1) x
compute sretsrf(t)=sqrt(2.0*%funcval)
end do t
*
scatter(style=lines,$
header="Efficient Frontier with Risk-Free Asset",$
vlabel="Expected Return",$
hlabel="Sigma") 2
# srets erets
# sretsrf erets