LIVE·WAITING…
connecting to the live quote stream…
--:--:--UTC
#40
Kelly fraction
easyTradingacceptance —~15 min
Implement kelly_fraction(p, b) — the Kelly criterion for a bet that wins with probability p and pays b to 1: f* = (p·b - (1 - p)) / b. When the edge is negative the right size is zero — never a short position in your own bankroll — so clamp the result at 0.
Kelly is the size that maximises long-run growth; anything above it grows slower and swings harder, which is why practitioners bet half of it. The workbench's Kelly bot shows both. Return the fraction rounded to 4 decimal places.
example 1
input
p=0.55, b=1.0
output
0.1
example 2
input
p=0.45, b=1.0
output
0
note
A coin that loses 55% of the time at even money — the right size is nothing.
constraints
- 0 ≤ p ≤ 1
- b > 0
teacher · 3 hints · the first is free
↗ read the theory
the chapter this problem is cut from
▶ open in the workbench
run the same math on a real tape
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to kelly_fraction()
p=0.55, b=1.0
expected
0.1
the judge calls kelly_fraction() with exactly these inputs · outputs are compared to 6 decimal places
● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice