Normal sampling distributions
You'd like to estimate a realistic mean closing price for the S&P 500 over a subset of its trading history. This seems like a natural application of a confidence interval, since you have a sample statistic and want to use it to estimate a population statistic. However, your first step should be to check if the sampling distribution is approximately normal. In this exercise, you'll do exactly that. In the next exercise, you'll use this result to create your confidence interval.
The same data btc_sp_df
has been loaded for you, as have the packages pandas as pd
, NumPy as np
and Matplotlib as plt
.
This exercise is part of the course
Foundations of Inference in Python
Exercise instructions
- Define a variable
num_samples
as the desired number of samples (200), and define an empty listsample_means
to store the mean from each of the 200 samples. - Write a
for
loop which will repeat the sampling processnum_samples
times. - Select 500 random S&P500 closing prices from the
Close_SP500
column ofbtc_sp_df
. - Compute the mean of each of these samples and store them in
sample_means
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define the number of samples to take and store the sample means
num_samples = ____
sample_means = ____
# Write a for loop which repeats the sampling num_samples times
for i in ____:
# Select 500 random Close_SP500 prices
sp500_sample = np.___(____, size=____)
# Compute mean closing price and save it to sample_means
____.append(____.mean())
plt.hist(sample_means)
plt.show()