Skip to main content

Macro-economic data-source clients (CPI, central-bank rates) for the okama project

Project description

okama-macro

Macro-economic data-source clients — CPI inflation and central-bank / policy rates — for the okama project.

One package, one HTTP/DataFrame layer, one dependency. It consolidates the macro source clients that used to live as separate per-source micro-repos and as in-repo modules of okama-API, behind a single unified series API. Rationale and migration history: mbk-dev/okama-API#41 and its ADR 0001.

Install

pip install okama-macro

Requires Python ≥ 3.11. Runs on both pandas 2.x and 3.x.

Quick start

import okama_macro

okama_macro.list_series()
# ['CHN_LPR1.RATE', 'CHN_LPR5.RATE', 'CNY.INFL', 'EU_DFR.RATE',
#  'EU_MLR.RATE', 'EU_MRO.RATE', 'GBP.INFL', 'HKD.INFL', 'HK_BR.RATE',
#  'ILS.INFL', 'IND_RBI.RATE', 'INR.INFL', 'ISR_IR.RATE', 'UK_BR.RATE',
#  'USD.INFL', 'US_EFFR.RATE']

# A rate as a decimal fraction (3.62% -> 0.0362), observations only:
okama_macro.get('US_EFFR.RATE', first_date='2020-01-01')

# Monthly m/m inflation as a decimal fraction:
okama_macro.get('USD.INFL')

The contract

Every series returned by get() obeys the same contract, so callers never special-case a source:

  • Decimal fractions — m/m inflation 0.0042, a rate 0.0525 (never percent, never an index level).
  • CPI series are monthly, stamped on the first of the month, derived from the source's index via pct_change() (base-invariant).
  • Rate series normally carry observations only — no padding. Forward-fill to a daily grid on the consumer side if you need one. UK_BR.RATE is the documented exception: the Bank of England source publishes change dates, and the client safely forward-fills them into a daily series.
  • Ascending DatetimeIndex, float dtype, and Series.name == key.

get() raises ValueError for an unknown key (listing the known ones); list_series() returns the available keys, sorted.

Available series

Key Series Source module
USD.INFL US CPI, m/m fred (FRED CPIAUCNS)
HKD.INFL Hong Kong Composite CPI, m/m censtatd (HK C&SD)
INR.INFL India General CPI, m/m mospi (MOSPI)
CNY.INFL China CPI, m/m nbsc (NBS China)
GBP.INFL UK CPIH, m/m ons (UK ONS)
ILS.INFL Israel CPI, m/m boi (Bank of Israel)
US_EFFR.RATE US Federal Funds rate fred (FRED DFF)
HK_BR.RATE HKMA Discount Window Base Rate hkma
IND_RBI.RATE RBI policy repo rate bis (history) + rbi (same-day tail)
CHN_LPR1.RATE China one-year Loan Prime Rate cfets
CHN_LPR5.RATE China five-year Loan Prime Rate cfets
ISR_IR.RATE Bank of Israel policy rate boi
EU_MRO.RATE ECB main refinancing operations rate ecb
EU_MLR.RATE ECB marginal lending facility rate ecb
EU_DFR.RATE ECB deposit facility rate ecb
UK_BR.RATE Bank of England Bank Rate boe

Raw per-source clients

Each source also exposes its raw client under okama_macro.sources.*, returning data as the agency publishes it (CPI index levels, rates in percent) — use these only if you need the unnormalised series; prefer get() otherwise.

from okama_macro.sources import (
    bis, boe, boi, censtatd, cfets, ecb, fred, hkma, mospi, nbsc, ons, rbi
)

hkma.get_base_rate()          # percent, daily
censtatd.get_composite_cpi()  # CPI index level, monthly

Configuration (environment)

Variable Needed for Notes
FRED_API_KEY USD.INFL, US_EFFR.RATE Free key from FRED; kept out of logs.
PROXY_HOST, PROXY_PORT bis, mospi, rbi Optional outbound HTTP proxy.
PROXY_USER, PROXY_PASS Optional proxy credentials.

Architecture

okama_macro/
├── __init__.py        # public API: get(), list_series()
├── registry.py        # key -> normalised Series (the contract)
├── _http.py           # shared Session: retry/back-off, proxy, browser UA,
│                       #   legacy-TLS, secret redaction
├── _frame.py          # DataFrame/Series shaping helpers
└── sources/           # one client per source (bis, boe, boi, censtatd, cfets,
                        #   ecb, fred, hkma, mospi, nbsc, ons, rbi)

Two layers: thin sources (data as published, on the shared _http) and a registry that normalises each key to the contract above.

Development

poetry install
poetry run pytest        # test suite
poetry run ruff check .  # lint (rules C, E, F, W, B)

CI runs the suite and lint on Python 3.11, 3.12, 3.13 and 3.14. poetry.lock is intentionally untracked.

License

MIT.

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

okama_macro-0.1.0.tar.gz (33.2 kB view details)

Uploaded Source

Built Distribution

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

okama_macro-0.1.0-py3-none-any.whl (47.8 kB view details)

Uploaded Python 3

File details

Details for the file okama_macro-0.1.0.tar.gz.

File metadata

  • Download URL: okama_macro-0.1.0.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for okama_macro-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b15916e12793a215df327757de08a9c1d51eba8fe2e1f8a8157b5ea937bc74e7
MD5 a7afe2ee227e485f75c95268ea77d160
BLAKE2b-256 f7d6c8fe9dcca7bfa58ff2ed00d590a0e3e7e5d07dcf0985c47c66b517788087

See more details on using hashes here.

Provenance

The following attestation bundles were made for okama_macro-0.1.0.tar.gz:

Publisher: publish-to-pypi.yml on mbk-dev/okama-macro

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file okama_macro-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: okama_macro-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 47.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for okama_macro-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64ed131e4f639795d2307964e494b902f5c02e91f1c1ee612b90c495d4aff1f4
MD5 e093c9151e234d9da05fdbf91e67a912
BLAKE2b-256 6cbfad66e83a27296b219db399945e1a0b297c7ee4863a6e3e51a7c06bdf937b

See more details on using hashes here.

Provenance

The following attestation bundles were made for okama_macro-0.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on mbk-dev/okama-macro

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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