Skip to main content

Python package for Swiss financial data

Project description

swiss-finance-data

Python package for Swiss financial data — official sources, clean API

PyPI version Tests Coverage License Python Downloads


Why swiss-finance-data?

Accessing Swiss financial data in Python is fragmented. Existing tools focus on US/global markets and provide limited support for Swiss-specific datasets.

swiss-finance-data aims to provide:

  • A unified, clean API for Swiss financial data
  • Official government data sources — no scraping
  • Extensible provider architecture
  • Long-term maintainability

Scope

swiss-finance-data focuses on:

  • Official and legally reusable data sources
  • Clean abstraction over data providers
  • Stability and long-term maintainability
  • Swiss-specific financial datasets

It does not aim to replace global data providers such as yfinance, but to complement them for Swiss markets.


Features

v0.2.0 — Available now:

  • SNB Policy Rate — Current and historical Swiss National Bank policy rates
  • SARON — Swiss Average Rate Overnight, the CHF risk-free reference rate (replaces LIBOR)
  • CHF FX Rates — EUR, USD, GBP, JPY, CAD, AUD, SEK, NOK, DKK vs CHF
  • Provider Architecture — Extensible system for multiple data sources
  • Tested & documented — 86% unit test coverage
  • Reliable — Official Swiss government data sources, no scraping
  • Robust error handling — Clear messages for invalid date ranges and future dates

Installation

pip install swiss-finance-data

Requirements: Python 3.10+

Requires internet access — data is fetched live from the official SNB API.


Quick Start

from swiss_finance import SNB, FX

# SNB Policy Rate
rate = SNB.get_policy_rate()
print(f"SNB Policy Rate: {rate}%")

# SARON — CHF risk-free rate (use in Sharpe ratio calculations)
saron = SNB.get_saron()
rf = saron / 100
print(f"SARON: {saron}%")

# CHF Exchange Rates
eur_chf = FX.get_rate("EUR")
usd_chf = FX.get_rate("USD")
print(f"EUR/CHF: {eur_chf}")
print(f"USD/CHF: {usd_chf}")

# Historical data
rates = SNB.get_historical_rates(start="2022-01")
saron_hist = SNB.get_historical_saron(start="2022-01")
fx_hist = FX.get_historical_rates("EUR", start="2022-01")
print(fx_hist.tail())
#                  rate
# date
# 2025-12-01  0.93313
# 2026-01-01  0.92732
# 2026-02-01  0.91406

API Documentation

SNB Policy Rate

# Current rate
SNB.get_policy_rate(provider='snb_official') -> float

# Historical rates
SNB.get_historical_rates(
    start='YYYY-MM',  # optional
    end='YYYY-MM',    # optional
    provider='snb_official'
) -> pd.DataFrame

# List providers
SNB.list_providers() -> list

SARON

# Current SARON rate
SNB.get_saron() -> float

# Historical SARON rates
SNB.get_historical_saron(
    start='YYYY-MM',  # optional
    end='YYYY-MM'     # optional
) -> pd.DataFrame

FX — CHF Exchange Rates

Supported currencies: EUR, USD, GBP, JPY, CAD, AUD, SEK, NOK, DKK

# Current rate
FX.get_rate(currency='EUR') -> float

# Historical rates
FX.get_historical_rates(
    currency='EUR',
    start='YYYY-MM',  # optional
    end='YYYY-MM'     # optional
) -> pd.DataFrame

# List supported currencies
FX.list_currencies() -> list

Error handling

from swiss_finance import SNB, FX, SNBAPIError, DataValidationError

try:
    rate = SNB.get_policy_rate()
except SNBAPIError as e:
    print(f"Failed to fetch data: {e}")

try:
    rates = SNB.get_historical_rates(start='2030-01')
except DataValidationError as e:
    print(f"Invalid date range: {e}")

Data Sources

All data sources are documented in docs/DATA_SOURCES.md.

Source Dataset License
Swiss National Bank SNB Policy Rate SNB Open Data terms
Swiss National Bank SARON (monthly avg, 2009+) SNB Open Data terms
Swiss National Bank CHF FX Rates (monthly avg, 1999+) SNB Open Data terms

Development

Setup

git clone https://github.com/EMen11/swiss-finance-data.git
cd swiss-finance-data
pip install -e .[dev]

Run tests

pytest --cov=swiss_finance tests/

API Stability

  • v0.x — API may evolve based on feedback
  • v1.0+ — Stable public API with backward compatibility guaranteed
  • Versioning follows Semantic Versioning (SemVer).

Roadmap

  • v0.1.0 — SNB policy rates
  • v0.1.1 — Improved error handling and date validation
  • v0.2.0 — SARON + CHF FX rates
  • v0.3.0 — SMI equities + Swiss government bonds
  • v0.4.0 — Real estate indices (SWIIT)
  • v1.0.0 — Stable API, full documentation

License

MIT License — see LICENSE for details.


Author

Elie Menassa

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

swiss_finance_data-0.2.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

swiss_finance_data-0.2.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file swiss_finance_data-0.2.0.tar.gz.

File metadata

  • Download URL: swiss_finance_data-0.2.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for swiss_finance_data-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9fa560d7c2562ff548849def27dd25261a93158ca828838a09359d6a41516479
MD5 7f8297847d1f775474d31e694c460f1d
BLAKE2b-256 846f1dcbc8e309a09d3fad1468696d16fc21fd88c5a86bb1a9d689a3ba901fa8

See more details on using hashes here.

File details

Details for the file swiss_finance_data-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for swiss_finance_data-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90da0e23ba573c6c9cff3051fc25a2ceab4177691f8f60362a85e4befd37a5ec
MD5 0ff646284388f23b98d44fc4dd5cdf34
BLAKE2b-256 1a9d33238907a940c0972bbcfc7dc2d17dc8edf51ce3080fb8c11a37cfd9bd94

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