0
$\begingroup$

A simple code below to do currency conversion copied from QuantLib-Python Documentation. This is failing in the EUR to GBP conversion (in the last line of code). Thank you for looking into this. The ERROR message is-

UnicodeEncodeError: 'utf-8' codec can't encode character '\udca3' in position 0: surrogates not allowed

import QuantLib as ql
usd = ql.USDCurrency()
eur = ql.EURCurrency()
gbp = ql.GBPCurrency()

usdToeur = ql.ExchangeRate(eur, usd, 1.18)
gbpToeur = ql.ExchangeRate(eur, gbp, 0.85)

m_usd = 5 * usd
m_eur = 4.39 * eur
print( 'Converting from USD: ', m_usd, ' = ', usdToeur.exchange(m_usd))
print( 'Converting from EUR: ', m_eur, ' = ', usdToeur.exchange(m_eur))

print(usdToeur.source())
print(usdToeur.target())
print(usdToeur.rate())


print(gbpToeur.source())
print(gbpToeur.target())
print(gbpToeur.rate())

optNotional = 1000000 *eur

print(optNotional)

print(usdToeur.exchange(optNotional))

print(gbpToeur.exchange(optNotional))
$\endgroup$
2
  • $\begingroup$ What line gives the error? $\endgroup$
    – simsalabim
    Apr 3, 2021 at 15:37
  • $\begingroup$ The last line of the code $\endgroup$ Apr 23, 2021 at 5:02

1 Answer 1

1
$\begingroup$

Your last line is trying to print the sterling symbol but it seems it's not compatible with your terminal or your Python interpreter.

You can use

print(gbpToeur.exchange(optNotional).value())

instead, which doesn't try the fancy formatting and just outputs the number.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.