Skip to content

Instantly share code, notes, and snippets.

@dooglus
Created February 3, 2016 07:35
Show Gist options
  • Select an option

  • Save dooglus/1426a596d59b722d3312 to your computer and use it in GitHub Desktop.

Select an option

Save dooglus/1426a596d59b722d3312 to your computer and use it in GitHub Desktop.

Revisions

  1. dooglus created this gist Feb 3, 2016.
    26 changes: 26 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    import random, math

    num_sims = 1000
    num_rolls = 1000
    chance = 5/100.0
    edge = 1 - 2*chance
    start_bank = 1000

    risk = 0
    while risk < 1:
    sim_count = 0
    sum_log_banks = 0
    while sim_count < num_sims:
    bank = start_bank
    roll_count = 0
    while roll_count < num_rolls:
    if random.random() < chance:
    bank *= (1-risk)
    else:
    bank *= (1+risk)
    roll_count += 1
    sum_log_banks += math.log(bank/start_bank)
    sim_count += 1

    print risk, sum_log_banks / sim_count
    risk += 0.01