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.
本练习是课程的一部分
Foundations of Inference in Python
练习说明
- 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.
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Select a sample of 500 random days
sample_closing = 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=____)