import pandas as pd
import yfinance as yf
import cufflinks as cf
import plotly.offline
cf.go_offline()
cf.set_config_file(offline=False, world_readable=True)
# Define the Ticker Symbol
ticker_symbol = "GOOG"
# Get the data on this ticker
ticker_data = yf.Ticker(ticker_symbol)
# Get the historical prices for the specified period
ticker_df = ticker_data.history(period="1d", start="2021-1-1", end="2023-6-15")
# Calculate Simple Moving Averages
ticker_df["SMA30"] = ticker_df["Close"].rolling(window=30).mean()
ticker_df["SMA100"] = ticker_df["Close"].rolling(window=100).mean()
# Define the data
data = [ticker_df["SMA30"], ticker_df["SMA100"], ticker_df["Close"]]
# Plot the chart
ticker_df.iplot(
title="Moving Averages of " + ticker_symbol,
xTitle="Date",
yTitle="Price",
theme="pearl",
)