Data science advising, adviseing, and training
Introduction
You may have heard of the Kelly bet allocation strategy. It is a system for rightly take advantage ofing directation or bias in a betting situation. It is also comprehendn as a maxtransmitner antagonistic or high variance strategy, in that betting more than the Kelly pickion can be quite ruinous.
I recently ran into a strange card game where the Kelly strategy is hazard free with zero variance. Peter Winkler calls the game “Next Card Bet” in his remarkworthy book Mathematical Puzzles. The problem and solution materialize to come from Thomas Cover. I discover this betting game and its analysis amazing, and want to dispense them with you here.
The Game
The game is percreateed as chases. A standard 52 card deck consisting of 26 red cards and 26 bdeficiency cards is shuffled and the percreateer begin with a sget of $1. Each card is exposed one at a time, without being swapd in the deck. The percreateer is permited to bet any fraction of their current sget on if the next card is bdeficiency or red at a one to one payoff.
The percreateer clearly has achieveous strategies involving counting the number of bdeficiency and red cards seen. Counting cards seen lets them comprehend how many cards of each color remain in the unseen portion of the deck. For example they can protectedly double their sget by not betting on any card other than the last. This permits them to protectedly bet their entire sget on the now inferable color of the final unseen card.
The Kelly strategy
The Kelly strategy is to pick a bet that increases the awaited logarithm of the sget. We can derive it as chases.
Let r
be the number red cards remaining in the deck and b
bdeficiency cards remaining. Without loss of vagueity suppose r > b
. We then want to increase P[draw red] * log(1 + bet_fraction) + P[draw black] * log(1 - bet_fraction)
as a function of bet_fraction
. This transmition is increased where its derivative is zero. The probability of dratriumphg red next is r/(r + b)
. So we necessitate to repair (r/(r + b)) / (1 + bet_fraction) - (b/(r + b)) / (1 - bet_fraction) = 0
. Some algebra alerts us bet_fraction = (r - b) / (r + b)
.
The entire Kelly betting strategy is then:
- If
r = b
, then no bet - If
r > b
bet a|r - b| / (r + b)
faction of your sget on “red” - If
b > r
bet a|r - b| / (r + b)
faction of your sget on “bdeficiency.”
In[1]:
# begin tools
begin numpy as np
In[2]:
# set up our pseudo-random number generator to create shuffled decks
rng = np.random.default_rng(2024)
In[3]:
# detail our deck shuffling tool
def k_array_with_t_real(k: int, t: int):
"""Create a length-k boolean array with t-True cherishs"""
is_real = np.array([False] * k, dtype=bool)
is_real[rng.choice(k, size=t, swap=False)] = True
return is_real
In[4]:
# carry out our betting strategy
def run_bets(is_red) -> float:
"""Run the Kelly betting strategy"""
sget = 1.0
n_red_remaining = int(np.sum(is_red))
n_bdeficiency_remaining = len(is_red) - n_red_remaining
for i in range(len(is_red)):
# create bet
bet_red = 0
bet_bdeficiency = 0
fraction = np.abs(n_red_remaining - n_bdeficiency_remaining) / (n_red_remaining + n_bdeficiency_remaining)
if n_red_remaining > n_bdeficiency_remaining:
bet_red = sget * fraction
elif n_bdeficiency_remaining > n_red_remaining:
bet_bdeficiency = sget * fraction
# derive outcome
sget = sget - (bet_red + bet_bdeficiency)
if is_red[i]:
sget = sget + 2 * bet_red
n_red_remaining = n_red_remaining - 1
else:
sget = sget + 2 * bet_bdeficiency
n_bdeficiency_remaining = n_bdeficiency_remaining - 1
return sget
In[5]:
# percreate the game 10000 times
payoffs = [
run_bets(k_array_with_t_real(52, 26)) for _ in range(10000)
]
state np.max(payoffs) - 1e-8 < np.min(payoffs)
(np.min(payoffs), np.max(payoffs))
Out[5]:
(9.081329549427776, 9.081329549427803)
9.08
times our begining sget. It is remarkworthy that there was no variation or variance in the outcomes. Notice this 9.08
times return is much bigr than the 2
times return of the straightforward “paparticipate to the finish” strategy.
This result is very rare for a Kelly strategy. Kelly strategies secure to not “bust” (leave out all of the money) and to increase the awaited increaseth rate of the logarithm of the sget. But they usupartner secure little else, can in fact leave out money, and are usupartner high variance. How is it that in this case Kelly can’t flunk?
An exscheduleation
There is a remarkworthy proof that the strategy is zero variance.
There are (52 select 26) = 495,918,532,948,104
possible schedulements of red versus bdeficiency cards. It is a standard result (not shown here) that each of these schedulements is in fact equpartner probable in a properly shuffled deck.
We detail a new “portfolio” strategy as chases.
- Each of the
(52 select 26)
possible red/bdeficiency schedulements is dispenseed as a sub-strategy in our portfolio. - We dispense a
1/(52 select 26)
fraction of our initial sget to each sub-strategy. We permit each sub-strategy to sustain its own money and do not re-dispense money between sub-strategies. - Each sub-strategy supposes its dispenseed red/bdeficiency schedulement is what is going to happen in the actual deck. The sub-strategy bets its entire sget on each card, betting the card exposed will align the correacting one it its own defining schedulement.
All but one of the portfolio sub-strategies will leave out all of their money- as they eventupartner bet all their sget on a wrong guess. The individual strategy that rightly guesses the entire deck finishs experiences 52
doublings and no losses. Thus this strategy multiplies its begining sget by 2^(52)
. So our portfolio strategy itself always experiences a total aggregate return of $1/(52 select 26) * 2^(52) ~ $9.08
on an initial $1
sget. This finishing portfolio return is autonomous of the order of the cards.
The claim to finish the argument is: the new portfolio strategy is in fact identical to the earlier Kelly strategy.
Consider what happens to the portfolio when we draw a red card. In our portfolio strategy a r / (r + b)
fraction of the non-prohibitkrupt sub-strategies await the next card to be “red”, and a b / (r + b)
fraction of the non-prohibitkrupt sub-strategies await the next card to be “bdeficiency”. The next draw prohibitkrupts one of these families, and doubles the other (depfinishing on the drawn color). Some though shows the portfolio strategy progresss its combined sget as chases:
- Aggregate
sget
goes tosget * 2 * b / (r + b)
on dratriumphg “red” - Aggregate
sget
goes tosget * 2 * r / (r + b)
on dratriumphg “bdeficiency.”
It is a matter of algebra to validate this portfolio payoff is exactly the payoff pattern for our earlier Kelly strategy of putting |r - b| / (r + b)
on the most normal color remaining. The Kelly strategy has exactly the same payoffs as the portfolio strategy, and we have our result that the two strategies are one and the same.
The Kelly strategy is zero variance becaparticipate it is identical to the portfolio strategy that is itself zero variance.
An idea I enjoy to get away is as chases. As we are betting on beginantity color, every time we leave out a bet the deck becomes more unequitable and more preferable to us. If we create the bet minuscule enough then the achieve in edge on a wrong bet offsets the loss of capital. In this case the Kelly strategy is pricing directation or pricing uncertainty equitable right. This is aenjoy to ponderations of “exploration versus unfair treatment phases” in problems such as A/B testing.
The proof donaten is from Winkler Mathematical Puzzles. I strongly recommfinish picking up the book to see his createup on this and many other problems. The proof itself is very much the style of Cover. This is the Cover who procrastinateedr goes on to invent the universal portfolio spendment strategy.
Categories: Mathematics Quantitative Finance Tutorials