/* Portfolio optimization in Picat. From Xpress-Model example foliolp.mos http://examples.xpress.fico.com/example.pl?id=mosel_model_10 Solution: frac:[30, 0, 20, 0, 7, 30, 0, 0, 13, 0] return: 1399 This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import mip. % 0.003s % import sat. % 8.3s % import cp. % 80s! main => go. go => nolog, Shares = 1..10, Risk = [2,3,4,9,10], % set of high-risk values among shares NA = [1,2,3,4], % set of shares issues in N.-America Ret = [5,17,26,12,8,9,7,6,31,21], % estimated return in investment NumShares = Shares.length, % decision variables Frac = new_array(NumShares), Frac :: 0..100, % fractions; multiply by 100 since we use integers. Return #= sum([Ret[S]*Frac[S] : S in Shares]), % Limit the percentage of high-risk values sum([Frac[S] : S in Risk]) #<= 33, % 1/3 % Minimum amount of North-American values sum([Frac[S] : S in NA]) #>= 50, % 0.5 % Spend all the capital sum([Frac[S] : S in Shares]) #= 100, % Upper bounds on the investment per share foreach(S in Shares) Frac[S] #<= 30 % 0.3 end, println(solve), solve($[ffc,split,max(Return),report(printf("Return: %w\n",Return))], Frac), println(return=Return), println(frac=Frac), nl.