Compare commits

...

2 Commits

2 changed files with 18 additions and 9 deletions

View File

@ -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).
In other words, given enough time, we're all screwed.
### 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.
@ -35,6 +33,8 @@ Notice the e-n at the end... these are very small numbers, with only one simulat
* 7.788708234095218e-09
* 0.0041392388926358116
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)

23
main.go
View File

@ -7,37 +7,46 @@ import (
)
func main() {
// Random seed based on time when program runs
rand.Seed(time.Now().UTC().UnixNano())
var balance, investedPercentage, winningPercentage float64
balance = 100
// Initialize variables
var startingBalance, investedPercentage, winningPercentage float64
startingBalance = 100
investedPercentage = 0.80
winningPercentage = 0.70
discreteCompoundingPeriods := 200
numSimulations := 16
outputChannel := make(chan float64)
// Start simulations
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++ {
fmt.Println(<-outputChannel)
}
}
// discrete period, symmetric payoff simulator
func simulation(startingBalance, investedPercentage, winningPercentage float64, discreteCompoundingPeriods int, outputChannel chan float64) {
balance := startingBalance
// Each iteration is one bet
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 {
// you win
balance += investedAmount
balance += betAmount
} else {
// you lose
balance -= investedAmount
balance -= betAmount
}
}
// Calculate and report the result on the outputChannel
outputChannel <- (balance / startingBalance)
}