Should we buy?
In the last exercise, we simulated the random drawing of the lottery ticket once. In this exercise, we complete the simulation process by repeating the process multiple times.
Repeating the process gives us multiple outcomes. We can think of this as multiple universes where the same lottery drawing occurred. We can then determine the average winnings across all these universes. If the average winnings are greater than what we pay for the ticket then it makes sense to buy it, otherwise, we might not want to buy the ticket.
This is typically how simulations are used for evaluating business investments. After completing this exercise, you will have the basic tools required to use simulations for decision-making.
This exercise is part of the course
Statistical Simulation in Python
Exercise instructions
- Set the
size
parameter, which controls the number of simulations, to 2000. - Set
payoffs
equal to a list containing how much you could lose and how much you could win. - Set
probs
equal to a list of probabilities of losing and winning. - Calculate the mean of
outcomes
and assign it toanswer
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Initialize size and simulate outcome
lottery_ticket_cost, num_tickets, grand_prize = 10, 1000, 10000
chance_of_winning = 1/num_tickets
size = ____
payoffs = ____
probs = ____
outcomes = np.random.choice(a=____, size=size, p=____, replace=True)
# Mean of outcomes.
answer = ____
print("Average payoff from {} simulations = {}".format(size, answer))