Lua Source demonstration of using Kelly Criteria to figure out appropriate amount to risk for any single trade based on your current capital, odds of winning and win versus loss payout.
Risking the full portion recommended by Kelly Criteria is considered too risky by many investors. Those investors tend to chose to invest 1/2 or 1/3 of what the Kelly formula recommends Ed Thorp’s white paper discusses the impact on capital growth when trading partial Kelly.
No Promises, No Warranty, Please use this as only an example and and independently confirm that it is producing the desired results.
Kelly % = W – [(1 – W) / R] W = Probability of winning 0.0 to 1.0 R = Payout ratio 0.0 to 1.0
Lua Kelly Criteria Source
function round4(anum) return math.floor(anum * 10000) / 10000 end function kelly_invest(bankroll, winProb, oddsRatio) local lossProb = 1 - winProb local kellyPerc = winProb - ((1 - winProb) / oddsRatio) local recomendInvest = bankroll * kellyPerc return kellyPerc, recomendInvest end function odds_ratio(avgOnWin, avgOnLoss) return avgOnWin / avgOnLoss end function test_kelly() function kelly_testp(bankroll, winProb, oddsRatio) kp, ri = kelly_invest(bankroll, winProb, oddsRatio) print( "kelly -- bankroll=" .. bankroll .. " winProb=" .. winProb .. " oddsRatio=" .. round4(oddsRatio) .. " Kelly Ratio=" .. round4(kp) .. " Kelly Investment=" .. round4(ri) ) end -- Convert our Average Win / Loss to a Payout local avgWin = 185.32 local avgLoss = 210.13 local odr = odds_ratio(avgWin,avgLoss) print("avgWin=" .. avgWin .. " avgLoss=" .. avgLoss .. " oddsRatio=" .. round4(odr)) -- Calcuate Kelly Investment for some test conditions kelly_testp(1000, 0.56, odr) kelly_testp(1000, 0.71, odr ) kelly_testp(1000, 0.71, 1.2) kelly_testp(1000, 0.71, 0.7) kelly_testp(1000, 0.60, 1.0) end test_kelly()
-
See Also
- http://www.valueinvestingworld.com/2013/05/ed-thorp-jack-schwager-and-kelly.html
- http://www.edwardothorp.com/sitebuildercontent/sitebuilderfiles/Column23understandingthekellycriterion.doc
- http://www.investopedia.com/articles/trading/04/091504.asp
- http://www.elem.com/~btilly/kelly-criterion/
- http://www.albionresearch.com/kelly/default.php
Thanks Joseph Ellsworth
Contact Us
This is nice, I do some Lua for server side Redis. Thanks.