Path: blob/master/data/create_stooq_data.ipynb
2908 views
Download and store STOOQ data
This notebook contains information on downloading the STOOQ stock and ETF price data that we use in Chapter 09 for a pairs trading strategy based on cointegration and Chapter 11 for a long-short strategy using Random Forest return predictions.
Imports & Settings
Set Data Store path
Modify the path to the DATA_STORE
if you would like to store the data elsewhere and change the notebooks accordingly
Stooq Historical Market Data
Note that the below downloading details may change at any time as Stooq updates their website; if you encounter errors, please inspect their website and raise a GitHub issue to let us know so we can update the information.
Update 12/2020: please note that STOOQ will disable automatic downloads and require CAPTCHA starting Dec 10, 2020 so that the code that downloads and unpacks the zip files will no longer work; please navigate to their website here for manual download.
Download price data
Download price data for the selected combination of asset class, market and frequency from the Stooq website
Store the result under
stooq
using the preferred folder structure outlined on the website. It has the structure:/data/freq/market/asset_class
, such as/data/daily/us/nasdaq etfs
.
Use the symbol for the market you want to download price data for. In this book we'll be useing us
and jp
.
Add symbols
Add the corresponding symbols, i.e., tickers and names by following the directory tree on the same site. You can also adapt the following code snippet using the appropriate asset code that you find by inspecting the url; this example works for NASDAQ ETFs that have code g=69
:
Store price data in HDF5 format
To speed up loading, we store the price data in HDF format. The function get_stooq_prices_and_symbols
loads data assuming the directory structure described above and takes the following arguments:
frequency (see Stooq website for options as these may change; default is
daily
market (default:
us
), andasset class (default:
nasdaq etfs
.
It removes files that do not have data or do not appear in the corresponding list of symbols.
We'll be using US equities and ETFs in Chapter 9 and and Japanese equities in Chapter 11. The following code collects the price data for the period 2000-2019 and stores it with the corresponding symbols in the global assets.h5
store: