計算信賴區間
既然你已經證明 S&P 500 的收盤價之抽樣分配大致呈常態分配,接下來就來計算信賴區間吧!你想估計 S&P 500 的平均收盤價,而計算信賴區間正好可以幫你做到這點。
相同的資料 btc_sp_df 已為你載入,且已載入套件 pandas 為 pd、NumPy 為 np,以及 scipy.stats 為 stats。
本練習屬於課程
Python 推論基礎
練習說明
- 從
Close_SP500欄位隨機抽取 500 天的樣本。 - 計算此隨機樣本的平均值。
- 將標準差除以樣本大小的平方根,計算此隨機樣本的標準誤。
- 使用你剛剛計算的數值,求出 95% 信賴區間。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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=____)