# Get the last 365 days of Microsoft stock at a 1 day frequency
msft = yf.Ticker("MSFT")
end_date = pd.Timestamp.today(tz='America/New_York').ceil('D')
start_date = end_date - pd.Timedelta(365,'D')
data = msft.history(start=start_date,end=end_date, interval='1d').reset_index()
# Plot as a line chart
fig = go.Figure(data=go.Scatter(
x=data.Date,
y=data.Close,
mode='lines'
))
fig.update_layout(
title='Microsoft (MSFT)',
title_x=0.5,
autosize=False,
width=800,
height=500,
xaxis= dict(rangeselector=dict(
buttons=list([
dict(count=30,
label="30D",
step="day",
stepmode="backward"),
dict(count=6,
label="6M",
step="month",
stepmode="backward"),
dict(count=1,
label="YTD",
step="year",
stepmode="todate"),
dict(count=1,
label="1Y",
step="year",
stepmode="backward")
])
)),
)
fig.show()