Currencies Module

Currency Framework

Currency

class pyquantlib.Currency

Bases: pybind11_object

Currency specification.

__init__() None

Default constructor, creates an empty currency.

code() str

Returns the ISO 4217 three-letter code, e.g., ‘USD’.

empty() bool

Returns true if this is an empty (uninitialized) currency.

fractionSymbol() str

Returns the fraction symbol, e.g., ‘c’ for cents.

fractionsPerUnit() int

Returns the number of fractional units per currency unit, e.g., 100.

name() str

Returns the full currency name, e.g., ‘U.S. Dollar’.

numericCode() int

Returns the ISO 4217 numeric code, e.g., 840.

rounding() Rounding

Returns the rounding convention for this currency.

symbol() str

Returns the currency symbol, e.g., ‘$’.

triangulationCurrency() Currency

Returns the triangulation currency, if any.

usd = ql.USDCurrency()
print(usd.name())   # "U.S. dollar"
print(usd.code())   # "USD"
print(usd.symbol()) # "$"

Available Currencies

Region

Currencies

Americas

USD, CAD, MXN, BRL, ARS, CLP, COP, PEN

Europe

EUR, GBP, CHF, SEK, NOK, DKK, PLN, CZK, HUF, RON

Asia-Pacific

JPY, CNY, CNH, HKD, SGD, AUD, NZD, KRW, TWD, INR, THB, MYR, IDR, PHP

Middle East/Africa

AED, SAR, ILS, ZAR, EGP, KES, NGN

Crypto

BTC, ETH, LTC, XRP, DASH, ZEC

Money

class pyquantlib.Money

Bases: pybind11_object

Amount of cash in a specific currency.

class ConversionType

Bases: pybind11_object

Conversion type for money arithmetic.

Members:

NoConversion : Do not perform conversions.

BaseCurrencyConversion : Convert both operands to base currency.

AutomatedConversion : Return result in the currency of the first operand.

__init__(value: SupportsInt | SupportsIndex) None
AutomatedConversion = <ConversionType.AutomatedConversion: 2>
BaseCurrencyConversion = <ConversionType.BaseCurrencyConversion: 1>
NoConversion = <ConversionType.NoConversion: 0>
Money.ConversionType.name -> str
property value
class Settings

Bases: pybind11_object

Per-session settings for Money arithmetic.

static instance() Money.Settings

Returns the singleton instance.

__init__(*args, **kwargs)
property baseCurrency

The base currency used for conversions.

property conversionType

The conversion type used for money arithmetic.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__() -> None

Default constructor.

  1. __init__(currency: Currency, value: SupportsFloat | SupportsIndex) -> None

Constructs from currency and value.

  1. __init__(value: SupportsFloat | SupportsIndex, currency: Currency) -> None

Constructs from value and currency.

currency() Currency

Returns the currency.

rounded() Money

Returns the amount rounded according to the currency.

value() float

Returns the amount.

AutomatedConversion = <ConversionType.AutomatedConversion: 2>
BaseCurrencyConversion = <ConversionType.BaseCurrencyConversion: 1>
NoConversion = <ConversionType.NoConversion: 0>
usd_amount = ql.Money(100.0, ql.USDCurrency())
print(usd_amount.value())
print(usd_amount.currency())

ExchangeRate

class pyquantlib.ExchangeRate

Bases: pybind11_object

Exchange rate between two currencies.

class Type

Bases: pybind11_object

Type of exchange rate.

Members:

Direct : Directly quoted rate.

Derived : Rate derived from other rates.

__init__(value: SupportsInt | SupportsIndex) None
Derived = <Type.Derived: 1>
Direct = <Type.Direct: 0>
ExchangeRate.Type.name -> str
property value
static chain(r1: ExchangeRate, r2: ExchangeRate) ExchangeRate

Creates a derived rate by chaining two rates.

__init__(source: Currency, target: Currency, rate: SupportsFloat | SupportsIndex) None

Constructs an exchange rate from source to target currency.

rate() float

Returns the exchange rate value.

source() Currency

Returns the source currency.

target() Currency

Returns the target currency.

type() ExchangeRate.Type

Returns the type of the exchange rate.

Derived = <Type.Derived: 1>
Direct = <Type.Direct: 0>
rate = ql.ExchangeRate(ql.EURCurrency(), ql.USDCurrency(), 1.10)
usd_amount = rate.exchange(eur_amount)

ExchangeRateManager

class pyquantlib.ExchangeRateManager

Bases: pybind11_object

Global repository for exchange rates.

static instance() ExchangeRateManager

Returns the singleton instance.

__init__(*args, **kwargs)
add(rate: ExchangeRate, startDate: Date = <Date: January 1st, 1901>, endDate: Date = <Date: December 31st, 2199>) None

Adds an exchange rate.

clear() None

Clears all stored exchange rates.

lookup(source: Currency, target: Currency, date: Date = <Date: null date>, type: ExchangeRate.Type = <Type.Derived: 1>) ExchangeRate

Looks up an exchange rate between two currencies.

Currency Implementations

USDCurrency

class pyquantlib.USDCurrency

Bases: Currency

! The ISO three-letter code is USD; the numeric code is 840. It is divided in 100 cents.

ingroup currencies

__init__() None

EURCurrency

class pyquantlib.EURCurrency

Bases: Currency

! The ISO three-letter code is EUR; the numeric code is 978. It is divided into 100 cents.

ingroup currencies

__init__() None

GBPCurrency

class pyquantlib.GBPCurrency

Bases: Currency

! The ISO three-letter code is GBP; the numeric code is 826. It is divided into 100 pence.

ingroup currencies

__init__() None

JPYCurrency

class pyquantlib.JPYCurrency

Bases: Currency

! The ISO three-letter code is JPY; the numeric code is 392. It is divided into 100 sen.

ingroup currencies

__init__() None

CHFCurrency

class pyquantlib.CHFCurrency

Bases: Currency

! The ISO three-letter code is CHF; the numeric code is 756. It is divided into 100 cents.

ingroup currencies

__init__() None