FX — CHF Exchange Rates
The FX class provides CHF exchange rates sourced from the Swiss National Bank (monthly data, 1999+).
Supported currencies
| Code | Currency |
|---|---|
EUR |
Euro |
USD |
US Dollar |
GBP |
British Pound |
JPY |
Japanese Yen |
CAD |
Canadian Dollar |
AUD |
Australian Dollar |
SEK |
Swedish Krona |
NOK |
Norwegian Krone |
DKK |
Danish Krone |
All rates are expressed as units of foreign currency per 1 CHF.
FX.get_rate
Get the current CHF exchange rate for a given currency.
Parameters:
| Parameter | Type | Description |
|---|---|---|
currency |
str |
Currency code (e.g. 'EUR', 'USD') |
provider |
str |
Data provider (default: 'snb_fx') |
Returns: Current exchange rate as float (units of currency per 1 CHF).
Raises: ValueError if currency not supported, FetchError if fetch fails.
Example:
eur_chf = FX.get_rate("EUR")
print(f"EUR/CHF: {eur_chf}")
# EUR/CHF: 0.9321
usd_chf = FX.get_rate("USD")
print(f"USD/CHF: {usd_chf}")
# USD/CHF: 0.8854
# Convert 1000 CHF to EUR
chf_amount = 1000
eur_amount = chf_amount * eur_chf
print(f"1000 CHF = {eur_amount:.2f} EUR")
# 1000 CHF = 932.10 EUR
FX.get_historical_rates
Get historical CHF exchange rates (monthly, 1999+).
Parameters:
| Parameter | Type | Description |
|---|---|---|
currency |
str |
Currency code |
start |
str |
Start date YYYY-MM (optional) |
end |
str |
End date YYYY-MM (optional) |
provider |
str |
Data provider (default: 'snb_fx') |
Returns: DataFrame with DatetimeIndex and rate column.
Raises: ValueError if currency not supported or start > end.
Example:
# Plot EUR/CHF since 2015
import matplotlib.pyplot as plt
rates = FX.get_historical_rates("EUR", start="2015-01")
rates.plot(title="EUR/CHF Monthly (SNB)")
plt.ylabel("EUR per CHF")
plt.tight_layout()
plt.show()
# Compare multiple currencies
import pandas as pd
currencies = ["EUR", "USD", "GBP"]
df = pd.DataFrame({
ccy: FX.get_historical_rates(ccy, start="2020-01")["rate"]
for ccy in currencies
})
df.plot(title="CHF FX Rates (SNB, 2020+)")
FX.list_currencies
List all supported currency codes.
Example:
Data source
Exchange rates are sourced from the SNB data portal (data.snb.ch), cube devkum. Data is monthly and available from January 1999.
Note
Rates represent monthly averages, not spot rates. For intraday or daily FX data, a commercial provider is required.