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.

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

1 Answer 1


I haven't looked at your code yet, but here are two pointers:

  • $\begingroup$ That is not finding the tangency portfolio. It is just discretizing the returns space and plotting points of min variance on the graph. $\endgroup$
    – user862
    Aug 15, 2010 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.