GICS
This library provides a way to parse, manipulate and analyze GICS codes.
GICS (Global Industry Classification Standard) is a classification system by MSCI
Installation
npm install gics --save
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
const GICS = require("gics");
let validSectorLevelGICS = new GICS("10");
console.log(gics.sector)
let validFullGICS = new GICS("10101010");
console.log(validFullGICS.sector.name)
console.log(validFullGICS.subIndustry.name)
console.log(validFullGICS.level(4).name)
console.log(validFullGICS.level(3).name)
console.log(validFullGICS.sector.code)
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 definition is used.
Versions are named after the date in which they became effective, following the format YYYYMMDD.
Current available versions are: 20140228 and 20160901 (default).
@throws {Error} Throws error if the version is invalid/unsupported.
Example
const GICS = require("gics");
let gics = new GICS("4040");
let gicsOld = new GICS("4040", "20140228");
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
const GICS = require("gics");
let gics = new GICS("1010");
console.log(gics.sector.name);
console.log(gics.sector.code);
industryGroup
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
const GICS = require("gics");
let gics = new GICS("453010");
console.log(gics.industryGroup.name);
console.log(gics.industryGroup.code);
console.log(gics.subIndustry);
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
const GICS = require("gics");
let gics = new GICS("453010");
console.log(gics.industry.name);
console.log(gics.industry.code);
subIndustry
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
const GICS = require("gics");
let gics = new GICS("45301010");
console.log(gics.subIndustry.name);
console.log(gics.subIndustry.code);
console.log(gics.subIndustry.description);
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
const GICS = require("gics");
let gics = new GICS("45301010");
console.log(gics.level(1) == gics.sector);
console.log(gics.level(2) == gics.industryGroup);
console.log(gics.level(3) == gics.industry);
console.log(gics.level(4) == gics.subIndustry);
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
const GICS = require("gics");
let gics = new GICS("10");
console.log(gics.children.length);
console.log(gics.children[1].code);
isSame(anotherGics)
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} anotherGics GICS object to compare with
Example
const GICS = require("gics");
let gics1 = new GICS("1010");
let gics2 = new GICS("1010");
gics1.isSame(gics2);
gics2.isSame(gics1);
isWithin(anotherGics)
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} anotherGics GICS object to compare with
Example
const GICS = require("gics");
new GICS("10101010").isWithin(new GICS("10"));
new GICS("101010").isWithin(new GICS("10"));
new GICS("101010").isWithin(new GICS("1010"));
new GICS("1010").isWithin(new GICS("10"));
new GICS("10").isWithin(new GICS("10"));
new GICS("1010").isWithin(new GICS("1010"));
new GICS("invalid").isWithin(new GICS("10"));
new GICS("10").isWithin(new GICS("invalid"));
new GICS("invalid").isWithin(new GICS("invalid"));
isImmediateWithin(anotherGics)
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} anotherGics GICS object to compare with
Example
const GICS = require("gics");
new GICS("10101010").isImmediateWithin(new GICS("10"));
new GICS("101010").isImmediateWithin(new GICS("10"));
new GICS("101010").isImmediateWithin(new GICS("1010"));
new GICS("1010").isImmediateWithin(new GICS("10"));
new GICS("10").isImmediateWithin(new GICS("10"));
new GICS("1010").isImmediateWithin(new GICS("1010"));
new GICS("invalid").isImmediateWithin(new GICS("10"));
new GICS("10").isImmediateWithin(new GICS("invalid"));
new GICS("invalid").isImmediateWithin(new GICS("invalid"));
contains(anotherGics)
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} anotherGics GICS object to compare with
Example
const GICS = require("gics");
new GICS("10").contains(new GICS("10101010"));
new GICS("10").contains(new GICS("101010"));
new GICS("10").contains(new GICS("1010"));
new GICS("10").contains(new GICS("10"));
new GICS("1010").contains(new GICS("10"));
new GICS("invalid").contains(new GICS("10"));
new GICS("10").contains(new GICS("invalid"));
new GICS("invalid").contains(new GICS("invalid"));
containsImmediate(anotherGics)
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} anotherGics GICS object to compare with
Example
const GICS = require("gics");
new GICS("10").containsImmediate(new GICS("10101010"));
new GICS("10").containsImmediate(new GICS("101010"));
new GICS("10").containsImmediate(new GICS("1010"));
new GICS("10").containsImmediate(new GICS("10"));
new GICS("1010").containsImmediate(new GICS("10"));
new GICS("invalid").containsImmediate(new GICS("10"));
new GICS("10").containsImmediate(new GICS("invalid"));
new GICS("invalid").containsImmediate(new GICS("invalid"));