開始使用免費開始

實作 Bollinger Bands

Bollinger Bands(布林通道)是在價格的簡單移動平均線上下方繪製的包絡線。由於通道的距離以標準差為基準,因此會隨標的價格的波動性而調整。

為了更清楚了解標準差設定對布林通道的影響,你將在同一個資料集上實作並繪製兩組不同設定的 Bollinger Bands。

你將使用已預先載入為 bitcoin_data 的比特幣歷史價格資料。talib 函式庫也已為你匯入。

本練習屬於課程

Financial Trading in Python

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Define the Bollinger Bands with 1-sd
upper_1sd, mid_1sd, lower_1sd = ____(bitcoin_data['Close'], 
                                     ____,
                                     ____,
                                     timeperiod=20)
# Plot the upper and lower Bollinger Bands 
plt.plot(bitcoin_data['Close'], color='green', label='Price')
plt.plot(____, color='tomato', label="Upper 1sd")
plt.plot(____, color='tomato', label='Lower 1sd')

# Customize and show the plot
plt.legend(loc='upper left')
plt.title('Bollinger Bands (1sd)')
plt.show()
編輯並執行程式碼