Python has a library that provides a rich set of features as technical indicators. The official reference can be found here The library also calculates Bollinger Bands, and returns three arrays of results that can be plotted on a graph to get what you want.
# !pip install yfinance
# !wget https://launchpad.net/~mario-mariomedina/+archive/ubuntu/talib/+files/libta-lib0_0.4.0-oneiric1_amd64.deb -qO libta.deb
# !wget https://launchpad.net/~mario-mariomedina/+archive/ubuntu/talib/+files/ta-lib0-dev_0.4.0-oneiric1_amd64.deb -qO ta.deb
# !dpkg -i libta.deb ta.deb
# !pip install ta-lib
import talib
import yfinance as yf
import datetime
import pandas as pd
import numpy as np
begin = datetime.datetime.today() - datetime.timedelta(days=100)
finish = datetime.datetime.today()
stockinfo = yf.download("AAPL", start=begin, end=finish)
stockinfo['20 Day MA'] = stockinfo['Adj Close'].rolling(window=20).mean()
stockinfo['20 Day STD'] = stockinfo['Adj Close'].rolling(window=20).std()
stockinfo['Upper_bband'] = stockinfo['20 Day MA'] + (stockinfo['20 Day STD'] * 1.5)
stockinfo['Lower_bband'] = stockinfo['20 Day MA'] - (stockinfo['20 Day STD'] * 1.5)
bbands = talib.BBANDS(np.array(stockinfo['Adj Close']))
import matplotlib.pyplot as plt
plt.figure(figsize=(12.5, 5))
plt.plot(stockinfo.index, stockinfo['20 Day MA'], label='20 Day MA')
plt.plot(stockinfo.index, stockinfo['Upper_bband'], label='upper_bband')
plt.plot(stockinfo.index, stockinfo['Lower_bband'], label='lower_bband')
plt.plot(stockinfo.index, bbands[0], label='bband1')
plt.plot(stockinfo.index, bbands[1], label='bband2')
plt.plot(stockinfo.index, bbands[2], label='bband3')
plt.title('AAPL: 20 Day Bollinger Band')
plt.xlabel(begin.strftime('%Y-%m-%d') + '-' + finish.strftime('%Y-%m-%d'))
plt.ylabel('Price (in USD)')
plt.legend(loc='upper left')
plt.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…