# Importing Required Libraries
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 = 'MSFT'
# Get the data on this ticker
tickerData = yf.Ticker(ticker_symbol)
# Get the historical prices for the specified period
ticker_df = tickerData.history(period='1d', start='2022-1-1', end='2023-1-25')
# Calculate RSI
delta = ticker_df["Close"].diff(1)
delta = delta.dropna()
up = delta.copy()
down = delta.copy()
up[up < 0] = 0
down[down > 0] = 0
average_gain = up.rolling(window=14).mean()
average_loss = abs(down.rolling(window=14).mean())
rs = average_gain / average_loss
RSI = 100.0 - (100.0 / (1.0 + rs))
# Add RSI to the data frame
ticker_df["RSI"] = RSI
# Define the data
data = ticker_df['RSI']
# Plot the chart
ticker_df['RSI'].iplot(title="RSI of " + ticker_symbol,
xTitle='Date', yTitle='RSI',
hline=[0,10,20,30,70,80,90,100],
theme='pearl')