From about September 2017 Yahoo! stopped traditional ways of doing automatic queries for getting historical stocks series. This code, being able to go over the limitations, can scrape over the web site and collect in a text format (both a .csv and .dat file for each needed title) all the avaible info about stocks (Date, Open, High, Low, Close, Adjusted Close, Volume).
Keep in Mind this is just a demo version of the code, so it has no running options and, by deafult, it is able to download stocks declared in sec.py file (line 6).
titles=["CORN", "UGA", "NDAQ", "FB", "RDS-A"]
For each title the time window considered is 3 years, you can easly change it through the line 78 of functions.py file:
date_2=(addYears(date_1, -3))
For all this kind of reasons, it should be clear the main point of strength of this code is not its performance...So if you have to use it for downloading a lot of stocks titles you firstly have to put your hands on it for a review, keeping always in mind there's a bottleneck with your speed network...
This code has been posted just for trying you to solve any troubles about querying Yahoo!Finance servers and so it clearly needs to be
adapted to fit your activity at best. So, feel free to change this few lines of code and reuse it as just as you think it is better...
At the end (but surely not at the least!) I would be grateful to you if you'd share with me your impovements for this code...
Thanks in advance!
For running just digit the execution command for any Python script in a cmd:
python sec.py
After running, program creates a folder with all the stocks files, as in the example:
A single file result in detail:
Code entirely written in Python 3.5.1. Feel free to contact me at: v.colamatteo@yahoo.it
.