Skip to content

Models

models

Business domain model for equities_classifier.

ClassificationNode(value: str, code: str | None = None) dataclass

Single hierarchy node.

code: str | None = None class-attribute instance-attribute

value: str instance-attribute

ClassificationSystem(id: ClassificationSystemID, display_name: str, short_name: str, authorities: tuple[str, ...], hierarchy: tuple[str, ...], supports_codes: bool) dataclass

Definition of a classification system.

authorities: tuple[str, ...] instance-attribute

display_name: str instance-attribute

hierarchy: tuple[str, ...] instance-attribute

id: ClassificationSystemID instance-attribute

short_name: str instance-attribute

supports_codes: bool instance-attribute

Security(name: str | None = None, ticker: str | None = None, provider_attributes: dict[str, dict[str, Any]] = dict(), classifications: list[SecurityClassification] = list(), *, identifiers: list[SecurityIdentifier] = list()) dataclass

Security class.

classifications: list[SecurityClassification] = field(default_factory=list) class-attribute instance-attribute

name: str | None = None class-attribute instance-attribute

provider_attributes: dict[str, dict[str, Any]] = field(default_factory=dict) class-attribute instance-attribute

ticker: str | None = None class-attribute instance-attribute

provider_attribute(provider: DataSourceID, attribute: str) -> Any | None

Return a provider-specific attribute.

Source code in src/equities_classifier/models.py
def provider_attribute(
    self,
    provider: DataSourceID,
    attribute: str,
) -> Any | None:
    """Return a provider-specific attribute."""
    return self.provider_attributes.get(provider, {}).get(attribute)

SecurityClassification(system: ClassificationSystem, nodes: dict[ClassificationLevel, ClassificationNode]) dataclass

Classification of a security.

nodes: dict[ClassificationLevel, ClassificationNode] instance-attribute

system: ClassificationSystem instance-attribute

SecurityIdentifier(type: SecurityIdentifierType, value: str) dataclass

Security identifier.

country: str | None = field(init=False) class-attribute instance-attribute

type: SecurityIdentifierType instance-attribute

value: str instance-attribute

value_cleaned: str | None = field(init=False) class-attribute instance-attribute

__post_init__() -> None

Strip identifier value and for Ticker split into value_cleaned and country provided as postfix. NOTE: derived attributes where not marked with a leading _ to allow transparent access as for orignal value.

Source code in src/equities_classifier/models.py
def __post_init__(self) -> None:
    """Strip identifier value and for Ticker split into value_cleaned and country provided as postfix.
     NOTE: derived attributes where not marked with a leading _ to allow transparent access as for orignal value.
     """

    # strip value
    object.__setattr__(self, "value", self.value.strip())

    # allow country suffix for ticker
    if self.type != SecurityIdentifierType.TICKER or "." not in self.value:
        object.__setattr__(self, "value_cleaned", self.value)
        object.__setattr__(self, "country", None)
    else:
        value_cleaned, country = self.value.split(".")
        object.__setattr__(self, "value_cleaned", value_cleaned)
        object.__setattr__(self, "country", country)

get_country()

Getter functkion for country.

Source code in src/equities_classifier/models.py
def get_country(self):
    """Getter functkion for country."""
    return self.country

get_value_cleaned()

Getter function for value_cleaned

Source code in src/equities_classifier/models.py
def get_value_cleaned(self):
    """Getter function for value_cleaned"""
    return self.value_cleaned

SecurityIdentifierIdentifiable(*, identifiers: list[SecurityIdentifier] = list()) dataclass

Base class for objects identified by security identifiers.

identifiers: list[SecurityIdentifier] = field(default_factory=list) class-attribute instance-attribute

has_identifier(identifier_type: SecurityIdentifierType) -> bool

Check if an identifier of a specific type is registered.

Source code in src/equities_classifier/models.py
def has_identifier(
    self,
    identifier_type: SecurityIdentifierType,
) -> bool:
    """Check if an identifier of a specific type is registered."""

    return self.identifier(identifier_type) is not None

identifier(identifier_type: SecurityIdentifierType) -> SecurityIdentifier | None

Find identifier of a specific type.

Source code in src/equities_classifier/models.py
def identifier(
    self,
    identifier_type: SecurityIdentifierType,
) -> SecurityIdentifier | None:
    """Find identifier of a specific type."""

    return next(
        (
            identifier
            for identifier in self.identifiers
            if identifier.type is identifier_type
        ),
        None,
    )

identifier_country(identifier_type: SecurityIdentifierType) -> str | None

Return country of an identifier of a type TICKER.

Source code in src/equities_classifier/models.py
def identifier_country(
    self,
    identifier_type: SecurityIdentifierType,
) -> str | None:
    """Return country of an identifier of a type TICKER."""

    identifier = self.identifier(identifier_type)
    return identifier.country if identifier is not None else None

identifier_value(identifier_type: SecurityIdentifierType) -> str | None

Return value of an identifier of a specific type.

Source code in src/equities_classifier/models.py
def identifier_value(
    self,
    identifier_type: SecurityIdentifierType,
) -> str | None:
    """Return value of an identifier of a specific type."""

    identifier = self.identifier(identifier_type)
    return identifier.value if identifier is not None else None

identifier_value_cleaned(identifier_type: SecurityIdentifierType) -> str | None

Return cleaned value of an identifier of a specific type.

Source code in src/equities_classifier/models.py
def identifier_value_cleaned(
    self,
    identifier_type: SecurityIdentifierType,
) -> str | None:
    """Return cleaned value of an identifier of a specific type."""

    identifier = self.identifier(identifier_type)
    return identifier.value_cleaned if identifier is not None else None

SecurityProviderRecord(name: str | None = None, ticker: str | None = None, *, identifiers: list[SecurityIdentifier] = list()) dataclass

Base class for SecurityProviderRecord classes ensuring common fields are contained.

datasource: DataSourceID class-attribute

name: str | None = None class-attribute instance-attribute

ticker: str | None = None class-attribute instance-attribute

provider_attributes() -> dict[str, Any]

Return all provider-specific attributes.

Source code in src/equities_classifier/models.py
def provider_attributes(self) -> dict[str, Any]:
    """Return all provider-specific attributes."""

    return {
        field.name: getattr(self, field.name)
        for field in fields(self)
        if field.name != "identifiers" and getattr(self, field.name) is not None
    }