Market data is crucial for backtesting your trading strategies, but is often not free and can be quite expensive. But finding free or cheap sources requires knowing where to look, and the options vary wildly by data type.
If you think of market data as just the OHLCV (Open, High, Low, Close, Volume) bars then that can be challenging to get for all markets beyond a daily granularity.
Low Granularity Market Data
For OHLCV data that is at the day timeframe, you can very easily get this data from Yahoo Finance using the yfinance python library to easily download the daily data for the symbol from (probably) when it was first listed. For example, you can get the data for the OHLCV bars for Coca Cola stock from the 2nd January 1962 till present.
High Granularity Market Data
For minute frequency OHLCV data, you can get most major assets that you’d need from Alpaca and you can use their python library to get the data in a useable form.
For symbols or timeframes Alpaca doesn't cover, you'll need a workaround, you can do an approach that will take longer but over time you will generate a database of minutely data. This method is just to get the maximum minutely data that yahoo finance will give you (which is 7 days) and then repeat this weekly and put it into a database. This allows you to very slowly generate your own database of minutely data for any symbol you’d need it for.
If you’d like to get the minutely data from yahoo and add it to your own database, you can do this with this script I created that by default captures some symbols that I just arbitrarily picked.
Fundamental & Economic Data
Fundamental data is free to just download from the SEC website. For Foreign Exchange, you can download from the many different sources depending on the country. I’ve listed sources for countries economies below for major currencies:
United Kingdom (GBP)
- Bank of England (opens in a new tab) - Interest Rates
- Office for National Statistics (opens in a new tab) - Inflation rate and other economic information
United States of America (USD)
- US Bureau of Labour Statistics (opens in a new tab) - Inflation rate and other economic information
- Federal Reserve Bank of St. Louis (opens in a new tab) - Interest Rates and other economic information
Europe (EUR)
- European Central Bank (opens in a new tab) - Interest Rates & Inflation rate (or as they call it cost of borrowing for a household) & other economic information
For “all” countries you can get more specific data from World Development Indicators which may be useful for an industry that is very fragile to shocks in things like fuel usage by a country.
Forex Data
Foreign Exchange data is very easy to get as you can just download it up to tick level granularity in some cases from HistData for free. Although this source doesn’t contain all foreign exchange markets, it does contain all major pairs.
Final thoughts
If the free sources don't cover what you need, paid alternatives like DataBento offer comprehensive data across all asset classes. However, the trade-off is worth considering: free data works well for stocks and forex, but futures and options markets simply don't have reliable free sources. If your strategy requires options or futures data, you'll likely need to budget for a paid service.
For more trading strategy guides and backtesting tips, check out the rest of my blog at mrgreeny.dev/blog.