Getting historical stock/ETF prices in python

Since I am the only non-software engineer here (:wink:), maybe someone has a tip for me here…

What are you using to get historical stock/etf prices directly in python?

The google finance API that used to work with is kaputt and the other API options listed here are limited in the time-span they cover, or the stocks/etfs they offer (limited European-listed stocks/etfs).


PS: Yes, I know I can do this all in google sheets…

You can try yahoo. I use it through beancount so I didn’t check the API myself but it seems to be able to find the data.

You’re right, thanks! I had read somewhere that it, too, had been discontinued, but didn’t actually try it out. Yahoo seems to have OK coverage of non-US-listed stocks.

I am using IEX Cloud.
Unfortunately, they do not have SIX coverage yet :frowning:

Here there is another one ! :wink::metro::railway_track::motorway:

1 Like

If you want to backtest your portfolio, I would suggest

I have also added SPI Extra with a csv.

Unfortunately, the YahooDailyReader API is buggy for some stocks/ETFs…

Ah yeah I noticed the same for this ETF when looking directly at their website. For some reason it shows a value around $60 outside of market hours…

Yeah, I guess it is their data not the API that is the problem… It’s almost as if it’s jumping to its GBP price rather than USD price on certain days.

The EUR denominated Amsterdam-listed version works (‘VWRL.AS’), but the first listing there was later.

For information, I started using Alpha Vantage API. I am able to get historical data for U.S. and Swiss ETF! It works great :slight_smile:

Thanks, I will look into that one. Google used to be the best API - too bad it is disabled.

I ended up just using Google Sheets to do this…

I was curious about how often the ETF dropped by X% as my strategy is regular purchases + extra ones when it drops by 6%, 12%, 18%, etc. from its last peak. By my count, with this strategy, I would have put extra money into VWRL 19 times in the past ~7 years (13 times at -6%, 5 at -12% and once at -18%).

1 Like

Just curious on the strategy - how much are these “extra” purchases (e.g. as proportion of your “regular” ones)?
And how did you decide for these 6/12/18% specifically?

Basically, the amount should be whatever I have in cash that I can reasonably put into an investment and still have a big enough amount of cash sitting around for normal expenses. Should be more or less equal to my normal monthly purchases. The 6% etc. is arbitrary, but back-checking makes this appear to be somewhat reasonable. This is a totally arbitrary strategy…but I think it is good to have a self-defined metric for putting extra money into the market to prevent too much emotional buying on bad news.


I am also using Alpha Vantage and I am satisfied. I am fetching the weekly data of all the stocks and etfs from nyse and nasdaq. The only problem is that the free account is limited to 1 call every 12 seconds, and maximum 500 calls per day

1 Like

Thanks for sharing and welcome to the community. Curious of hoy you implemented the data. Do you use Alpha Vantage with Excel?

I use Matlab and Python, but there is an add-on for Excel

I directly use the REST API with C++.

By reading and partipating to this forum, you confirm you have read and agree with the disclaimer presented on
En lisant et participant à ce forum, vous confirmez avoir lu et être d'accord avec l'avis de dégagement de responsabilité présenté sur