How to get stock fundamentals data with Python
theautomatic.net
theautomatic.net
https://www.youtube.com/parttimelarry
It covers popular services and libraries like Alpaca, Robinhood Private API, TD Ameritrade option prices, Yahoo Finance, TradingView alerts, backtesting, and a lot more.
I'm asking because I've used semi-pro and pro infra (paid services) and it was hard to get consistent returns. It was easy to get returns, but rarely beyond, say, S&P 500 returns (at which point, I might as well just invest in the S&P 500 index.)
What you really want to know is "how problematic is the noise in this data"?
One way to answer it is to create your own FF sorts [1] and regress your Yahoo-derived factor returns against Ken French's (which come from CRSP/Compustat). If the intercepts are small/statistically insignificant and the R2's reasonable, then you're all set.
The big problem you will hit is survivorship bias in Yahoo!. My own research suggests that the quality is perfectly acceptable, provided you back-fill an unbiased universe (e.g. Russell 3K) from another source.
I'm actually surprised you didn't outperform the market with the survivorship bias. Back test must have covered a very small time period.
[1] https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data...
You need a set of companies that lacks this bias, and the set of Russell 3000 index constituents is a good set to use.
Some of the older Russel 3000 companies will be missing from Yahoo, because they are delisted or bankrupt. You need to find a secondary source for them, or "back-fill" your securities master.
Math is funny that way. Miss out on some fundamental aspect and it'll ruin you. And Khan explains some really basic concepts in ways that has given me new perspective or insight.
Depends how new you are to it all, but assuming you just know basic trading stuff (what a bid/offer is, what options greeks are, etc..). Everything I do is stat arb type of trades. My path won't be the same as yours, but here's how I started.
What I did...
- read literally every link and topic under https://www.investopedia.com (the education tab -> investing trading section on the right)
- quantopian.com - look under the learning tab. I went through all the material - literally all of it. There's a series of Lectures that explains a ton
- quantconnect.com - I went through all their tutorials. Read through the existing strategies to get a feel for everything and gain insights - https://www.quantconnect.com/tutorials/strategy-library
- Absorbed almost everything Ernie Chan has written. This was the first book that got me interested in all this - https://www.amazon.com/Quantitative-Trading-Build-Algorithmi...
I read a _ton_ and played around with lots and lots of data to try and get my systems working. Still no where near where I'd like to be, but been profitable since the beginning (minus a giant loss on some gambles I took - I no longer trade discretionary because of this). The links I pasted above are what I'd consider the "easy" part of all this, anyone can read and learn. Learning the more in-depth stuff around specific topics is harder, but I have a bunch of books (willing to share some recommendations if you need).
Once you progress, you'll find specific areas you're interested in (equity options, commodity futures, spread trades, fixed income/bonds, etc.. ).
edit: think I should follow up with a comment/question I ask myself alot. Is all the work/time worth it? In my case, I'd say yes, because I've always had an interest in finance and literally would be reading + working with markets on the side for fun anyway. If I think of all the effort poured into this vs say working for some large tech company... I'd probably say just go work the high paying tech job. Obviously you can make money in the markets, but the tradeoff for keeping your sanity is a very real question you have to ask yourself.
To answer your question, I started in equities but moved to commodity and index futures/options.
The important math for understanding the foundations of finance and business isn't advanced math. It is accounting - primarily addition, subtraction and simple algebra or calculus 101 for things like interest calculations or discounted value modeling. This basic math also underpins the "fundamentals" of business used in objective, common-sense investing - the kind Warren Buffett is fond of.
Also, "stocks" and math are a classic "the map is not the territory" situation. Math describes stocks and business performance very well but does not define it. A machine learning algorithm trained on historical price data in concert with differential equations of 1,000 variables will historically do no better at investing than buying and holding index funds.
Technical Analysts "quants" would disagree, but alas: https://www.bloomberg.com/news/articles/2020-05-02/after-qua...
So the thing to focus on isn't going from math -> stock trading. It is to learn accounting and business and basic stock market concepts. Eventually a math background will help, but it's support not the foundation.
So far I have only found https://eodhistoricaldata.com and haven't tested them yet, is there anything better?
You can also scrape the fundamentals directly from the 10-K statements each company publishes, but it's very difficult to get a clean, consistent dataset out of it.
You're almost always better off getting the data yourself and cleaning it.
Is Yahoo cool with web scraping? Is it just something they tolerate? Are they just too incompetent to care?
If you have a use case where a program in C runs in a reasonable time on your laptop but one in Python doesn't, that solution is only going to take you so far before you'll want to graduate from your laptop and take advantage of the Python ecosystem again in real big data contexts.
https://www.interactivebrokers.com/en/index.php?f=14193#coll...
I cannot recommend the stock prices though. Somehow there were just a lot of mistakes and you can get them from other sources cheaper.
https://developer.tdameritrade.com/option-chains/apis/get/ma...
IEX only does end of day pricing and even that is delayed until the next day.
In full disclosure, I work at Tradier.
Disclaimer: One of my writers wrote it for my blog