Skip to main content

GICS

This library provides a way to parse, manipulate and analyze GICS codes. GICS (Global Industry Classification Standard) is a classification system by MSCI

The original package https://github.com/dorklein/py-gics was fork-updated here https://github.com/ErnstHaagsman/py-gics but not published. Neither were the changes pulled. This fork was then upgraded to consistent and not deprecated setup/packaging interface.

Installation

poetry

poetry add py-gics-updated

pip

pip install py-gics-updated

Usage

In practice, GICS codes are represented by strings (just as dates can be). This library provides a wrapper for the string that allows the user to manipulate and display the represented GICS code in different ways. To wrap a string representing a GICS code, just build a new instance of GICS passing the string as the first argument.

Example

from gics import GICS

valid_sector_level_GICS = GICS('10')
print(valid_sector_level_GICS.sector.name)  # 'Energy'

valid_full_GICS = GICS('10101010')
print(valid_full_GICS.sector.name)  # 'Energy'
print(valid_full_GICS.sub_industry.name)  # 'Oil & Gas Drilling'
print(valid_full_GICS.level(4).name)  # 'Oil & Gas Drilling'
print(valid_full_GICS.level(3).name)  # 'Energy Equipment & Services'
print(valid_full_GICS.sector.code)  # '10'

GICS API

This section describes every method and property in the GICS object

Constructor

Description

Represents a GICS code. You can instantiate GICS codes using a string representing a code. The string has to be a valid GICS. If it's not, that isValid method will return false. Note that creating an empty GICS will mark it as invalid but can still be used to query the definitions (although that object itself will not be a definition)

@class      GICS GICS
@param      {string}  code     GICS code to parse. Valid GICS codes are strings 2 to 8 characters long, with even length.
@param      {string}  version  Version of GICS definition to use. By default the latest in the package available definition (so far 2023-0318 with description updates form 2025) is used. Versions are named after the date in which they became effective, following the format YYYYMMDD. Current available versions are: 20140228 and 20160901 and 20180929 and 20230318 (default).
@throws     {Error}            Throws error if the version is invalid/unsupported.

Example

from gics import GICS

gics = GICS('4040')  # Default GICS definition version (20160901)
gics_old = GICS('4040', '20140228')  # GICS using a previous definition 

sector

Description

Gets the definition for the sector of this GICS object (GICS level 1)

@return     {object}  Definition of the GICS level. It has 3 properties: name, description and code. Keep in mind that only level 4 usually has a description.

Example

from gics import GICS

gics = GICS('1010')
print(gics.sector.name)  # 'Energy'
print(gics.sector.code)  # '10'

industry_group

Description

Gets the definition for the industry group of this GICS object (GICS level 1)

@return     {object}  Definition of the GICS level. It has 3 properties: name, description and code. Keep in mind that only level 4 usually has a description.

Example

from gics import GICS

gics = GICS('453010')
print(gics.industry_group.name)  # 'Semiconductors & Semiconductor Equipment'
print(gics.industry_group.code)  # '4530'
 # If asked for a component that's not defined by this level, it returns null
print(gics.sub_industry)  # null

industry

Description

Gets the definition for the industry of this GICS object (GICS level 1)

@return     {object}  Definition of the GICS level. It has 3 properties: name, description and code. Keep in mind that only level 4 usually has a description.

Example

from gics import GICS

gics = GICS('453010')
print(gics.industry.name)  # 'Semiconductors & Semiconductor Equipment'
print(gics.industry.code)  # '453010'

sub_industry

Description

Gets the definition for the sub-industry of this GICS object (GICS level 1)

@return     {object}  Definition of the GICS level. It has 3 properties: name, description and code. Keep in mind that only level 4 usually has a description.

Example

from gics import GICS

gics = GICS('45301010')
print(gics.sub_industry.name)  # 'Semiconductor Equipment'
print(gics.sub_industry.code)  # '45301010'
print(gics.sub_industry.description)  # 'Manufacturers of semiconductor equipment, including manufacturers of the raw material and equipment used in the solar power industry'

level(gicsLevel)

Description

Gets the definition of the given level for this GICS object.

@param      {number}  gicsLevel  Level of GICS to get. Valid levels are: 1 (Sector), 2 (Industry Group), 3 (Industry), 4 (Sub-Industry)

Example

from gics import GICS

gics = GICS('45301010')
print(gics.level(1) == gics.sector)  # true
print(gics.level(2) == gics.industry_group)  # true
print(gics.level(3) == gics.industry)  # true
print(gics.level(4) == gics.sub_industry)  # true

children

Description

Gets all the child level elements from this GICS level. For example, for a Sector level GICS, it will return all Industry Groups in that Sector. If the GICS is invalid (or empty, as with a null code), it will return all Sectors. A Sub-industry level GICS will return an empty array.

@return     {array} Array containing objects with properties code (the GICS code), name (the name of this GICS), and description (where applicable)

Example

from gics import GICS

gics = GICS('10')
print(gics.children.length)  # 10
print(gics.children[1].code)  # '1010'

is_same(another_gics)

Description

Determines if this GICS is the same as the given one. To be considered the same both GICS must either be invalid, or be valid and with the exact same code. This means that they represent the same values at the same level.

@param      {object}  another_gics  GICS object to compare with

Example

from gics import GICS

gics1 = GICS('1010')
gics2 = GICS('1010')
gics1.is_same(gics2)  # true
gics2.is_same(gics1)  # true

is_within(another_gics)

Description

Determines if this GICS is a sub-component of the given GICS. For example, GICS 101010 is within GICS 10. Invalid GICS do not contain any children or belong to any parent, so if any of the GICS are invalid, this will always be false. Two GICS that are the same are not considered to be within one another (10 does not contain 10).

@param      {GICS}  another_gics  GICS object to compare with

Example

from gics import GICS

GICS('10101010').is_within(GICS('10'))  # true
GICS('101010').is_within(GICS('10'))  # true
GICS('101010').is_within(GICS('1010'))  # true
GICS('1010').is_within(GICS('10'))  # true
GICS('10').is_within(GICS('10'))  # false
GICS('1010').is_within(GICS('1010'))  # false
GICS('invalid').is_within(GICS('10'))  # false
GICS('10').is_within(GICS('invalid'))  # false
GICS('invalid').is_within(GICS('invalid'))  # false

is_immediate_within(another_gics)

Description

Determines if this GICS is a sub-component of the given GICS at the most immediate level. For example, GICS 1010 is immediate within GICS 10, but 101010 is not. Invalid GICS do not contain any children or belong to any parent, so if any of the GICS are invalid, this will always be false. Two GICS that are the same are not considered to be within one another (10 does not contain 10).

@param      {GICS}  another_gics  GICS object to compare with

Example

from gics import GICS

GICS('10101010').is_immediate_within(GICS('10'))  # false
GICS('101010').is_immediate_within(GICS('10'))  # false
GICS('101010').is_immediate_within(GICS('1010'))  # true
GICS('1010').is_immediate_within(GICS('10'))  # true
GICS('10').is_immediate_within(GICS('10'))  # false
GICS('1010').is_immediate_within(GICS('1010'))  # false
GICS('invalid').is_immediate_within(GICS('10'))  # false
GICS('10').is_immediate_within(GICS('invalid'))  # false
GICS('invalid').is_immediate_within(GICS('invalid'))  # false

contains(another_gics)

Description

Determines if this GICS contains the given GICS. For example, GICS 10 contains GICS 101010. Invalid GICS do not contain any children or belong to any parent, so if any of the GICS are invalid, this will always be false. Two GICS that are the same are not considered to be within one another (10 does not contain 10).

@param      {GICS}  another_gics  GICS object to compare with

Example

from gics import GICS

GICS('10').contains(GICS('10101010'))  # true
GICS('10').contains(GICS('101010'))  # true
GICS('10').contains(GICS('1010'))  # true
GICS('10').contains(GICS('10'))  # false
GICS('1010').contains(GICS('10'))  # false
GICS('invalid').contains(GICS('10'))  # false
GICS('10').contains(GICS('invalid'))  # false
GICS('invalid').contains(GICS('invalid'))  # false

contains_immediate(another_gics)

Description

Determines if this GICS contains the given GICS at the most immediate level. For example, GICS 10 contains immediate GICS 1010, but not 101010. Invalid GICS do not contain any children or belong to any parent, so if any of the GICS are invalid, this will always be false. Two GICS that are the same are not considered to be within one another (10 does not contain 10).

@param      {GICS}  another_gics  GICS object to compare with

Example

from gics import GICS

GICS('10').contains_immediate(GICS('10101010'))  # false
GICS('10').contains_immediate(GICS('101010'))  # false
GICS('10').contains_immediate(GICS('1010'))  # true
GICS('10').contains_immediate(GICS('10'))  # false
GICS('1010').contains_immediate(GICS('10'))  # false
GICS('invalid').contains_immediate(GICS('10'))  # false
GICS('10').contains_immediate(GICS('invalid'))  # false
GICS('invalid').contains_immediate(GICS('invalid'))  # false

Publish with poetry - replaced by GitHub Action

# Make sure to update the version in pyproject.toml
poetry build
poetry publish

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_gics_updated-0.2.2.tar.gz (52.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_gics_updated-0.2.2-py3-none-any.whl (55.0 kB view details)

Uploaded Python 3

File details

Details for the file py_gics_updated-0.2.2.tar.gz.

File metadata

  • Download URL: py_gics_updated-0.2.2.tar.gz
  • Upload date:
  • Size: 52.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for py_gics_updated-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b835b79889a3d8ef4d3700974a00273dfccb15d81ce2926ec13b5218eca74f43
MD5 d855ca1e765aff648edf0159029f7a0c
BLAKE2b-256 cdfe248220e1c58ae91f164b61260a65817489cd2cecc6c6ab83a8654cc2d1db

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_gics_updated-0.2.2.tar.gz:

Publisher: publish.yml on dornech/py-gics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_gics_updated-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: py_gics_updated-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 55.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for py_gics_updated-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 241dc0628abb4bb1011c6f860590f34889aef5f9fb013c19b91c58478ee0afa6
MD5 55c0f987d11886b356f399d7bf0db78c
BLAKE2b-256 c54f155244818dcc1a43e3c690ae658cb6d24a3d9f73cdbfa4ef14c197594935

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_gics_updated-0.2.2-py3-none-any.whl:

Publisher: publish.yml on dornech/py-gics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page