Class: SecID::SEDOL

Inherits:
Base
  • Object
show all
Includes:
Checkable, Suggestable
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 checksum Note: SEDOL excludes vowels (A, E, I, O, U) to avoid forming words.

Examples:

Validate a SEDOL

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

Calculate checksum

SecID::SEDOL.checksum('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})
  (?<checksum>\d)?
\z/x
CHARACTER_WEIGHTS =

Weights applied to each character position in the checksum 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 Suggestable

SecID::Suggestable::HOMOGLYPHS, SecID::Suggestable::RANK

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 Suggestable

#suggest

Methods included from Checkable

#calculate_check_digit, #check_digit, #restore, #restore!, #to_s, #valid?

Methods inherited from Base

#==, #as_json, #deconstruct_keys, detection_priority, example, full_name, has_check_digit?, has_checksum?, #hash, id_length, length_specificity, length_values, short_name, #to_h, type_key

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



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

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

Instance Method Details

#calculate_checksumInteger

Returns the calculated checksum (0-9).

Returns:

  • (Integer)

    the calculated checksum (0-9)

Raises:



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

def calculate_checksum
  validate_format_for_calculation!
  mod10(weighted_sum)
end

#to_isin(country_code = 'GB') ⇒ ISIN

Returns a new ISIN instance with calculated checksum.

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 checksum

Raises:



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

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