Class: SecID::SEDOL

Inherits:
Base
  • Object
show all
Includes:
Checkable
Defined in:
lib/sec_id/sedol.rb

Overview

Stock Exchange Daily Official List (SEDOL) - a 7-character alphanumeric code that identifies securities traded on the London Stock Exchange and other UK exchanges.

Format: 6-character identifier + 1-digit check digit Note: SEDOL excludes vowels (A, E, I, O, U) to avoid forming words.

Examples:

Validate a SEDOL

SecID::SEDOL.valid?('B19GKT4')  #=> true

Calculate check digit

SecID::SEDOL.check_digit('B19GKT')  #=> 4

See Also:

Constant Summary collapse

FULL_NAME =

Human-readable name of the standard.

'Stock Exchange Daily Official List'
ID_LENGTH =

Valid length(s) of a normalized identifier.

7
EXAMPLE =

A representative valid identifier.

'B0YBKJ7'
VALID_CHARS_REGEX =

Pattern matching the identifier's permitted character set.

/\A[0-9BCDFGHJKLMNPQRSTVWXYZ]+\z/
ID_REGEX =

Regular expression for parsing SEDOL components. Excludes vowels (A, E, I, O, U) from valid characters.

/\A
  (?<identifier>[0-9BCDFGHJKLMNPQRSTVWXYZ]{6})
  (?<check_digit>\d)?
\z/x
CHARACTER_WEIGHTS =

Weights applied to each character position in the check digit calculation.

[1, 3, 1, 7, 3, 9].freeze
GENERATE_CHARSET =

Characters valid in a SEDOL body (alphanumeric excluding vowels).

ALPHANUMERIC.grep(VALID_CHARS_REGEX).freeze
ISIN_COUNTRY_CODES =

Valid country codes for SEDOL to ISIN conversion.

Set.new(%w[GB IE GG IM JE FK]).freeze

Constants included from Checkable

Checkable::CHAR_TO_DIGIT, Checkable::CHAR_TO_DIGITS

Constants included from Generatable

Generatable::ALPHA, Generatable::ALPHANUMERIC, Generatable::DIGITS

Constants included from Validatable

Validatable::ERROR_MAP

Constants included from Normalizable

Normalizable::SEPARATORS

Instance Attribute Summary

Attributes inherited from Base

#full_id, #identifier

Instance Method Summary collapse

Methods included from Checkable

#restore, #restore!, #to_s, #valid?

Methods inherited from Base

#==, #as_json, example, full_name, has_check_digit?, #hash, id_length, length_specificity, length_values, short_name, #to_h

Methods included from Validatable

#errors, #valid?, #validate, #validate!

Methods included from Normalizable

#normalize!, #normalized, #to_pretty_s, #to_s, #to_str

Constructor Details

#initialize(sedol) ⇒ SEDOL

Returns a new instance of SEDOL.

Parameters:

  • sedol (String)

    the SEDOL string to parse



43
44
45
46
47
# File 'lib/sec_id/sedol.rb', line 43

def initialize(sedol)
  sedol_parts = parse sedol
  @identifier = sedol_parts[:identifier]
  @check_digit = sedol_parts[:check_digit]&.to_i
end

Instance Method Details

#calculate_check_digitInteger

Returns the calculated check digit (0-9).

Returns:

  • (Integer)

    the calculated check digit (0-9)

Raises:



65
66
67
68
# File 'lib/sec_id/sedol.rb', line 65

def calculate_check_digit
  validate_format_for_calculation!
  mod10(weighted_sum)
end

#to_isin(country_code = 'GB') ⇒ ISIN

Returns a new ISIN instance with calculated check digit.

Parameters:

  • country_code (String) (defaults to: 'GB')

    the ISO 3166-1 alpha-2 country code (default: 'GB')

Returns:

  • (ISIN)

    a new ISIN instance with calculated check digit

Raises:



55
56
57
58
59
60
61
# File 'lib/sec_id/sedol.rb', line 55

def to_isin(country_code = 'GB')
  unless ISIN_COUNTRY_CODES.include?(country_code)
    raise InvalidFormatError, "'#{country_code}' is not a valid SEDOL country code!"
  end

  ISIN.new("#{country_code}00#{restore}").restore!
end