---
title: 'Homework 10: The Students Break the Bank at Monte Carlo'
author: "36-350"
date: "Due at 11:59 pm on Monday, 24 November 2014"
output: pdf_document
---

This is the final homework of the semester. Celebrate on your own time.

Now that we are discussing  simulation, `for` loops are now back on the table. Let's use this as well as `while` and repeat to simulate some outcomes.

1. **Gambler's Ruin**: Suppose you have a bankroll of $1000 and make bets of $100 on a fair game. By simulating the outcome directly for at most 5000 iterations of the game (or hands), estimate:
    a. the probability that you have "busted" (lost all your money) by the time you have placed your one hundredth bet. 
    b. the probability that you have busted by the time you have placed your five hundredth bet by simulating the outcome directly. 
    c. the mean time you go bust, given that you go bust within the first 5000 hands.
    d. the mean and variance of your bankroll after 100 hands (including busts).
    e. the mean and variance of your bankroll after 500 hands (including busts).
 
Note: you *must* stop playing if your player has gone bust. How will you handle this in the `for` loop?

2. Repeat the previous problem with betting on black in American roulette, where the probability of winning on any spin is 18/38 for an even payout.

3. **Markov Chains**. Suppose you have a game where the probability of winning on your first hand is 48%; each time you win, that probability goes up by one percentage point for the next game (to a maximum of 100%, where it must stay), and each time you lose, it goes back down to 48%. Assume you cannot go bust and that the size of your wager is a constant $100.
    a. Is this a fair game? Simulate one hundred thousand sequential hands to determine the size of your return. Then repeat this simulation 99 more times to get a range of values to calculate the expectation.
    b. Repeat this process but change the starting probability to a new value within 2% either way. Get the expected return after 100 repetitions. Keep exploring until you have a return value that is as fair as you can make it. Can you do this automatically?
    c. Repeat again, keeping the initial probability at 48%, but this time change the probability increment to a value different from 1%. Get the expected return after 100 repetitions. Keep changing this value until you have a return value that is as fair as you can make it. 

4. For the last two examples in the previous question, you calculated a mean value. Because you saved these final results in a vector, use the bootstrap to estimate the variance of the return in each case for your final answer. Once you have these results, which game has the smaller variance in returns?
