Compare commits
2 Commits
ea278caa3d
...
a6a06adb69
Author | SHA1 | Date | |
---|---|---|---|
a6a06adb69 | |||
adad0973f9 |
@ -12,8 +12,6 @@ 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).
|
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.
|
|
||||||
|
|
||||||
### Output
|
### Output
|
||||||
|
|
||||||
Notice the e-n at the end... these are very small numbers, with only one simulation winning out with 24441% return based on the original balance.
|
Notice the e-n at the end... these are very small numbers, with only one simulation winning out with 24441% return based on the original balance.
|
||||||
@ -35,6 +33,8 @@ Notice the e-n at the end... these are very small numbers, with only one simulat
|
|||||||
* 7.788708234095218e-09
|
* 7.788708234095218e-09
|
||||||
* 0.0041392388926358116
|
* 0.0041392388926358116
|
||||||
|
|
||||||
|
In other words, given enough time, we're all screwed.
|
||||||
|
|
||||||
### Reference Video
|
### Reference Video
|
||||||
|
|
||||||
[](https://www.youtube.com/watch?v=91IOwS0gf3g)
|
[](https://www.youtube.com/watch?v=91IOwS0gf3g)
|
||||||
|
23
main.go
23
main.go
@ -7,37 +7,46 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// Random seed based on time when program runs
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
|
|
||||||
var balance, investedPercentage, winningPercentage float64
|
// Initialize variables
|
||||||
balance = 100
|
var startingBalance, investedPercentage, winningPercentage float64
|
||||||
|
startingBalance = 100
|
||||||
investedPercentage = 0.80
|
investedPercentage = 0.80
|
||||||
winningPercentage = 0.70
|
winningPercentage = 0.70
|
||||||
discreteCompoundingPeriods := 200
|
discreteCompoundingPeriods := 200
|
||||||
numSimulations := 16
|
numSimulations := 16
|
||||||
outputChannel := make(chan float64)
|
outputChannel := make(chan float64)
|
||||||
|
|
||||||
|
// Start simulations
|
||||||
for i := 0; i < numSimulations; i++ {
|
for i := 0; i < numSimulations; i++ {
|
||||||
go simulation(balance, investedPercentage, winningPercentage, discreteCompoundingPeriods, outputChannel)
|
go simulation(startingBalance, investedPercentage, winningPercentage, discreteCompoundingPeriods, outputChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for simulations to finish and write output
|
||||||
for i := 0; i < numSimulations; i++ {
|
for i := 0; i < numSimulations; i++ {
|
||||||
fmt.Println(<-outputChannel)
|
fmt.Println(<-outputChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// discrete period, symmetric payoff simulator
|
||||||
func simulation(startingBalance, investedPercentage, winningPercentage float64, discreteCompoundingPeriods int, outputChannel chan float64) {
|
func simulation(startingBalance, investedPercentage, winningPercentage float64, discreteCompoundingPeriods int, outputChannel chan float64) {
|
||||||
balance := startingBalance
|
balance := startingBalance
|
||||||
|
|
||||||
|
// Each iteration is one bet
|
||||||
for i := 0; i < discreteCompoundingPeriods; i++ {
|
for i := 0; i < discreteCompoundingPeriods; i++ {
|
||||||
investedAmount := balance * investedPercentage
|
// Each bet is a fixed percentage of the balance
|
||||||
|
betAmount := balance * investedPercentage
|
||||||
if rand.Float64() <= winningPercentage {
|
if rand.Float64() <= winningPercentage {
|
||||||
// you win
|
// you win
|
||||||
balance += investedAmount
|
balance += betAmount
|
||||||
} else {
|
} else {
|
||||||
// you lose
|
// you lose
|
||||||
balance -= investedAmount
|
balance -= betAmount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate and report the result on the outputChannel
|
||||||
outputChannel <- (balance / startingBalance)
|
outputChannel <- (balance / startingBalance)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user