Appearance
What is a CUSIP Number
CUSIP stands for Committee on Uniform Securities Identification Procedures and is pronounced Q-sip.
A CUSIP number identifies most financial securities in the United States and Canada, including: stocks of all registered U.S. and Canadian companies, commercial paper, and U.S. government and municipal bonds.
These numbers are used to help facilitate trades and settlements by providing a constant identifier to help distinguish the securities within a trade.
CUSIP numbers format
CUSIP numbers consist of nine characters (including letters and numbers).
- The first six alphanumeric characters are known as the base or CUSIP-6, which identifies the issuer.
- The seventh and eighth digits identify the type of security.
- The ninth digit is a check digit that is automatically generated.
For instance,
Apple's common stock CUSIP is 037833100
. Apple's company identifier is 037833
and the security identifiers are 10
for the common stock and the last 0
is the check digit.
And a CUSIP for one of Apple's outstanding bonds is 037833AK6
. The company identifier is still 037833
and the security identifiers are AK
for that specific bond and the last 6
is the check digit.
Some CUSIP numbers examples:
Security | CUSIP |
---|---|
SPY ETF | 78462F103 |
VOO ETF | 922908363 |
QQQ ETF | 46090E103 |
Apple Stock | 037833100 |
Microsoft Stock | 594918104 |
Meta(Facebook) Stock | 30303M102 |
How to generate the check digit
The 9th digit is an automatically generated check digit using the "Modulus 10 Double Add Double" technique based on the Luhn algorithm.
- Begining at the rightmost character(the 8th character) and moving left, every second character is multiplied by two(including the rightmost character).
INFO
Letters are converted to numbers. The letter A will be 10, and the value of each subsequent letter will be the preceding letter’s value incremented by 1. In other words, A=10, B=11, C=12, ..., Z=35.
- Sum the values of the resulting digits (numbers greater than 10 become two seperate digits).
- The check digit is calculated by
10 - (s mod 10)) mod 10
, wheres
is the sum from step 2. This is the smallest number (possibly zero) that must be added tos
to make a multiple of 10.
For example, in the case of 037833AK6
, the payload is 037833AK
and the calculation steps are as the following table.
The swift language version validating the CUSIP check digit algorithm is as the following code.
swift
func isValidCUSIP( cusip:String) -> Bool {
let cusipchars = Array("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
let multiple = [1,2,1,2,1,2,1,2]
if cusip.count != 9 {
return false
}
let cusipArray = Array(cusip)
var sum = 0
for i in 0...7 {
guard let index = cusipchars.firstIndex(of: cusipArray[i]) else {
return false
}
let num = index * multiple[i]
sum += (num%10 + num/10)
}
guard let check = Int(String(cusipArray[8])) else {
return false
}
let calCheck = (10 - (sum % 10))%10 // or 9 - ((sum+9) % 10)
return check == calCheck
}