17.7. Assignment 1#

Instructions: This problem set should be done individually.

Answer each question in the designated space below.

After you are done, save, download, and upload in blackboard under Assignment 1.

17.8. Write your name and simon email#

Please write names below

  • [Name]:

  • [email]:

NOTE:

  1. You can edit this cell by double clicking in it and hitting Ctrl+enter for it to render.

  2. This is Markdown cell, where we type text. For more info on how to do formatting on markdown please see here https://ingeh.medium.com/markdown-for-jupyter-notebooks-cheatsheet-386c05aeebed, but you don’t need to.

17.9. Discussion Forum Assignment#

Due to assigment: “Quant investing from the trenches” in the discussion forum

https://edstem.org/us/courses/30665/discussion/1972479

17.10. Part A: Basic Commands#

Exercise 1

In the first cell, try y.append(z).

In the second cell try y.extend(z).

Explain the behavior.

HINT: When you are trying to explain, use y.append? and y.extend? to see a description of what these methods are supposed to do.

y = ["a", "b", "c"]
z = [1, 2, 3]
# your code here

print(y)
['a', 'b', 'c']
y = ["a", "b", "c"]
z = [1, 2, 3]
# your code here

print(y)
['a', 'b', 'c']

Exercise 2

Experiment with two versions of the range function. Explain what d is and how you get the second option to implement the first by choosing a particular d.

# try list(range(a, N)) -- you pick `a` and `N`
# try list(range(a, N, d)) -- you pick `a`, `N`, and `d`

Exercise 3

Use Jupyter’s help facilities to learn how to use the pop method to remove the number 10.48 from the list gdp_data.

gdp_data = [9.607, 10.48, 11.06]
# your code here

Exercise 4

Explain what happens to the value you popped.

Experiment with calling pop twice.

# your code here

Exercise 5

Run the following two variations on the code with only a single difference in the indentation.

After you do that, modify the value of x to print 3 in the first cell and then 2, 3 in the second cell instead.

Create a cell below to explain what is going on.

x = 1

if x > 0:
    print("1")
    print("2")
print("3")
x = 1

if x > 0:
    print("1")
print("2") # changed the indentation
print("3")

Exercise 6

Using the code cell below as a start, print "Good afternoon" if the current_time is past noon.

Otherwise, do nothing.

(Hint: Write some conditional based on current_time.hour.)

import datetime
current_time = datetime.datetime.now()

## your code here

Exercise 7

You will generate a random number between 0 and 1, add code to print “x > 0.5” or “x <= 0.5” depending on the value of the number.

This also introduces a new package numpy.random for drawing random numbers.

import numpy as np
x = np.random.random()
print(f"x = {x}")

## your code here

Exercise 8

Write a for loop that uses the lists of cities and states below to print the same “{city} is in {state}” using zip.

cities = ["Phoenix", "Austin", "San Diego", "New York"]
states = ["Arizona", "Texas", "California", "New York"]

for __, __ in zip(__,__):
    print(f"{__} is in {__}")
# Your code here

Exercise 9

Try to find the index of the first value in x that is greater than 0.999 using a for loop and break.

Hint: try iterating over range(len(x)).

x = np.random.rand(10000)
# Your code here

Exercise 10

Write a for loop that adds up all values in x that are greater than or equal to 0.5.

Use the continue word to end the body of the loop early for all values of x that are less than 0.5.

Hint: Try starting your loop with for value in x: instead of iterating over the indices of x.

x = np.random.rand(10000)
# Your code here

17.11. Part B: Applications#

Exercise 1

In economics, when an individual has some knowledge, skills, or education which provides them with a source of future income, we call it human capital.

When a student graduating from high school is considering whether to continue with post-secondary education, they may consider that it gives them higher paying jobs in the future, but requires that they don’t begin working until after graduation.

Consider the simplified example where a student has perfectly forecastable employment and is given two choices:

  1. Begin working immediately and make 60,000 a year until they retire 40 years later.

  2. Pay 20,000 a year for the next 4 years to attend university, then get a job paying 200,000 a year until they retire in 40 years after making the college attendance decision.

Assume wages and tuitions are paid at the beginning of each year.

What is the expected rate of return of this investment?

To do this first start by constructing the npv of the college decision using the NPV of high school as inspiration. Do this for a given interest rate, say 5%.

Then build a expression that returns the difference in NPVs.

Finally, change the interest rate manually until this difference in the NPVs is the less than 1000 dollars.

# Discount rate
r = 0.05

# High school wage
w_hs = 80000

# College wage and cost of college
c_college = 20000 
w_college = 200000

# Compute npv of being a hs worker
npv_hs=0
for t in range(0,40):
    npv_hs=npv_hs+w_hs/(1+r)**t
print(npv_hs)
# Compute npv of attending college
npv_c=0
for t in range(0,__):
    __=__+__

for t in range(__,40):
    __=__+__
print(npv_c)
# Compute npv of being a college worker

# Is npv_collegeworker - npv_collegecost > npv_hsworker

Exercise 2

Companies often invest in training their employees to raise their productivity. Economists sometimes wonder why companies spend this money when this incentivizes other companies to hire their employees away with higher salaries since employees gain human capital from training.

Let’s say that it costs a company 25,000 dollars to teach their employees Python, but it raises their output by 2,500 per month. How many months would an employee need to stay for the company to find it profitable to pay for their employees to learn Python if their monthly discount rate is r = 0.01?

# Define cost of teaching python
cost = 25_000
r = 0.01

# Per month value
added_value = 2500

n_months = 0
total_npv = 0.0

# Put condition below here
while False: # (replace False with your condition here)
    n_months = n_months + 1  # Increment how many months they've worked

    # Increase total_npv