示例#1
0
def validate_isin(isin):
    """
    Validate an ISIN
    """
    if (len(isin) == 12 and isin[:2] in NUMBERING_AGENCIES.keys()
            and isin_checksum(isin[:11]) == isin[11]):
        return True
    else:
        return False
示例#2
0
def validate_isin(isin):
    """
    Validate an ISIN
    """
    if len(isin) == 12 \
       and isin[:2] in NUMBERING_AGENCIES.keys() \
       and isin_checksum(isin[:11]) == isin[12]:
        return True
    else:
        return False
示例#3
0
def cusip2isin(cusip, nation=None):
    # Validate inputs
    if not validate_cusip(cusip):
        raise ValueError("'%s' is not a valid CUSIP" % cusip)

    nation = nation or "US"
    if nation not in NUMBERING_AGENCIES.keys():
        raise ValueError("'%s' is not a valid country code" % nation)

    # Construct ISIN
    base = nation + cusip
    return base + isin_checksum(base)
示例#4
0
def cusip2isin(cusip: str, nation: Optional[str] = None) -> str:
    # Validate inputs
    if not validate_cusip(cusip):
        raise ValueError("'%s' is not a valid CUSIP" % cusip)

    nation = nation or "US"
    if nation not in NUMBERING_AGENCIES.keys():
        raise ValueError("'%s' is not a valid country code" % nation)

    # Construct ISIN
    base = nation + cusip
    return base + isin_checksum(base)
示例#5
0
def validate_isin(isin: str) -> bool:
    """
    Validate an ISIN
    """
    if (
        len(isin) == 12
        and isin[:2] in NUMBERING_AGENCIES.keys()
        and isin_checksum(isin[:11]) == isin[11]
    ):
        return True
    else:
        return False
示例#6
0
def cusip2isin(cusip, nation=None):
    # Validate inputs
    if not validate_cusip(cusip):
        raise ValueError("'%s' is not a valid CUSIP" % cusip)

    nation = nation or 'US'
    if nation not in NUMBERING_AGENCIES.keys():
        raise ValueError("'%s' is not a valid country code" % nation)

    # Construct ISIN
    base = nation + cusip
    return base + ISINchecksum(base)
示例#7
0
def isin_checksum(base):
    """
    Compute the check digit for a base International Securities Identification
    Number (ISIN).  Input an 11-char alphanum str, output a single-char str.

    http://goo.gl/8kPzD
    """
    assert len(base) == 11
    assert base[:2] in NUMBERING_AGENCIES.keys()
    check = ''.join([str(int(char, 36)) for char in base])
    check = check[::-1]  # string reversal
    check = ''.join([d if n % 2 else str(int(d)*2) for n, d in enumerate(check)])
    return str((10 - sum([int(d) for d in check]) % 10) % 10)
示例#8
0
def isin_checksum(base: str) -> str:
    """
    Compute the check digit for a base International Securities Identification
    Number (ISIN).  Input an 11-char alphanum str, output a single-char str.

    http://goo.gl/8kPzD
    """
    assert len(base) == 11
    assert base[:2] in NUMBERING_AGENCIES.keys()
    check = "".join([str(int(char, 36)) for char in base])
    check = check[::-1]  # string reversal
    check = "".join([d if n % 2 else str(int(d) * 2) for n, d in enumerate(check)])
    return str((10 - sum([int(d) for d in check]) % 10) % 10)