Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I'm looking to solve the two questions shown in the screenshots below. I'm confused as to how to unroll a code and think I

Hello, I'm looking to solve the two questions shown in the screenshots below. I'm confused as to how to unroll a code and think I may be overcomplicating the concept. Could someone please help me answer these questions? In one screen shot I have the context of the question and question 1 visible, in the other I have question 1 and question 2 visible. Thank you!

image text in transcribedimage text in transcribed
"Unrolling" a for loop means to manually write out all the code that it executes. The result is code that does the same thing as the loop, but without the structure of the loop. For example, for the following loop: for num in np. arange(3) : print ("The number is", num) The unrolled version would look like this: print ("The number is", 0) print ("The number is", 1) print ("The number is", 2) Unrolling a for loop is a great way to understand what the loop is doing during each step. In this exercise, you'll practice unrolling for loops. In each question below, write code that does the same thing as the given code, but with any for loops unrolled. It's a good idea to run both your answer and the original code to verify that they do the same thing. (Of course, if the code does something random, you'll get a different random outcome than the original code!) First, run the cell below to load data that will be used in a few questions. In [ ]: mkt = Table. read_table( 'https://www. dropbox. com/s/t2ob9vzc5gpeigo/F-F_Research_Data_5_Factors_2x3. CSV? raw=1' ) . select mkt Question 1. Unroll the code below. In [ ] : # this table will hold 5 monthly returns randomly-drawn, with replacement, from the history # we're basically assuming that possible outcomes for the future will look like outcomes in the past mkt_sim = Table( ) . with_columns ("Date", make_array ( ), "Mkt-RF", make_array ( ) ) for i in np. arange (5) : one_month = mkt . row(np. random. randint (mkt . num_rows) ) mkt_sim = mkt_sim. with_row(one_month) mkt_sim To [ ]:Unrolling a for loop is a great way to understand what the loop is doing during each step. In this exercise, you'll practice unrolling for loops. In each question below, write code that does the same thing as the given code, but with any for loops unrolled. It's a good idea to run both your answer and the original code to verify that they do the same thing. (Of course, if the code does something random, you'll get a different random outcome than the original code!) First, run the cell below to load data that will be used in a few questions. In [ ]: mkt = Table. read_table ( 'https: / /www. dropbox. com/s/t2ob9vzc5gpeigo/F-F_Research_Data_5_Factors_2x3. CSV? raw=1' ) . select mkt Question 1. Unroll the code below. In [ ]: # this table will hold 5 monthly returns randomly-drawn, with replacement, from the history # we're basically assuming that possible outcomes for the future will look like outcomes in the past mkt_sim = Table( ) . with_columns ("Date", make_array ( ), "Mkt-RF", make_array ( ) ) for i in np. arange (5) : one_month = mkt. row(np. random. randint (mkt . num_rows) ) mkt_sim = mkt_sim. with_row(one_month) mkt_sim In [ ]: Question 2. In the previous question, we basically simulate market returns for a 5-month period. An alternative approach to simulation is to assume that returns follow the normal distribution and that the mean/standard deviation will be the same as in history. Use the np.random.normal() function to simulate 1 month of market return. In [ ] : np. random. seed (12345) # DO NOT CHANGE THIS LINE OF CODE one_sim = . . . one_sim

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions

Question

What may be the causes of the current subprime mortgage crisis?

Answered: 1 week ago

Question

What does the following code print? \f

Answered: 1 week ago