Last active
March 15, 2024 20:12
-
-
Save izikeros/811a04bd74c8a4d7745f12ee981cf26f to your computer and use it in GitHub Desktop.
[OHLC from Yahoo] Download OHLC ticker data from Yahoo #finance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import yfinance as yf | |
| from datetime import datetime # To get the current date and time | |
| start_date = datetime(2011, 1, 1) | |
| end_date = datetime(2011, 5, 1) | |
| ticker = "MSFT" | |
| yf_ticker_obj = yf.Ticker(ticker) | |
| if start_date != None and end_date != None: | |
| OHLC_data = yf_ticker_obj.history( | |
| start=start_date, end=end_date, interval="1d", auto_adjust=True | |
| ) | |
| else: | |
| OHLC_data = yf_ticker_obj.history(period="max", interval="1d", auto_adjust=True) | |
| # period = 'max' - pulling data for maximum number of days. | |
| # auto_adjust = 'True' - adjusting data for Dividends and Splits | |
| OHLC_data = OHLC_data.drop(["Dividends", "Stock Splits"], axis=1, errors="ignore") | |
| OHLC_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment