Verifying with Python! Visualizing the Relationship Between Money Supply (M2) and Gold Prices
"When money is printed, gold prices rise."
This is a common saying in the investment world.
In fact, it is said that when monetary easing or quantitative easing is implemented, the value of fiat currency relatively decreases, making gold prices prone to rising.
So, is that really the case?
This time, using Python,
US M2 (Money Supply)
Gold Price
I combined these to,
"M2 ÷ Gold Price"
create and analyze a unique indicator.
Data Used
I used two types of data this time.
M2 (Money Supply)
M2 was obtained from FRED (Federal Reserve Economic Data).
In Python, you can easily obtain it just by using pandas_datareader.
#FREDからデータ取得
def fred(symbol,start,end):
df = data.FredReader(symbol, start, end)
date = df.read().index
value = df.read()[symbol]
return date, value
m2_date, m2_price = fred("M2NS", start, end)Since it is updated monthly, you can automatically retrieve the latest data.
Gold Price
On the other hand, I used a CSV file for the gold price.
gold_history = pd.read_csv('chart_20260625T044248.csv')The dates in the CSV are
01/01/1915 #month/day/yearin a string format (object type), so
gold_history["Date"] = pd.to_datetime(
gold_history["Date"],
format="%m/%d/%Y"
)I am converting it to datetime type as follows.
After that,
gold_history = gold_history.set_index("Date")
gold_value = gold_history['Value']I made it possible to handle it as time-series data with.
Merging M2 and Gold Prices
Since both use the date and time as an index,
merge_df = pd.DataFrame()
merge_df["gold"] = gold_value
merge_df["m2"] = m2_price
merge_df.dropna(inplace=True)you can easily merge them just by.
Pandas is very convenient because it automatically aligns data where the dates match.
Proprietary Indicator "M2 to Gold Ratio"
The indicator I created this time is as follows.
merge_df["ratio"] = (
merge_df["m2"] /
merge_df["gold"]
)In other words,
an indicator obtained by dividing the amount of money in the market by the gold price
is what it becomes.
The larger this value is,
the more undervalued gold is relative to the money supply
and the smaller it is,
the more overvalued gold is relative to the money supply
can be considered.
Of course, this is an indicator I created for analysis and does not indicate the fair price of gold. However, it can be used as a yardstick for observing long-term trends.
Adding Moving Averages
To make it easier to grasp the trend,
50-month moving average
100-month moving average
200-month moving average
were also calculated.
merge_df["SMA50"] = (
merge_df["ratio"]
.rolling(50)
.mean()
)
merge_df["SMA100"] = (
merge_df["ratio"]
.rolling(100)
.mean()
)
merge_df["SMA200"] = (
merge_df["ratio"]
.rolling(200)
.mean()
)To observe long-term trends, overlaying moving average lines makes changes easier to understand.
Create graph

The green line represents the ratio of M2 to gold prices.
Furthermore,
Blue: 50-month moving average
Red: 100-month moving average
Yellow: 200-month moving average
are overlaid.
By doing this, you can check short-term, medium-term, and long-term trends simultaneously.
What can be read from the graph
Looking at the graph, it is clear that the ratio of M2 to gold prices is not constant but follows a large cycle.
In the 1970s, the ratio dropped significantly due to the surge in gold prices.
The ratio increased in the early 2000s, but has since declined again following the financial crisis, quantitative easing, and the COVID-19 pandemic.
Also, the ratio is currently at a low level compared to the past, which indicates that gold prices remain relatively high in relation to the increase in money supply.
Of course, you cannot make investment decisions based solely on this ratio. However, it is interesting that by viewing gold prices from the perspective of money supply, you can grasp long-term changes that are difficult to notice from news alone.
The fun of analyzing with Python
In this analysis, by using Python, I was able to combine different data sources to create my own unique indicators.
Beyond just using existing technical indicators,
“What would happen if I combined this data with that data?”
The ability to analyze with that kind of mindset is the appeal of Python.
Since you can automate the entire flow of acquiring, processing, and visualizing data, once you have created the program, you can easily reproduce the same analysis with the latest data.
Summary
In this article, I used Python to calculate the ratio of money supply (M2) to gold prices and visualized the long-term trends.
Here are the three things I learned from this analysis:
You can handle different data by combining FRED and CSV
You can easily merge time-series data with Pandas
By creating your own indicators, you can analyze the market from a new perspective
Python is a powerful tool that allows you to not only look at existing data but also realize your own unique analysis.
この記事は noteマネー にピックアップされました

