Search code examples
optimizationoptaplannerportfolio

I want to add lower limit constraints in portfolio optimization in Optaplanner exercise


I want to add lower limit constraints in portfolio optimization in Optaplanner exercise.

In Portfolio optimization in Optaplanner, we can control ratio limit by controlling sector constraints, and can only control upper limit value which is given as Quantity Maximum.

I've tried 'add lower limit as Quantity Minimum, and change Hardscore by quantity minimum similarly as quantity maximum.' However, I failed to apply it.

Anyway, is there any better way to add lower limit constraints in portfolio optimization in Optaplanner?

Plz Help me!


Solution

  • If it's for example per region, just add quantityMillisMinimum field on Region:

    public class Region extends AbstractPersistable {
    
        private String name;
        private Long quantityMillisMaximum; // In milli's (so multiplied by 1000)
    
        // New field
        private Long quantityMillisMinimum; // In milli's (so multiplied by 1000)
    }
    

    and a score rule to add the hard constraint:

    // New rule
    rule "Region quantity minimum"
        when
            $region : Region($quantityMillisMinimum : quantityMillisMinimum)
            accumulate(
                AssetClassAllocation(region == $region, quantityMillis != null, $quantityMillis : quantityMillis);
                $quantityMillisTotal : sum($quantityMillis);
                $quantityMillisTotal < $quantityMillisMinimum
            )
        then
            scoreHolder.addHardConstraintMatch(kcontext,
                    $quantityMillisTotal - $quantityMillisMinimum);
    end
    

    Are you using portfolio optimization for anything serious? :)