From 0c9a3b086d30a5a1498c1a4c5db3238df4153913 Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Thu, 20 May 2021 16:39:13 -0600 Subject: [PATCH] initial commit --- README.md | 25 +++++++++++++++++++++++++ main.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 main.go diff --git a/README.md b/README.md index 3e12a20..04af4b9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,27 @@ # kelly-paper-experiment +If you start with $100 balance, and you make a bet with a 70% chance of winning. If you win, you get $80. If you lose, you lose $80. + +Do you take the bet? Even more interesting, if you could keep repeating this bet over and over again, always betting 80% of your balance, should you do it? + +It makes sense, right, the odds are in your favor! + +### The actual answer - if you want to go broke, then yes + +This blew my mind, how counter-intuitive the answer to this question actually is. + +This program runs 16 simulations where you start with a balance of 100 currencies. You make consecutive bets, always betting 80% of your total balance with a 70% chance of winning each bet. It then reports the results after ONLY 200 bets. The result is the percentage of your returns (your end balance divided by your starting balance). + +In other words, given enough time, we're all screwed. + +### Reference Video + +[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/91IOwS0gf3g/0.jpg)](https://www.youtube.com/watch?v=91IOwS0gf3g) + + +### How to build this program yourself + +1. Install go - https://golang.org/dl/ +2. Clone - git clone https://deadbeef.codes/steven/kelly-paper-experiment.git +3. Build - cd kelly-paper-experiment && go build . + diff --git a/main.go b/main.go new file mode 100644 index 0000000..0d1e059 --- /dev/null +++ b/main.go @@ -0,0 +1,43 @@ +package main + +import ( + "fmt" + "math/rand" + "time" +) + +func main() { + rand.Seed(time.Now().UTC().UnixNano()) + + var balance, investedPercentage, winningPercentage float64 + balance = 100 + investedPercentage = 0.80 + winningPercentage = 0.70 + discreteCompoundingPeriods := 200 + numSimulations := 16 + outputChannel := make(chan float64) + + for i := 0; i < numSimulations; i++ { + go simulation(balance, investedPercentage, winningPercentage, discreteCompoundingPeriods, outputChannel) + } + + for i := 0; i < numSimulations; i++ { + fmt.Println(<-outputChannel) + } + +} + +func simulation(startingBalance, investedPercentage, winningPercentage float64, discreteCompoundingPeriods int, outputChannel chan float64) { + balance := startingBalance + for i := 0; i < discreteCompoundingPeriods; i++ { + investedAmount := balance * investedPercentage + if rand.Float64() <= winningPercentage { + // you win + balance += investedAmount + } else { + // you lose + balance -= investedAmount + } + } + outputChannel <- (balance / startingBalance) +}