# Portfolio Optimization

2 messages
Open this post in threaded view
|

## Portfolio Optimization

 Hi, I'm an R newbie and I've been struggling with a optimization problem for the past couple of days now. Here's the problem - I have a matrix of expected payouts from different stock option strategies. Each column in my matrix represents a different stock and each row represents the return to the strategy given a certain market move. So the rows are not a time series of percentage returns but a dollar payout in different expected scenarios, i.e. Expected Return Matrix (ER) =                   stock1   stock2  .... stockn                                                scenario1   \$              \$               \$                                                scenario2   \$              \$               \$                                                scenario3   \$              \$               \$                                                    ... I want to create an optimal portfolio of these strategies by applying a vector of weights. The weights will be the number of contracts of each to buy and won't be a percentage weighting. There are a few constraints I need it comply with:    - The weights have to be integers    - The minimum portfolio return (ER* Weights) across the scenarios has to    be greater than some negative number I specify    - There has to be a certain minimum number of stocks in the portfolio so    length(weights)>some number I specify. Any help is GREATLY appreciated since I have tried so many different functions and packages. Even if someone can just lead me to the correct function to use that would be a great help as I've looked at optim, solveLP, ROI package and many others. Thanks, S         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Portfolio Optimization

 I would be biased towards using a heuristic, for instance Threshold Accepting (TA), for solving such a problem. (TA is implemented in package NMOF. Disclosure: I am the author of that package.) But you will not find a ready-to-use solution there. (1) you need an objective function, ie, a function that maps a given vector of holdings (and data like your scenario matrix) into a real number; the better the portfolio, the lower the number. (2) For TA, you need a so-called neighbourhood function. That is a function that changes one portfolio vector into another, by changing some elements. Examples for simple neighbourhoods are in the package vignettes. Do you have a budget constraint? If yes, and you want to work with integers, I would suggest using a "cash" variable. (See, eg, Algorithm 3 in http://www.swissfinanceinstitute.ch/rp20.pdf ) (3) The constraints can, at least in a first round, be included through penalties. Regards, Enrico PS. There is a mailing list dedicated to finance-with-R questions, and you may get better answers there. https://stat.ethz.ch/mailman/listinfo/r-sig-finance-- Enrico Schumann Lucerne, Switzerland http://nmof.net/Am 13.01.2012 17:06, schrieb Sal Pellettieri: > Hi, > > I'm an R newbie and I've been struggling with a optimization problem for > the past couple of days now. > > Here's the problem - I have a matrix of expected payouts from different > stock option strategies. Each column in my matrix represents a different > stock and each row represents the return to the strategy given a certain > market move. So the rows are not a time series of percentage returns but a > dollar payout in different expected scenarios, i.e. > > Expected Return Matrix (ER) =                   stock1   stock2  .... stockn >                                                 scenario1   \$              \$ >                \$ >                                                 scenario2   \$              \$ >                \$ >                                                 scenario3   \$              \$ >                \$ >                                                     ... > > I want to create an optimal portfolio of these strategies by applying a > vector of weights. The weights will be the number of contracts of each to > buy and won't be a percentage weighting. There are a few constraints I need > it comply with: > >     - The weights have to be integers >     - The minimum portfolio return (ER* Weights) across the scenarios has to >     be greater than some negative number I specify >     - There has to be a certain minimum number of stocks in the portfolio so >     length(weights)>some number I specify. > > Any help is GREATLY appreciated since I have tried so many different > functions and packages. Even if someone can just lead me to the correct > function to use that would be a great help as I've looked at optim, > solveLP, ROI package and many others. > > > Thanks, > S > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.