Skip to main content

Module convert

Module convert 

Source
Expand description

Conversions between securities identifiers.

An ISIN is the international wrapper around a national securities number (the NSIN). For three jurisdictions that wrapper is exact and reversible:

  US / CA ISIN   country prefix · 9-char NSIN · check   NSIN  IS  the CUSIP
  GB / IE ISIN   country prefix · 00 + SEDOL  · check   NSIN  IS  00 + SEDOL
  CH / LI ISIN   country prefix · 0…0 + VALOR · check   NSIN  IS  padded VALOR
  • A US or CA ISIN embeds a Cusip verbatim as its nine-character NSIN. Extracting the CUSIP is taking those nine characters; building the ISIN is prefixing US or CA and computing a fresh ISIN check digit.
  • A GB or IE ISIN embeds a seven-character Sedol right-aligned in the nine-character NSIN, left-padded with the two literal characters 00. Extracting the SEDOL strips that 00.
  • A CH or LI ISIN embeds a Valor — a one-to-nine-digit number — left-padded with zeros to nine digits. Extracting the VALOR strips the leading zeros.

The two check-digit schemes are independent: the CUSIP, SEDOL, and ISIN algorithms are unrelated, so every conversion recomputes — never reuses — the target’s check digit and re-parses the result through the target type’s own validator. A conversion with no defined meaning (a non-US/CA ISIN to a CUSIP, say) returns ConversionError::UnsupportedCountry; a conversion whose result is not a valid identifier returns ConversionError::NotConvertible or ConversionError::Validation. A conversion never returns a wrong answer.

Every *_to_isin function and build_isin left-pads a short national number into the nine-character NSIN field, so a Sedol (00 + 7) and a Valor (zero-padded to 9) land where the standard places them.

§References

  • ISO 6166 (ISIN), ANSI X9.6 (CUSIP), London Stock Exchange (SEDOL), SIX Financial Information (VALOR) — the schemes whose embedding rules these conversions implement.

Functions§

build_isin
Assembles an ISIN from a two-character country prefix and a national number, computing the ISIN check digit.
cusip_to_isin
Wraps a Cusip into an ISIN for the given country.
isin_to_cusip
Extracts the Cusip embedded in a United States or Canada ISIN.
isin_to_sedol
Extracts the Sedol embedded in a United Kingdom or Ireland ISIN.
isin_to_valor
Extracts the Valor embedded in a Switzerland or Liechtenstein ISIN.
sedol_to_isin
Wraps a Sedol into an ISIN for the given country.
valor_to_isin
Wraps a Valor into an ISIN for the given country.