Page 1 of 1
Optimal portfolio weights
Posted: Tue Dec 09, 2014 7:30 am
by ylijohtaja
Hi
It is easy enough to compute efficient frontiers given a set of return time series. However, I have not been able to find a way to store the optimal portfolio weights for the various points in the efficient frontier. How could this be implemented?
Cheers,
Re: Optimal portfolio weights
Posted: Tue Dec 09, 2014 9:20 am
by TomDoan
In (for instance)
PORTFOLIO.RPF, wouldn't a
COPY instruction applied to ERETS and the corresponding SRETS and/or SRETSRF series do it?
Re: Optimal portfolio weights
Posted: Tue Dec 09, 2014 9:51 am
by ylijohtaja
Yes, I did use PRINT(window='name') to get the erets and srets series already (so, I do get the efficient frontier points), but what I would need are the optimal portfolio weights for each asset for each expected return point - I apologize for being unclear in my first message.
Re: Optimal portfolio weights
Posted: Tue Dec 09, 2014 10:28 am
by TomDoan
In PORTFOLIO.RPF, you would need to add the lines in red to save the portfolio weights. This will create a VECT[SERIES] with n elements with each entry in that corresponding to the test value of ERETS. (The LQPROG instruction needs the X parameter to save the weights---the first LQPROG in the example doesn't, this one does, though in the original program, it doesn't actually use it for anything).
dec vect[series] pweights(n)
do i=1,n
set pweights(i) 1 101 = 0.0
end do i
*
do t=1,101
lqprog(noprint,q=omega,a=arf,b=erets(t)-rf,equalities=1) x
compute sretsrf(t)=sqrt(2.0*%funcval)
compute %pt(pweights,t,x)
end do t
Re: Optimal portfolio weights
Posted: Fri Dec 12, 2014 7:45 am
by ylijohtaja
This works well - many thanks!
Re: Optimal portfolio weights
Posted: Sun Feb 13, 2022 5:07 am
by Baroni77
Hi Tom,
how would you efficiently modify the code so that instead of minimising variance s.t. target expected return, you maximise the Sharpe Ratio and pull out those weights?
Many thanks
TomDoan wrote:In PORTFOLIO.RPF, you would need to add the lines in red to save the portfolio weights. This will create a VECT[SERIES] with n elements with each entry in that corresponding to the test value of ERETS. (The LQPROG instruction needs the X parameter to save the weights---the first LQPROG in the example doesn't, this one does, though in the original program, it doesn't actually use it for anything).
dec vect[series] pweights(n)
do i=1,n
set pweights(i) 1 101 = 0.0
end do i
*
do t=1,101
lqprog(noprint,q=omega,a=arf,b=erets(t)-rf,equalities=1) x
compute sretsrf(t)=sqrt(2.0*%funcval)
compute %pt(pweights,t,x)
end do t
Re: Optimal portfolio weights
Posted: Mon Feb 14, 2022 12:41 pm
by TomDoan
Based upon the second analysis (with the risk-free asset):
lqprog(q=omega,a=arf,b=1.0,equalities=1) y
compute x=y/%sum(y)
which minimizes the variance for a given mean, then renormalizes the weights to sum to 1.