Select Page

Visualizing trends in an index

This question asks you to plot the Bitcoin price index (BPI) along with 5-day and 10-day averages. Please execute the code cell below; it will read in a csv file containing the daily closing price from Sep. 1, 2018 to Aug. 31, 2019 (data obtained from https://www.coindesk.com/price/). Perform the following tasks. You may use any built-in Python functions as well as data strucutres and functions provided by the numpy library.

• Observe that the closing prices are at a daily interval. We therefore do not need the date information. Clean up the data and only retain the price information. Store the result in a list or a numpy array in floating point format.
• Recall that a simple moving average is defined as the (unweighted) mean over the previous 𝑁N days.
Perform a simple moving average of the price index. The number of days 𝑁N to average over should be adjustable. If you are using numpy, you may find the function np.convolve helpful.
• Plot the raw price index data along with 5-day and 10-day simple moving average. Plot on the same figure in order to help you visually ascertain the effect of the filter.
• What is the effect of the moving average filter? In what circumstances would you not want to use a moving average?

2Eight athletes are competing in a 1500 m race. Using numpy , write a vectorized race simulation according to the following criteria:

• The granularity of the simulation is 1 s, i.e. each iteration in your simulation represents 1 second.
• During each iteration, each athelete can randomly take 1, 2, 3, or 4 steps. Each step is 1 m long.
• When the race is complete, return the winner and the winning time. There should not be any ties. If there is a tie, select a winner at random.

Please pay attention to the following:

• There should only be one loop in your simulation: the loop that advances the simulation by a second.
• All other operations should be done using vectorized array operations and boolean indexing.
• The following numpy functions will be helpful:
1. Run your simulation 10,000 times. For each run, record the winner and the winning time. Produce a bar chart showing the number of times each athelete won. Also display a bar chart showing the average winning time for each athlete.