xotl.tools.dim.currencies – Concrete numbers for money

Concrete numbers for money.

You may have 10 dollars and 5 euros in your wallet, that does not mean that you have 15 of anything (but bills, perhaps). Though you may evaluate your cash in any other currency you don’t have that value until you perform an exchange with a given rate.

This module support the family of currencies. Usage:

>>> from xotl.tools.dim.currencies import Rate, Valuation, currency
>>> dollar = USD = currency('USD')
>>> euro = EUR = currency('EUR')
>>> rate = 1.19196 * USD/EUR

>>> isinstance(dollar, Valuation)
True

>>> isinstance(rate, Rate)
True

# Even 0 dollars are a valuation
>>> isinstance(dollar - dollar, Valuation)
True

# But 1 is not a value nor a rate
>>> isinstance(dollar/dollar, Valuation) or isinstance(dollar/dollar, Rate)
False

Currency names are case-insensitive. We don’t check the currency name is listed in ISO 4217. So currency MVA is totally acceptable in this module.

We don’t download rates from any source.

This module allows you to trust your computations of money by allowing only sensible operations:

>>> dollar + euro  
Traceback (...)
...
OperandTypeError: unsupported operand type(s) for +: '{USD}/{}' and '{EUR}/{}

If you convert your euros to dollars:

>>> dollar + rate * euro
2.19196::{USD}/{}

# Or your dollars to euros
>>> dollar/rate + euro
1.83895432733::{EUR}/{}