<jupyter_start><jupyter_text>Bollinger Bands Bollinger Bands represent a key technical trading tool for financial traders. Bollinger bands are plotted by two (2) standard deviations (a measure of volatility) away from the moving average of a price. Bollinger Bands allow traders to monitor and take advantage of shifts in price volatilities. This provides a confidence interval that shows h Main Components of a Bollinger BandsUpper Band: The upper band is simply two standard deviations above the moving average of a stock’s price.    Middle Band: The middle band is simply the moving average of the stock’s price.    Lower Band: Two standard deviations below the moving average is the lower band.<jupyter_code># import needed libraries
import pandas as pd
import matplotlib.pyplot as plt
from pandas_datareader import data as web
# Make function for calls to Yahoo Finance
def get_adj_close(ticker, start, end):
    '''
    A function that takes ticker symbols, starting period, ending period
    as arguments and returns with a Pandas DataFrame of the Adjusted Close Prices
    for the tickers from Yahoo Finance
    '''
    start = start
    end = end
    info = web.DataReader(ticker, data_source='yahoo', start=start, end=end)['Adj Close']
    return pd.DataFrame(info)
# Get Adjusted Closing Prices for Amazon between 2015-2019
amzn = get_adj_close('amzn', '1/2/2015', '31/12/2019')
amzn
# Calculate 30 Day Moving Average, Std Deviation, Upper Band and Lower Band
amzn['30 Day MA'] = amzn['Adj Close'].rolling(window=20).mean()
amzn['30 Day STD'] = amzn['Adj Close'].rolling(window=20).std()
amzn['Upper Band'] = amzn['30 Day MA'] + (amzn['30 Day STD'] * 2)
amzn['Lower Band'] = amzn['30 Day MA'] - (amzn['30 Day STD'] * 2)
# Simple 30 Day Bollinger Band for Facebook (2016-2017)
amzn[['Adj Close', '30 Day MA', 'Upper Band', 'Lower Band']].plot(figsize=(15,6))
plt.title('30 Day Bollinger Band for Amazon')
plt.ylabel('Price (USD)')
plt.show()
# set style, empty figure and axes
plt.style.use('fivethirtyeight')
fig = plt.figure(figsize=(12,6))
ax = fig.add_subplot(111)

# Get index values for the X axis for Amazon DataFrame
x_axis = amzn.index.get_level_values(0)

# Plot shaded 21 Day Bollinger Band for Amazon
ax.fill_between(x_axis, amzn['Upper Band'], amzn['Lower Band'], color='grey')

# Plot Adjust Closing Price and Moving Averages
ax.plot(x_axis, amzn['Adj Close'], color='blue', lw=2)
ax.plot(x_axis, amzn['30 Day MA'], color='black', lw=2)

# Set Title & Show the Image
ax.set_title('30 Day Bollinger Band For Amazon')
ax.set_xlabel('Date (Year/Month)')
ax.set_ylabel('Price(USD)')
ax.legend()
plt.show()<jupyter_output>No handles with labels found to put in legend.
{'fraction_non_alphanumeric': 0.10755489393375511, 'fraction_numerical': 0.02791216970599181, 'mean_word_length': 5.026905829596412, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '189610', 'license': 'MIT', 'n_tokens_mistral': 906, 'n_tokens_neox': 822, 'n_words': 333, 'path': 'AmazonStockAnalysis-main/.ipynb_checkpoints/Bollinger Bands-PFE-checkpoint.ipynb', 'repo_name': 'mylar-pr/stock-trading-ml', 'size': '2687'}