The work has not been graded but I like the output that was submitted to me. Is it possible for the same prof to do the next assignment I will be submitting? If possible, I will greatly appreciate it.
Q4. Back to roulette.
Here you will write two functions that simulate various bets in roulette. Review the slides from class to see the possible bets and their pay offs.
This should give you practice in the following aspects of function writing:
Additionally, you will compare various betting strategies.
In class (see the slides), we looked at a function to simulate betting red in roulette. We reproduce this function here for your convenience.
betRed = function(numBets, betAmt = 1) { winLoss = sample(rep(c(-1, 1), c(20, 18)), size = numBets, replace = TRUE) netGain = sum(winLoss * betAmt) return(netGain) }
We compare the net gain of two types of betting strategies: 100 bets of $1 on red and 1 bet of $100 on red. To do this we repeated the betting process 10,000 times to see the kinds of net gains we might get with each strategy.
gain100B.1D = replicate(10000, betRed(numBets = 100, betAmt = 1)) gain1B.100D = replicate(10000, betRed(numBets = 1, betAmt = 100))
You should be able to use the above plotting function to compare the net gains from the 2 strategies by running it as follows:
plotGains(gain1B.100D, gain100B.1D)
When we play roulette we start with a particular sum of money, e.g., we may have $100 in our wallet. Then what’s in our wallet impacts how much and how long we can bet. For example, with $100 in our wallet we cannot place a $200 bet. Also, depending on our winnings, we may be able to place 200 $1 bets or we may run out of money before then.
For your first function, augment the betRed function to accept an additional parameter called wallet that contains the starting amount of money. Call this new function betRed2. Give wallet a default value so that it runs like the original betRed function if the default value of wallet is used.
The return value from this function should be the net gain. As before, this is the winnings less the losses. However, if at some point in your betting, you no longer have enough funds to place a bet then you can’t continue your betting.
NOTE: DO NOT USE A FOR LOOP IN THIS FUNCTION. Consider instead the cumsum() function and logical expressions.
Here are some tests that you can run to see if your code is working correctly (note: there are errors right now because the code has not been written!)
betRed2(betAmt = 100, numBets = 1, wallet = 50)
## Error in eval(expr, envir, enclos): could not find function “betRed2”
# returns 0 betRed2(betAmt = 100, numBets = 1, wallet = 100)
## Error in eval(expr, envir, enclos): could not find function “betRed2”
# returns either -100 or 100 test1 = replicate(10000, betRed2(betAmt = 1, numBets = 100, wallet = Inf))
## Error in FUN(X[[i]], …): could not find function “betRed2”
mean(test1)
## Error in mean(test1): object ‘test1’ not found
# should be near -5.26 test2 = replicate(10000, betRed2(betAmt = 100, numBets = 100, wallet = 500))
## Error in FUN(X[[i]], …): could not find function “betRed2”
plotGains(test2)
## Error in eval(expr, envir, enclos): could not find function “plotGains”
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more