Serving the Quantitative Finance Community

 
User avatar
jessie
Topic Author
Posts: 0
Joined: February 7th, 2006, 12:43 pm

quadratic programming

February 18th, 2006, 3:18 pm

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
 
User avatar
KackToodles
Posts: 0
Joined: August 28th, 2005, 10:46 pm

quadratic programming

February 19th, 2006, 3:38 pm

this sounds like a textbook problem.
 
User avatar
jessie
Topic Author
Posts: 0
Joined: February 7th, 2006, 12:43 pm

quadratic programming

February 21st, 2006, 10:35 am

yes, it is a quite stupid questions, however, I really have no idea how to write the code in Matlab. Any suggestions?
 
User avatar
Masjanja
Posts: 0
Joined: April 9th, 2003, 8:59 pm

quadratic programming

February 21st, 2006, 9:54 pm

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.
 
User avatar
cdmurray80
Posts: 0
Joined: November 30th, 2005, 3:28 am

quadratic programming

February 26th, 2006, 5:18 am

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?
 
User avatar
cdmurray80
Posts: 0
Joined: November 30th, 2005, 3:28 am

quadratic programming

February 26th, 2006, 5:19 am

There is also a minimization that minimizes the variance-covariance matrix times the vector of weights...sorry
 
User avatar
damel
Posts: 3
Joined: January 8th, 2006, 12:02 pm

quadratic programming

February 27th, 2006, 10:46 am

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.
Attachments
PortCons.zip
(5.27 KiB) Downloaded 73 times
Last edited by damel on February 26th, 2006, 11:00 pm, edited 1 time in total.