Download historical stock data from Yahoo Finance using Python
In this tutorial, I will share a script I use to easily download historical stock data from Yahoo finance using just a few lines of code in Python to help me analyze different stocks.
There are several Python libraries you can use these days to download stock data from Yahoo finance, but for me, I prefer directly to go to the source. In this tutorial, I will show you how we can make a request call to Yahoo Finance's back-end to access the stock data and export them as CSV files.
📑 Source Code: learndataanalysis.org/source-...
📃 If you want to export multiple historical data to a single Excel spreadsheet: • Download Multiple Hist...
► Buy Me a Coffee? Your support is much appreciated!
-------------------------------------------------------------------------------------------
☕ Paypal: www.paypal.me/jiejenn/5
☕ Venmo: @Jie-Jenn
💸 Join Robinhood with my link and we'll both get a free stock: bit.ly/3iWr7LC
► Support my channel so I can continue making free contents
---------------------------------------------------------------------------------------------------------------
🛒 By shopping on Amazon → amzn.to/2JkGeMD
👩💻 Follow me on Linked: / jiejenn
🌳 Becoming a Patreon supporter: / jiejenn
✉️ Business Inquiring: KZread@LearnDataAnalysis.org
#Stock #YahooFinance #HistoricalStockData #Python
Пікірлер: 106
To import price for for monthly interval, Yahoo Finance has change the parameter value from "1m" to "1mo".
such tremendous value in an 8 minute video! exactly what I needed, only a few lines of code
Great tutorial! The step by step way you explain the time conversion functions is superb. Hope you continue doing this as a series. Liked and subscribed.
Thank you. I have been trying to script this for a long time!
Crazy good. Thank you for creating this vid.
Hello Sir, This video tutorial was great, learned something new. Thanks a lot! :)
Thanks bro! I learn a lot!
Thank you for this great introduction! Could you please make a series on this topic?! How do you build your portfolio? How do you choose stocks - based on which criteria?
@jiejenn
3 жыл бұрын
I will eventually make a video on how I use data analytics and Python to determine my stock purchasing decision.
@amarshah1230
2 жыл бұрын
@@jiejenn thanks for this, let me know when you have a video for stock purchasing - thanks
Nice!!! Did this with the data on redfin
Great and useful content! Nice tutorial
@jiejenn
3 жыл бұрын
Thanks!
good job, just what i needed
Thank you so much Jie! I got it right first try lol
@jiejenn
Жыл бұрын
Glad you got the script to work on the 1st try!
Awesome, thanks for sharing! 👍🏿
@jiejenn
2 жыл бұрын
Glad the video helped.
Thank you for sharing.
thank you so much for this
Excellent!!!
Awesome tutorial! It is the simplest and best way to download the price data. Thanks a lot. Do you have any tips for downloading the historical fundamentals number such as PE, PB etc?
@jiejenn
2 жыл бұрын
Something like this? kzread.info/dash/bejne/pqaTsLOPhcfTprw.html
great one, thank you
@jiejenn
3 ай бұрын
👍
When I print 'query_string', I am able to get the link. However, it automatically downloads the csv straight to my computer rather than asking me. Because of this, my data isn't on my python IDE. Any suggestions on how to fix this?
Hi thanks for the upload! Do you think you can do a video tutorial for showing the stock option data using yahoo finance api or any other api? Also, is there a way to change the periods so that it automatically pulls the most recent X years of data as opposed to having to go back into the code and changing the dates each time?
thank you ❤
I basically copied the entire thing.. and then "query_string in my terminal but a hyperlink doesnt show up for me too look at it... I need help ! Also, any time i write code and run the module i never see any results. Newb here.
Fantastic
This wasn't working for me, I was getting a 404 error. After a bit of fruitlessness and frustration I have found the issue. I was forgetting to use the download link, not the webpage address. Hopefully this will help anyone else having similar PEBKAC issues.
thanks for making this video. good job 👏
It's starting.👄👍
Thanks for the video. Is there a way to get the intraday data between the given two dates?
@jiejenn
2 жыл бұрын
Not with Yahoo's API. Storage is costly so that's why most of the services only provide daily data. If you are looking for intradat data, Google might be your best friend.
Awesome video with clear explanation!! I ran your code, however I'm missing my middle "Low" Column. Instead of numbers, each item in the column just says "..." any thoughts?
@jiejenn
3 жыл бұрын
By default, pandas doesn't display all the columns on the console. Insert this line before your print statement pd.set_option('display.max_columns', 100)
Thanks for the video! If I wanted to take just the numbers from the 'Close' column, how would I do that? When I try (using df['Close']) it outputs more than just the actual number values of that column.
@jiejenn
2 жыл бұрын
Can you be more specific? What do you mean by outputs more than just the actual number?
@samjockel5848
2 жыл бұрын
@@jiejenn If I run your code using print(df['Close']), I get an output of: 0 123.080002 1 122.940002 2 122.250000 3 123.750000 and so on... Is it possible to only get an output of just the closing prices, instead of having them numbered 0-3? To be more specific, I'm trying to put these closing prices into an array so I can manipulate them and do some equations. I'm not sure if this approach will actually work, but let me know what you think!
Hi there! is there a way to pull other fields such as EV, Revenue, market cap, forward revenue estimates on a monthly periodicity please? (revenue is published every quarter and not every month so there could be 3x the same Revenue number to represent a quarter) . thanks!
@jiejenn
2 жыл бұрын
Check out these 2 videos for reference: 📚 kzread.info/dash/bejne/pqaTsLOPhcfTprw.html 📚 kzread.info/dash/bejne/iYCsqtued5aTY7Q.html
@jd5787
2 жыл бұрын
@@jiejenn thanks, viewing now!
can u teach me how to get data in minuteframe
I can see the download link for a regular stock, but there is no download link for S&P500 on yahoo finance. Am I doing something wrong?
@jiejenn
3 жыл бұрын
What are you trying to download? If you don't see the option on Yahoo Finance, then it is probably not available.
Good video. How about modifying the script for a list of symbols? Thank you.
@jiejenn
3 жыл бұрын
Create a list of symbols and iterate each one.
What if I want historical data of 1 min (^NSEBANK) of about 5 Years ??
What Python program do you use? I'm a complete beginner to PyCharm and can't seem to find where to actually type the code!
@jiejenn
5 ай бұрын
I'm using VS Code.
This was very good video. Im getting started with python and will be coming to your site a lot to learn. I wish you would share with us the algorithm you used to make 100k! Can you share? :)
@jiejenn
2 жыл бұрын
Maybe one day. It's 200k as of today now.
hello, when I use the API try to take history data , I get response : forbindan the API isn't to be access now?
@jiejenn
2 жыл бұрын
I just tried the script, it is working fine for me snipboard.io/5dCu39.jpg. Makes sure your url is constructed correctly.
For some reason I am having a problem calling pd.read_csv(query_string). I am getting HTTP Error 404: Not Found. I am suspecting that this is because it is not returning a CSV file. I did click on the printed query_string that I created and it does take me to the expected site with data. Am I missing a parameter?
@jiejenn
2 жыл бұрын
I just tested it and it is exporting the file just fine. Have you tried copy paste the code snippet from the post too? learndataanalysis.org/source-code-download-historical-stock-data-from-yahoo-finance-using-python/
Can you make a loop for downloading one file with the stock history for several stocks?
@jiejenn
2 жыл бұрын
Try this video kzread.info/dash/bejne/oop8sNCrgbjdZ6g.html
Great Job sir, How to download NSE & BSE IPO Historical data with stock code, Listing price, OHLC, Listing Date. Thank you
How to download 1 hour ?
I tried to scrape over 900 tickers using a for-loop. After about 30% through the list of tickers, encountered HTTP Error 401: Unauthorized ... Is this a YahooFinance restriction to prevent user from hoarding resources? Is there a workaround solution?
@jiejenn
2 жыл бұрын
You probably made too many requests in a short period amount of time and now your IP is permanently blocked by the host.
Hey, I'm getting a syntax error on line 12 during the query _string... I don't know what I did wrong, I copied everything you had
@jiejenn
3 жыл бұрын
Syntax error means you have a typo somewhere in your script.
@damianwysokinski3285
3 жыл бұрын
maybe wrong date combinations
Hi Jie, can you get historical data for Crypto as well? Thanks
@jiejenn
2 жыл бұрын
This is something I never thought of doing. Let me look into it!
Thanks a lot for this video. I tried daily period and working fine but it does not work for weekly period. using the option 1w. Any idea how can I solve it ?
@jiejenn
2 жыл бұрын
Look like Yahoo Finance API made the change to the parameter value. Use 1mo instead of 1m.
@carlossierra919
Жыл бұрын
@@jiejenn what is the parameter to use for weekly period ?
Great to learn new way to download the stock historical data from Yahoo finance, thanks. But I would like to know what is the different from using "yfinance" library or "pandas_datareader" library? Is this method better than those library?
@jiejenn
Жыл бұрын
Should be the same endpoint since there is only one. I prefer directly work with the endpoint just so if something changes, I don't have to wait till the author fix the package.
How do you get the import panda part
@jiejenn
2 жыл бұрын
Do you mean installing pandas package? In your terminal, pip install pandas.
Why does it skip some dates? Is it due to not having the information for that date?
@jiejenn
Ай бұрын
Weekends and holidays.
can you download a 2 hour time interval?
@jiejenn
3 жыл бұрын
If you want to download stock price every x hours, you will have to create a scraper.
@lordstrading6327
3 жыл бұрын
@@jiejenn Thanks Jen. Please can I email you? I am trying to find/scrap the volume data on plus500 website. But I can't find it.
Hello, Thank you for your effort and posting such a usufl video. I have followed the code however; when I run the code i'm getting urllib.error.HTTPError: HTTP Error 422: Unprocessable Entity. Anyone facing this issue?
@jiejenn
2 жыл бұрын
I just tested the script, and I am not getting the 422 error.
Hi Jie, I tried your code but got the followed error: HTTPError: HTTP Error 422: Unprocessable Entity How to fix this? Thanks in advance!
@leichen1842
2 жыл бұрын
Solved. For monthly data, we should use '1mo'
@jiejenn
2 жыл бұрын
Glad to see you solved your issue.
Hi Jie, thanks for your video, I found it very helpful. I am wondering if you know how to full financial statements data into excel? It would make the fundamental analysis much easier. Thanks heaps in advance
@jiejenn
3 жыл бұрын
Are you referring to the Financial Statements on the Financial tab? If so, then the only ways are either sign up for their Premium service or manually create a script to scrape the information.
@coconut7135
3 жыл бұрын
@@jiejenn Yes, thanks you very much!
Hi, sir. What broker are you in?
@jiejenn
2 жыл бұрын
I do my own investing.
@marcusrecarus3692
2 жыл бұрын
@@jiejenn How about the screenshot of your portfolio? Was it "I do my own investing."?
Download button is missing now :c
@jiejenn
Жыл бұрын
I just checked, it's still there.
How did you make money with that data?
@jiejenn
2 жыл бұрын
By doing some data analysis.
i want in minutes time frame
@jiejenn
2 жыл бұрын
Okay.
hey Jei, cannot fetch yahoo finance stock (daily closing data) now, i think yahoo finance restricted, any good solution for this problem?
@jiejenn
Жыл бұрын
I just tested the script, and it is working fine for me. Perhaps you have a typo somewhere? Either way, there should be an error message indicates what is causing the issue.
@ErtizaAbbas
Жыл бұрын
@@jiejenn hmm, actually, i am trying fetch data via yfinance , while yahoo finance historical data page doesn't present 'Donaload' clickable button, and this is the issue and i can't solve it
@jiejenn
Жыл бұрын
Then you will have to reach out to yfinance.
nooby programmer here! I got a long list of errors on my machine: please help :)) - urllib.error.URLError:
@jiejenn
Жыл бұрын
Maybe this post might help stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error