Question: This is a problem using python and functions. Problem 5 - streaks.py: Winning streaks? The debate on whether the random walk model for stock prices


This is a problem using python and functions.
Problem 5 - streaks.py: Winning streaks? The debate on whether the random walk model for stock prices is appropriate has been going on for a long time. Some of it's opponents argue that "all those pattens we observe must be evidence of non-randomness". However, fairly complex pattems can arise through purely random processes In this problem, you will study a simple pattern that may arise in a simple random process. Consider a sequence of coin tosses where the probability of landing heads is p. A streak is a contiguous sub-sequence of tosses that landed the same way (i.e., either all heads or all tails). For example, in the sequence of N 14 tosses, H, H, T, T, T, H. T, H.H, H. T. T. T, T we have six streaks, Therefore, the maximum streak length is 4 (corresponding to the last streak) Problem 5a -streaks.py: Maximum streak length [30 points] Write a function max_streak ( that accepts the number of coin tosses N (positive integer), and the probability of heads p (float, between 0 and1), as arguments. Your function should generate one random sequence of N coin tosses and return the maximum streak length in that sequence. Please use the provided toss function to generate the random coin tosses. Hint: Consider the previous example. If you had the streak sequence, 2xH.3xT, 1xH, 1xT, 3xH, 4xT, instead of the original sequence, the problem would be trivial: would reduce to what you did in Problem 2. Therefore, can you first write a function that prints out the streak s keep track of the "current streak" (consisting of "length so far" and the kind of streak, heads or tails). When you see a new element, you need to decide whether the "current streak" becomes longer by one, or whether i ends (hence ? As you examine each element think about how to Problem 5 - streaks.py: Winning streaks? The debate on whether the random walk model for stock prices is appropriate has been going on for a long time. Some of it's opponents argue that "all those pattens we observe must be evidence of non-randomness". However, fairly complex pattems can arise through purely random processes In this problem, you will study a simple pattern that may arise in a simple random process. Consider a sequence of coin tosses where the probability of landing heads is p. A streak is a contiguous sub-sequence of tosses that landed the same way (i.e., either all heads or all tails). For example, in the sequence of N 14 tosses, H, H, T, T, T, H. T, H.H, H. T. T. T, T we have six streaks, Therefore, the maximum streak length is 4 (corresponding to the last streak) Problem 5a -streaks.py: Maximum streak length [30 points] Write a function max_streak ( that accepts the number of coin tosses N (positive integer), and the probability of heads p (float, between 0 and1), as arguments. Your function should generate one random sequence of N coin tosses and return the maximum streak length in that sequence. Please use the provided toss function to generate the random coin tosses. Hint: Consider the previous example. If you had the streak sequence, 2xH.3xT, 1xH, 1xT, 3xH, 4xT, instead of the original sequence, the problem would be trivial: would reduce to what you did in Problem 2. Therefore, can you first write a function that prints out the streak s keep track of the "current streak" (consisting of "length so far" and the kind of streak, heads or tails). When you see a new element, you need to decide whether the "current streak" becomes longer by one, or whether i ends (hence ? As you examine each element think about how to
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
