Lesson 18: Monte Carlo Simulation

2
April 13, 2016 at 9:31 am  •  Posted in s16-busad360 by  •  2 Comments

Previous | Next

Wed Apr 13

Review:

  • Multiple Regression in Python

Presentation:

Assignment:

  • Create a simple Monte Carlo Simulation with Python
  • Simulate a simple Dice Game:
    • Roll 2-7, lose
    • Roll 8-12, win
    • Start with $100
      • bet $1 per roll (win pays $1, loss takes $1 bet)
      • roll 100 times and find ending balance (could be negative)
      • simulate 100 outcomes (10,000 total rolls of the dice)
    • Report the mean, median, and standard deviation of your final balances
    • Repeat using 1,000 rolls per outcome (100,000 total rolls of the dice) and report the mean, median and standard deviation of final outcomes
Here’s some python code to help you get going (and plain text below): 

rolldice18

import random

def rollDice():
roll = random.randint(1,6)
return roll

j = 0
rollcount = 0
rolls = []

while j < 100:
i = 0
j = j + 1

while i < 100:
i = i + 1
result = rollDice()
rolls.append(result)
rollcount += 1

import scipy
mr = scipy.mean(rolls)
print(“Total rolls = “)
print rollcount
print(“Mean roll = “)
print mr

 

Leave a Reply