YasserKhalil
YasserKhalil

Reputation: 9568

Get last price of stock data in python

I have searched for this topic and I found some packages that are useful. All what I am trying to get is the last price of any specific ticker such as "MSFT" Here's a code that I found and it is good

import pandas_datareader as pdr
from datetime import datetime

ibm = pdr.get_data_yahoo(symbols='MSFT', start=datetime(2021, 3, 1), end=datetime(2021, 3, 12))
print(ibm['Adj Close'])

This works for range of dates. How can I get the last price only without hard-coding the start date or end date?

Upvotes: 0

Views: 3132

Answers (1)

JongHyeon Yeo
JongHyeon Yeo

Reputation: 1039

Just use tail keyword.

from datetime import datetime, date

ibm = pdr.get_data_yahoo(symbols='MSFT', start = date.today(), end = date.today())
print(ibm['Adj Close'].tail(1))

Upvotes: 3

Related Questions