# hw24.mpl Thu Apr 25 2013 # Vaibhav Verma # You can post this online read `/home/vverna/programs/em13/C24.mpl`; # N is the capital you want to come up with. # T is the number of rounds. # i is your current capital # p is the probability of winning a round OptimalGamblingTerse := proc(N, i, p, T) local jake, cc, coin, t, result: cc := i: t := T: result := []: while cc > 0 and cc < N and t > 0 do: jake := BestSDD(N, cc, p, t): result := [op(result), 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 <= 0 or t=0 or jake[2] = 0 then return false, result: fi: if cc >= N then return true, result: fi: end: #ManyOptimalGambling(N, i, p, T, K) ManyOptimalGambling := proc(N, i, p, T, K) local x, success, closest, result, smallest: success := 0: closest := 1: for x from 1 to K do: result := OptimalGamblingTerse(N, i, p, T): if result[1] = true then success := success + 1: smallest := min(result[2]): if smallest < closest then closest := smallest: fi: fi: od: return success / K, closest: end: # ManyOptimalGambling(20, 9, 11/20, 10, 5000)[1] # > 0.4728000000 # # BestSDD(20, 9, 11/20, 10)[2] # > 0.5651360230 # # These probabilities seem off to me. BestKellyFactor := proc(N, i, p, TimeIsMoney, resolution) local f, champ, rec, champf: champ := 0: champf := resolution: f := resolution: while f <= 1 do: rec := 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: if rec > champ then champ := rec: champf := f: fi: f := f * 2: od: return champf: end: