Calculating confidence intervals
Now that you've demonstrated that the sampling distribution for the closing price of the S&P 500 is approximately normally distributed, you'll compute a confidence interval! You want to estimate the mean closing price of the S&P 500, and calculating a confidence interval will do just that for you.
The same data btc_sp_df
has been loaded for you, as have the packages pandas as pd
, NumPy as np
and scipy.stats
as stats
.
This exercise is part of the course
Foundations of Inference in Python
Exercise instructions
- Select a random sample of 500 days from the column
Close_SP500
. - Calculate the mean of this random sample.
- Calculate the standard error of this random sample as the standard deviation divided by the square root of the sample size.
- Calculate a 95% confidence interval using the values you just calculated.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Select a sample of 500 random days
sample_df = np.____(____, size=____)
# Calculate the mean of the sample
sample_mean = ____
# Calculate the standard error of the sample
sample_se = ____ / ____
# Calculate a 95% confidence interval using this data
stats.norm.interval(alpha=____,
loc=____,
scale=____)