Page 1 of 1
quadratic programming
Posted: February 18th, 2006, 3:18 pm
by jessie
A little stupid question: when we build up a portfolio, how can we impose the restriction that the weights lie within [0,1] (which means short stocks is not allowed), and the summation of the weights is equal to 1? How do we write the code? Any reference are highly appreciated. Thanks, jessie
quadratic programming
Posted: February 19th, 2006, 3:38 pm
by KackToodles
this sounds like a textbook problem.
quadratic programming
Posted: February 21st, 2006, 10:35 am
by jessie
yes, it is a quite stupid questions, however, I really have no idea how to write the code in Matlab. Any suggestions?
quadratic programming
Posted: February 21st, 2006, 9:54 pm
by Masjanja
Jessie,Check this:
http://root.cern.ch/root/html/examples/ ... o.C.htmlIt considers the case that you need: "no short selling".The code is intented to be used in ROOT (which you can download for free), and if you know C++ you shouldn't have any problem to understand it. In any case comments in the example can help you to write the code yourself in Matlab.Hope this helps,Masjanja.
quadratic programming
Posted: February 26th, 2006, 5:18 am
by cdmurray80
I have only once used a QP package in matlab but it took as input matrices of inequality and equality constraints. . Making the weights sum to 1 is adding a linear equality constraint that looks like thisEquality constraint: Ax=bA = [1,1,1,1,1,1,1...]b= [1]x = weights to solve forA is 1xN matrix of 1's, where N is the number of items in the portfolio.To keep the weights explicitly non zero, you could enter N inequality constraintsInequality constraint: Cx >= dd = [0;0;0;0;...]C = identity matrixx = weights to solve fordoes this help at all?
quadratic programming
Posted: February 26th, 2006, 5:19 am
by cdmurray80
There is also a minimization that minimizes the variance-covariance matrix times the vector of weights...sorry
quadratic programming
Posted: February 27th, 2006, 10:46 am
by damel
if you are using matlab, you can use these 2 following functions:- portcons: to impose your constraints in inequality equations; ( you have to create one matrix and one vector representing your right and left hands of inequality equations )- portopt: to implement the optimization.matlab offers more than one way to build portfolios. this is only one of them.see the attachment: is an excel file where I built a portfolio where you have 20 stocks on the short leg and 20 stocks on the long leg.the maximum weight on a single stock is 15% (both for long and short positions).the sum of the long weights cannot be more than 100%.the sum of the short weights cannot be more than 100%.if you need some more detail, you can see the help or contact me.