Skip to main content

Market liquidity proxies

Project description

CI Coverage PyPI License

Market Liquidity Proxies

This repository provides an overview of key market liquidity proxies and additional alternatives for crypto, bond, and stock markets. These proxies serve as indicators of market sentiment, risk appetite, and liquidity conditions.


Global Liquidity Model

The Global Liquidity Model provides a index of net liquidity in the financial system by aggregating key U.S. economic indicators from the FRED database. It combines the effects of the Federal Reserve balance sheet, bank reserves, reverse repo operations, and the U.S. Treasury General Account to estimate market liquidity. The model highlights how central bank actions and fiscal flows impact liquidity, offering a clear, data-driven perspective through an interactive stacked area chart.

Crypto Proxies

  1. Ethereum / Bitcoin (ETH / BTC): Reflects liquidity preference and risk sentiment within the cryptocurrency market. Barring idiosyncratic events it acts as a proxy for broader market liquidity.

Stock Market ETF Ratios

  1. QQQ / SPY Ratio: Reflects liquidity preference and risk sentiment within the US stock market. Shows the performance of high-beta QQQ (Nasdaq-100) vs. SPY (S&P 500).

Bond Market ETF Yield Spreads

Reflect funding stress in the broader market. When liquidity is ample, spreads tend to be tight, and they widen when liquidity is drained and stress builds in the system.

  1. HYG / LQD Spread: Measures the risk premium between high-yield (HYG) and investment-grade bonds (LQD).

  2. LQD / TNX Spread: Measures the risk premium between investment-grade bonds (LQD) and 10-year Treasury yields (UST-10Y).

Installation

Install package from PyPi: In order to install package use package manager of your choice, the most standard command is:

pip install liquidity

Retrieve API Key: Depending on what charts/models you want to generate you will need corresponding key:

Set the api-key as an environment variable.

export FRED_API_KEY="<your-api-key>"
export ALPHAVANTAGE_API_KEY="<your-api-key>"

Usage

Below are some example code snippets:

Example 1: Generate liquidity model

from liquidity.models.liquidity import GlobalLiquidity

model = GlobalLiquidity()
model.show()

The code will retrieve data using the FRED Economic database API, and generate the liquidity chart. Below example of generated chart: Liquidity proxies

To generate the model for a specific date range:

from liquidity.models.liquidity import GlobalLiquidity
from datetime import datetime

model = GlobalLiquidity(
    start_date=datetime(2021, 1, 1),
    end_date=datetime(2024, 12, 31)
)
model.show()

Next examples demonstrate how to display multiple liquidity proxies charts combined into a single matrix, showcasing various liquidity proxies and date periods:

Example 2: Display a 2x2 Matrix from specific date

from datetime import datetime
from liquidity.models import YieldSpread, PriceRatio
from liquidity.visuals import ChartMatrix

# Define a ChartMatrix object with 4 models
liquidity_proxies = ChartMatrix(
    models=[
        YieldSpread("HYG", "LQD"),
        YieldSpread("LQD", "UST-10Y"),
        PriceRatio("QQQ", "SPY"),
        PriceRatio("ETH", "BTC"),
    ],
    start_date=datetime(2020, 1, 1),
)

# Display the matrix grid of charts
liquidity_proxies.show()

This code will retrieve data from the available API providers for each of the specified liquidity proxies and display them in a 2x2 matrix chart. The charts will cover the period starting from January 1, 2020. Here's a preview of what the result will look like: Liquidity proxies

Example 3: Display a 2x3 Matrix of Charts for a specific year As the number of models increases, the method automatically determines the optimal layout for the matrix grid. For instance, if you have six charts, the layout will adjust accordingly.

Here’s an example of displaying a 2x3 matrix for the year 2024:

from datetime import datetime
from liquidity.models import YieldSpread, PriceRatio
from liquidity.visuals import ChartMatrix

# Define a ChartMatrix object with 6 models
liquidity_proxies = ChartMatrix(
    models=[
        YieldSpread("HYG", "LQD"),
        YieldSpread("HYG", "UST-10Y"),
        YieldSpread("LQD", "UST-10Y"),
        PriceRatio("QQQ", "SPY"),
        PriceRatio("BTC", "QQQ"),
        PriceRatio("ETH", "BTC"),
    ],
    start_date=datetime(2024, 1, 1),
    end_date=datetime(2024, 12, 31),
)

# Display the matrix of charts
liquidity_proxies.show()

This example retrieves data for the specified liquidity proxies over the year 2024 and displays the results in a 2x3 matrix. The layout will automatically adjust based on the number of models, ensuring the charts are well-organized and easy to interpret. Here is an example output for the 2024 data: Liquidity proxies

Notes:

  • Optional start_date and end_date Parameters: Both the start_date and end_date parameters are optional. If not specified, the method will use the full available data range for each chart. However, be aware that this may cause the time frames of each chart to differ, as different symbols (e.g., "HYG", "QQQ", "ETH") may have varying lengths of historical data available from the API providers.

  • Automatic Layout Adjustment: As the number of models increases, the method will automatically adjust the layout of the matrix to ensure the charts are displayed in a clean, readable format.

  • Data Retrieval: The charts will pull data from available API providers once a day (subsequent calss will be loaded from cache) for the specified models, ensuring accurate and up-to-date information.

  • Custom Date Ranges: If you want to focus on specific time periods, you can provide both start_date and end_date. Otherwise, the method will display data for the full available range.

Data Sources

This repository is based on market data APIs providing free access to data.

Future Improvements

In the future I plan to add even more data providers and liquidity proxies.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

liquidity-0.3.2.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

liquidity-0.3.2-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file liquidity-0.3.2.tar.gz.

File metadata

  • Download URL: liquidity-0.3.2.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for liquidity-0.3.2.tar.gz
Algorithm Hash digest
SHA256 59feb90cb2ed374cf3542239a2e81a17f1fbe4dddadc600df089fed484ea0fe6
MD5 0c341513910f3e4fbe6d4d01fa2ff492
BLAKE2b-256 ec478d4acf603173e4d2e7ba4fbc0671c7c30d3237b089706ec342ba49e94dce

See more details on using hashes here.

File details

Details for the file liquidity-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: liquidity-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for liquidity-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8e47c5aaff4d89fedddf8b996a4b6bdd9ebedd719dd4e4f8ce4c194937895f3f
MD5 5d99090198ee92eaadae4a417c8903b0
BLAKE2b-256 d49d4dadc4cf6d37ac2caf03e86fcdcb61f812b1ecf41cc540bdf182a4d1e66c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page