initial commit

This commit is contained in:
Steven Polley 2021-05-20 16:39:13 -06:00
parent d62d732f9a
commit 0c9a3b086d
2 changed files with 68 additions and 0 deletions

View File

@ -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 .

43
main.go Normal file
View File

@ -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)
}