Lightweight tools to collect and visualise M1 money supply against equity indices and constituents, and cryptocurrencies.
This small repo fetches M1 Money Supply from FRED, appends market data from Yahoo Finance, and provides simple utilities to visualise the series and compute long/short-term correlations.
- Fetch M1 series from FRED and save a single CSV (
data/data.csv). - Append index and constituent close prices from Yahoo Finance.
- Visualise M1 vs an index, a constituent, and a cryptocurrency using matplotlib.
- Compute per-year and per-quarter Pearson correlations with optional time-lagging to output a Fisher z-transformed averaged correlation coefficent.
Key concept — Fisher z-transformed average correlation
-
Problem: averaging Pearson r values directly is biased.
-
Approach (used by
src/calculating_correlation.py):- Compute Pearson r for each group (e.g. each year or each quarter).
- Apply Fisher z-transform: z = arctanh(r) (maps r in (-1,1) to real line).
- Average the z values: mean_z = mean(z_i).
- Convert back to correlation: avg_r = tanh(mean_z).
This stabilises variance and gives a sound aggregated correlation estimate.
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -e .- Provide secrets in a
.envfile at repository root:
cp .env.example .env
FRED_API_KEY=your_fred_api_key_here- Run the srcipts:
python run.py- All runtime parameters live under the
configs/directory (Hydra + OmegaConf). - Common config keys live in
configs/data_loader.yamlandconfigs/calculating_correlation.yaml. - You can override any config value on the command line. Example:
python src/data_loader.py load_data.start_date=2020-01-01 load_data.end_date=2024-12-31- Network:
yfinanceandfredapirequire outbound internet access. - Forward-fill / placeholders: if the data loader cannot fetch new M1 values it may forward-fill
the last value; that will produce zero-variance groups and cause NaNs in per-group Pearson
correlations. If you see NaNs in correlation output inspect
data/data.csvfor long runs of identicalM1_Money_Supplyvalues and fix the upstream fetch (preferred) or drop/NaN those rows.
- License: MIT (see
LICENSE)