#Nathan Fox #Homework 24 #I give permission for this file to be posted online ##Read old files read(`C24.txt`): #Help procedure Help:=proc(): print(` OptimalGamblingTerse(N,i,p,T) `): print(` ManyOptimalGambling(N,i,p,T,K) `): print(` BestKellyFactor(N,i,p,TimeIsMoney,resolution) `): print(` WhatKellyCharges(p,N,i) `): end: ##Problem 1 #OptimalGamblingTerse(N,i,p,T): does not tell you the story but #returns TWO outputs: #true (or false) if you came out alive (or dead) #A list of the intermediate probabilities (of length less than T #in the lucky case, and of length T in the sad case) OptimalGamblingTerse:=proc(N,i,p,T) local t,jake,coin,cc,L: L:=[]: cc:=i: t:=T: while cc>0 and cc0 do jake:=BestSDD(N,cc,p,t): L:=[op(L), jake[2]]: if jake[2]=0 then break: fi: coin:=LC(p): if coin then cc:=cc+jake[1]: else cc:=cc-jake[1]: fi: t:=t-1: od: if cc < N then return false,L: else return true,L: fi: end: ##Problem 2 #ManyOptimalGambling(N,i,p,T,K): runs OptimalGamblingTerse(N,i,p,T) #K times and returns TWO NUMBERS (in fractional form, if you want #floating point, use evalf) #the ratio of times the gambler came out alive #the "closest call", the lowest ever (intermediate) probability #of survival that ever showed up in the games that ended happily. ManyOptimalGambling:=proc(N,i,p,T,K) local closecall,wins,j,jake,pr: closecall:=1: wins:=0: for j from 1 to K do jake:=OptimalGamblingTerse(N,i,p,T): if jake[1] then wins:=wins + 1: for pr in jake[2] do if pr < closecall then closecall:=pr: fi: od: fi: od: wins/K, closecall: end: ##Problem 3 #ManyOptimalGambling(20,9,11/20,10,5000); #returned 0.5524000000, 0.07297623438 for me #BestSDD(20,9,11/20,10)[2]; #returned 0.5651360230 for me, which is 0.0127360230 more than #the ratio I found ##Problem 4 #BestKellyFactor(N,i,p,TimeIsMoney,resolution): inputs #N: the ultimate desired capital #i: your current capital #p: the probability of a succesfull one round (usually larger #than 1/2) #TimeIsMoney: the cost that you have to pay by playing a #single round #resolution: a small positive number (say 1/200) #tries out all the possible Kelly strategies, starting with #f=resolution, and then f=2*resolution, ..., and so on, all the #way to the bold scenario f=1, and finds the f that maximizes #(VGD(p,N,TiS(N))[i]-VGD(p,N,KeS(N,f)[i]))*TimeIsMoney -(VGW(p,N,TiS(N))[i]-VGW(p,N,KeS(N,f)[i]))*N #In other words you maximize the expected saving from exiting #the casino sooner than you would with timid play, take away #the expected extra loss due to your impatience and unwilling #to play the boring timid strategy. BestKellyFactor:=proc(N,i,p,TimeIsMoney,resolution) local val,champ,rec,maximizeMe,cand: maximizeMe:=proc(f) (VGD(p,N,TiS(N))[i]-VGD(p,N,KeS(N,f)[i]))*TimeIsMoney - (VGW(p,N,TiS(N))[i]-VGW(p,N,KeS(N,f)[i]))*N: end: champ:=resolution: rec:=maximizeMe(champ): for val from 2*resolution by resolution to 1 do cand:=maximizeMe(val): if cand > rec then champ:=val: rec:=cand: fi: od: champ: end: ##Problem 5 #WhatKellyCharges(p,N,i): finds out how much is TimeIsMoney when #f is Kelly's recommended value f=2*p-1 #The way this problem is phrased, I'm assuming you want a value #of TimeIsMoney that yields 2*p-1 as BestKellyFactor WhatKellyCharges:=proc(p,N,i) local j: for j from 0 to N do if 2*p-1 = BestKellyFactor(N,i,p,j,1/(2*denom(p))) then return j: fi: od: return FAIL: end: #WhatKellyCharges(11/20,20,10) returns FAIL #WhatKellyCharges(11/20,40,21) doesn't finish running #WhatKellyCharges(11/20,400,150) crashes Maple