top of page

Historical Stock Price downloader

Updated: Mar 6

[You can download the Historical Stock Price downloader Python Notebook from the Resources page]


Edit (6 Mar 2025): Since last week, I've been getting Error 429 despite the url working fine in Chrome. I guess Yahoo's started blocking requests from webscrapers. To get around it, change the read_json(symbol) function to instantiate the url request and add headers to pretend you're Chrome or Mozilla or some browser and not python, then use urlopen(). I've updated the scripts here accordingly. Cheers!


Yahoo Finance recently locked their historical stock prices export function behind their Gold membership paywall. Thankfully, their JSON query is still available. Here's a Python code (in Jupyter notebook format) that pulls and exports the prices into a csv file.


One way to test out the code is to use colab.google. Copy-paste the code into the notebook, edit the tickers and range etc, run it, and you should be able to find the csv file under the files section.



Download the csv file, and the historical closing prices of the stocks should all be there.


For the more advanced users, you might want to generate an executable file that points to your existing Excel or csv file with all the symbols in the top row, and update the file directly with the latest prices when you run the executable. Personally, I just converted it into a python script and wrote a batch file to run it. A double-click on the .bat file and the csv magically appears in the same directory. The python file allows easy edits too, if needed. I find this to be a good compromise between flexibility and convenience.


Hope this is useful! And if it is, do kindly acknowledge the website, and donations are always welcome. Every little bit helps! :)

Comments


Post: Blog2_Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Financial Literacy Singapore. Proudly created with Wix.com

bottom of page