FindMaximum/NMaximize vs. Excel Solver

*To*: mathgroup at smc.vnet.net*Subject*: [mg106714] FindMaximum/NMaximize vs. Excel Solver*From*: John <jhurley13 at gmail.com>*Date*: Thu, 21 Jan 2010 04:57:20 -0500 (EST)

FindMaximum/NMaximize vs. Excel Solver I am looking at a simple model that calculates the best wagers to place on a set of 20 horses, where the goal is to maximize reward vs. risk. Since the bets need to be constrained, I can't use NMaximize. The probabilities are the "real" probabilities of the horses winning; odds are what would be available at the track. I have working versions in Excel and Mathematica, but the Mathematica implementation runs twice as slowly, and it seems that there must be a more elegant way to do it. The examples I've seen for FindMaximum use 3 or fewer variables and list them explicitly. I am mostly interested in understanding if this is the Mathematica way of doing this problem (as opposed to finding a really fast way to bet on horses). solveHorse[]:=Module [{probabilities,odds,totalWager=100,vars,f,inRange,sol}, probabilities={0.2,0.2,0.2,0.2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.1,0.1}; odds={7,5,5,5,5,5,5,5,5,5,5,5,5,5,1,1,2,2,2,2}; inRange[x_]:=0<=x<=totalWager; f[a__Symbol]:=Module[{ep,var,ws,sp}, ws=List[a]; ep=MapThread[(#1*(1+#2)-totalWager)&,{ws,odds}]; sp= Dot[probabilities,ep]; var=((#-sp)^2)&/@ep; sp/Sqrt[Dot[probabilities,var]] ]; (* 23.08,25.64,25.64,25.64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.0,0.0 <-- Excel answer*) vars=Table[ToExpression["x"<>ToString[i]],{i,1,20}]; sol=FindMaximum[{f[vars]/.List->Sequence, (And@@inRange/@vars) && Total[vars]==totalWager }, vars,AccuracyGoal->6,PrecisionGoal->9,MaxIterations->1000]; Print["Final Rtn/SD: ",First[sol]]; If[#<10^-6,0,#]&/@vars/.Last[sol] ]; Timing[solveHorse[]] Final Rtn/SD: 0.444878 {5.28921, {23.0767,25.6411,25.6411,25.6411,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}