On the pathLiquidity3/3

Approximately Calculating USD Liquidity

An approximate US dollar liquidity index (WALCL − RRP − TGA) from FRED series fetched via OpenBB and compared with the S&P 500.

Research-0015Updated 5 min

Fig. — Net USD liquidity: Fed balance sheet minus TGA and RRP (illustrative)
Contents

What is the USD Liquidity Index

The USD Liquidity Index is a measure that indicates the dollars available in the market. This index indicates the ease with which banks and companies can access dollars for their activities.

When there is a high availability of dollars, interest rates are usually low, and conversely, when liquidity is low, interest rates rise, making access to financing more difficult.

The factors involved in this index are the monetary policies of the Federal Reserve of the United States, global economic conditions, and the global demand for dollars.

The formula is defined as:

WALCL (All Liabilities) – WLRRAL (RRP) – WDTGAL (TGA)

Where:

  1. WALCL represents the total amount of Federal Reserve liabilities, which includes bank reserves and other factors that inject liquidity into the system.
  2. WLRRAL (RRP) and WDTGAL (TGA) are mechanisms that drain or withdraw liquidity from the system. By subtracting them, you are eliminating the operations that decrease the amount of dollars available in the financial system.

Result: The net difference provides you with a measure of the available liquidity in the US financial system. The higher the number, the greater the amount of money circulating in the system.

Calculating the USD Liquidity Index in Python

To obtain these series, we will use OpenBB, specifically the openbb-fred extension and the openbb-economy extension. The first step is to import all the necessary libraries.

IN [01]python
from openbb import obb
from pandas import DataFrame

As we mentioned, we need two modules within the OpenBB library, which we will call as follows:

  • obb.economy.fred_search()
  • obb.economy.fred_series()
IN [02]python
data = obb.economy.fred_series(["WALCL", "WLRRAL", "WDTGAL", "SP500"])
data

OBBject

id: 066c7874-2012-7189-8000-1e79898a8a3c
results: [{'date': datetime.date(2002, 12, 18), 'WALCL': 719542.0, 'WLRRAL': 21905....
provider: fred
warnings: None
chart: None
extra: {'results_metadata': {'WALCL': {'title': 'Assets: Total Assets: Total Assets...

To access the metadata

IN [03]python
metadata = data.extra["results_metadata"]

metadata.keys()
metadata["WALCL"].get("title") 
metadata["WALCL"].get("units")

dict_keys(['WALCL', 'WLRRAL', 'WDTGAL', 'SP500'])'Assets: Total Assets: Total Assets (Less Eliminations from Consolidation): Wednesday Level''Millions of U.S. Dollars'

Searching and retrieving indices from FRED

First, let's search for the Wednesday level indices

IN [04]python
obb.economy.fred_search("Wednesday Levels").to_df().head(3)
OUT [04]
series_idtitleobservation_startobservation_endfrequencyfrequency_shortunitsunits_shortseasonal_adjustmentseasonal_adjustment_shortlast_updatedpopularitygroup_popularitynotes
0WALCLAssets: Total Assets: Total Assets (Less Elimi...2002-12-182024-08-14Weekly, As of WednesdayWMillions of U.S. DollarsMil. of U.S. $Not Seasonally AdjustedNSA2024-08-15 15:37:22-05
9494NaN
1H41RESPPALDKNWWAssets: Liquidity and Credit Facilities: Loans...2002-12-182024-08-14WeeklyWMillions of U.S. DollarsMil. of U.S. $Not Seasonally AdjustedNSA2024-08-15 15:37:01-05
7676NaN
2TREASTAssets: Securities Held Outright: U.S. Treasur...2002-12-182024-08-14Weekly, As of WednesdayWMillions of U.S. DollarsMil. of U.S. $

Next, we will search for the reverse repo Wednesday levels

IN [05]python

obb.economy.fred_search("Wednesday Levels Reverse Repo").to_df().head(3)
OUT [05]
series_idtitleobservation_startobservation_endfrequencyfrequency_shortunitsunits_shortseasonal_adjustmentseasonal_adjustment_shortlast_updatednotespopularitygroup_popularity
0WLRRALLiabilities and Capital: Liabilities: Reverse ...2002-12-182024-08-14Weekly, As of WednesdayWMillions of U.S. DollarsMil. of U.S. $Not Seasonally AdjustedNSA2024-08-15 15:37:49-05
Reverse repurchase agreements are transactions...6363
1WLRRAFOIALLiabilities and Capital: Liabilities: Reverse ...2002-12-182024-08-14Weekly, As of WednesdayWMillions of U.S. DollarsMil. of U.S. $Not Seasonally AdjustedNSA2024-08-15 15:37:36-05
Reverse repurchase agreements are transactions...4040
2WLRRAOLLiabilities and Capital: Liabilities: Reverse ...2002-12-182024-08-14Weekly, As of WednesdayWMillions of U.S. DollarsMil. of U.S. $

And the Treasury General Wednesday levels

IN [06]python
obb.economy.fred_search("Wednesday Levels Treasury General").to_df().head(3)
OUT [06]
series_idtitleobservation_startobservation_endfrequencyfrequency_shortunitsunits_shortseasonal_adjustmentseasonal_adjustment_shortlast_updatednotespopularitygroup_popularity
0WDTGALLiabilities and Capital: Liabilities: Deposits...2002-12-182024-08-14Weekly, As of WednesdayWMillions of U.S. DollarsMil. of U.S. $Not Seasonally AdjustedNSA2024-08-15 15:38:33-05
This account is the primary operational accoun...6464
1D2WLTGALLiabilities and Capital: Liabilities: Deposits...2002-12-182024-08-14Weekly, As of WednesdayWMillions of U.S. DollarsMil. of U.S. $Not Seasonally AdjustedNSA2024-08-15 15:38:37-05
NaN6060
2WLDLCLLiabilities and Capital: Liabilities: Deposits...2002-12-182024-08-14Weekly, As of WednesdayWMillions of U.S. DollarsMil. of U.S. $Not Seasonally Adjusted

And the S&P 500 price

IN [07]python
obb.economy.fred_search("SP500").to_df().head(2)
OUT [07]
series_idtitleobservation_startobservation_endfrequencyfrequency_shortunitsunits_shortseasonal_adjustmentseasonal_adjustment_shortlast_updatednotespopularitygroup_popularity
0SP500S&P 5002014-08-222024-08-21Daily, CloseDIndexIndexNot Seasonally Adjusted

We print the metadata

IN [08]python
for id in metadata:
    display(f"{id}: {metadata[id]['units']}")

'WALCL: Millions of U.S. Dollars''WLRRAL: Millions of U.S. Dollars''WDTGAL: Millions of U.S. Dollars''SP500: Index'

And we generate the Liquidity Index

IN [09]python
data.to_df().head(4)
data.to_df().dropna().head(4)
liquidity_index = DataFrame(data.to_df().dropna())
OUT [09]
WALCLWLRRALWDTGALSP500
date
---------------
2002-12-18719542.021905.06595.0NaN
2002-12-25732059.020396.04662.0NaN
2003-01-01730994.021091.04420.0NaN
2003-01-08723762.018709.05490.0NaN
WALCLWLRRALWDTGALSP500
date
---------------
2014-08-274413736.0282002.029547.02000.12
2014-09-034415587.0250306.021036.02000.72
2014-09-104421408.0267602.031872.01995.69
2014-09-174449588.0252224.0123965.02001.57

Organizing the Final DataFrame

IN [10]python
liquidity_index["USD Liquidity Index"] = (
    liquidity_index["WALCL"] - liquidity_index["WLRRAL"] - liquidity_index["WDTGAL"]
)
liquidity_index.tail(4)
OUT [10]
WALCLWLRRALWDTGALSP500USD Liquidity Index
date
------------------
2024-07-247205455.0805967.0767419.05427.135632069.0
2024-07-317178391.0813261.0854001.05522.305511129.0
2024-08-077175256.0681881.0785233.05199.505708142.0
2024-08-147177688.0722198.0788823.05455.215666667.0

Plotting using Plotly and normalizing the data so they can be compared

IN [11]python
y_axis = liquidity_index[["USD Liquidity Index", "SP500"]]


def absolute_maximum_scale(series):
    return series / series.abs().max()


def min_max_scaling(series):
    return (series - series.min()) / (series.max() - series.min())


def z_score_standardization(series):
    return (series - series.mean()) / series.std()


methods = {
    "z": z_score_standardization,
    "m": min_max_scaling,
    "a": absolute_maximum_scale,
}


def normalize(data: DataFrame, method: str = "z") -> DataFrame:
    for col in data.columns:
        data.loc[:, col] = methods[f"{method}"](data.loc[:, col])

    return data


normalized = normalize(y_axis, method="m")

normalized.tail(3)
OUT [11]
USD Liquidity IndexSP500
date
---------
2024-07-310.6435780.970490
2024-08-070.6988350.885139
2024-08-140.6872020.952750
IN [12]python
import pandas as pd

pd.options.plotting.backend = "plotly"
normalized.plot()



fig = go.Figure()

fig.add_scatter(
    x=normalized.index, y=normalized["USD Liquidity Index"], name="USD Liquidity Index"
)

fig.add_scatter(x=normalized.index, y=normalized["SP500"], name="S&P 500 Index")

fig.update_layout(
    title="USD Liquidity Index vs. S&P 500 Index (Normalized)",
    title_y=0.90,
    title_x=0.5,
    autosize=True,
)

Related posts: Limit Order Book: Aggregated Market Liquidity · Central Banks and Monetary Policy in Python.

Spotted an error? Let us know

Written by

Investor since 2014. Research since 2017. I have worked at several asset managers and crypto hedge funds. Passionate about code, data and finance. Currently based in Ukraine.