[R-SIG-Finance] Constrained portfolio optimization with DEoptim

Brian G. Peterson brian at braverock.com
Tue Oct 4 14:01:53 CEST 2016


On Tue, 2016-10-04 at 13:04 +0200, Kristian Lind wrote:
> Hi guys,
> 
> I’m working on a portfolio optimization problem
> 
> The problem I’m trying to solve is of the form Min risk s.t. return = X
> 
> For each asset I have simulated 1000 paths for the development in asset
> prices over 10 years.
> 
> The risk measure I’d like to minimize is YoY shortfall risk, but could be
> any risk metric that takes the information from the scenarios into
> consideration.
> 
> Likewise, the return is the mean annualized return over all the scenarios.
> 
> I have tried solving this problem using DEoptim, where deviations from the
> required return is penalized. Similar to the approach applied here:
> https://cran.r-project.org/web/packages/DEoptim/vignettes/
> DEoptimPortfolioOptimization.pdf
> 
> I am unable to achieve convergence where the constraint is fulfilled.
> 
> My object function is of the form
> 
> Obj <- function(Return data, portfolio weights, target return){
> 
> Normalize weights to 1
> calculate portfolio return
> calculate risk metric
> calculate deviation from target return
> return (risk metric + deviation from target return*1e6)
> 
> }
> 
> Any pointers on how to formulate and solve this problem would be much
> appreciated.

You haven't provided a reproducible example, making it hard to help you.

You can easily do this type of optimization with PortfolioAnalytics,
including the use of DEoptim, pso, GenSA, or random search as a global
solver.  The modular objective function of PortfolioAnalytics should
allow you to specify your problem pretty easily.  You'll need to pass in
your 'scenarios', and use functions in your objective that expect this
data and know how to apply weights to it, but that should be pretty
simple.

To get to a general answer to your question, you need to determine a few
things.

Is there a solution that meets your constraints?  Many portfolios are
over-constrained, and are unable to meet the objectives as defined.  In
these cases you need to be able to relax constraints to get to the
closest solution.  It often helps to plot the unconstrained and
constrained feasible spaces (e.g. with random portfolios from
PortfolioAnalytics) to see if you've overconstrained things.  

You don't appear to be using 'fnMap' to apply your full investment
(cardinality) constraint.  Using this tells DEoptim what the final
parameter values were, and doesn't hide them inside your custom
objective.

You're attempting to perform a penalized optimization with:

return (risk metric + deviation from target return*1e6)

Is this the right weighting/penalty between your objectives? Typically,
if you have no significant preference between your objectives, you want
to use a multiplier first to get them to similar overall scale.  Then
you want to separately penalize (with a large multiplier) deviation from
your constraint.  In this case, you are penalizing overshooting and
missing below the return in the same way.  This will give the optimizer
very little indication on direction to improve the solution.  It can
also make sense to plot the path the optimizer takes to see if you're
getting close to a solution.

Your use of 'scenarios' could be messing you up.  DEoptim permutes
'parameters', which are typically weights in portfolio optimization
space.  It then applies the objective function passing the parameters
into the objective. You've said that you're using a annualized mean
across the scenarios and an annualized shortfall risk across the
scenarios.  You're losing quite a lot of dimensionality by reducing 1000
scenarios on each asset to one number.  Doing simple linear combinations
of these will not take things like covariances into account, even though
by saying that you care about shortfall risk, I'd assume what you really
want is *portfolio* shortfall.  I would be concerned that the loss of
dimensionality suggested by your description would make it difficult to
get a realistic solution.   

There are several more things that could cause this to fail to converge.
I've covered the most likely ones, but further investigation would
require a reproducible example.

Regards,

Brian


-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list