# Tangency portfolio in R

I am trying to solve for an efficient portfolio in R. How do I translate my constraints for a tangency point for 2 risky asset portfolio, and a given risk free rate to R solve.QP function? So basically I have the following equations:

w = weight of the first risky asset
R1 = mean return of the first risky asset
R2 = mean return of the second risky asset
sd1 = sdev of first risky asset
sd2 = sdev of second risky asset
corr = correlation between two risky assets
rf = risk free rate
Return of portfolio, R = R2*(1-w)+R1*w
Standard Dev of portfolio, SD = sqrt((sd1*w)^2+(sd2*(1-w))^2+2*w*(1-w)*corr*sd1*sd2)

Now I need to maximize R-rf while minimizing SD (that is maximize my sharpe).
Let sigma be covariance matrix. So my function to minimize is W^T*sigma*W where W is
the weights vector. Now simulataneously I need to maximize the excess return (R-rf)
and W^T*1=1. I don't know how to express that in the constraints function.


I am confused how to express these constraints as expected by http://pbil.univ-lyon1.fr/library/quadprog/html/solve.QP.html . If you could also point me to a solved derivation of the final formula, that would be helpful as well as I am unable to get to the final formula.

• The link you gave points to your own machine - 127.0.0.1 Aug 15, 2010 at 7:00
• @csgillespie Fixed.
– user88
Aug 15, 2010 at 8:41
• You should ask on quant.stackexchange.com. Jul 1, 2011 at 6:51