欢迎使用 GICS Swift 库!该库实现了全球行业分类标准 (GICS),使用户能够解析 GICS 代码并检索有关 GICS 分类的相关信息。
全球行业分类标准是一个行业分析框架,旨在帮助投资者了解全球公司关键的商业活动。MSCI 和标普道琼斯指数开发了此分类标准,旨在为投资者提供一致且详尽的行业定义。
GICS 会进行年度审查,以确保其完全代表全球市场动态。此 Swift 库反映了2023 年 3 月 17 日生效的 GICS 结构。
8 位 GICS 编码系统的分层设计允许在 GICS 层级之间轻松转换。GICSRepresentable
协议定义了用于检索 GICS 分类信息的方法和属性,并基于 GICS 结构提供默认实现。 GICSRepresentable
的关键要求是与特定 GICS 代码相对应的 rawValue
。
GICS
是一个遵循 GICSRepresentable
协议的枚举,它使用与 GICS 分类相对应的值来表示所有四个 GICS 层级。这四个 GICS 层级被定义为枚举,即 GICS.Sector
、GICS.IndustryGroup
、GICS.Industry
和 GICS.SubIndustry
。每个枚举案例都对应于其相应层级中的 GICS 分类。
在文档中查找更多详细信息。
在 Package.swift
Swift Package Manager 清单中,将以下依赖项添加到 dependencies
参数
.package(url: "https://github.com/joey-gm/GICS", from: "2023.3.17")
将依赖项添加到清单中声明的任何目标
.target(name: "MyTarget", dependencies: ["GICS"])
使用 GICS 代码初始化 GICS 实例
let possibleGICS_a = GICS(rawValue: 40)
// possibleGICS_a is of type GICS? and equals GICS.sector(.financials)
let possibleGICS_b = GICS(rawValue: 4020)
// possibleGICS_b is of type GICS? and equals GICS.industryGroup(.financialServices)
let possibleGICS_c = GICS(rawValue: 402030)
// possibleGICS_c is of type GICS? and equals GICS.industry(.capitalMarkets)
let possibleGICS_d = GICS(rawValue: 40203020)
// possibleGICS_d is of type GICS? and equals GICS.subIndustry(.investmentBankingAndBrokerage)
let possibleGICS_e = GICS(rawValue: 12345678)
// possibleGICS_e is of type GICS? and equals nil
// ('12345678' is not a valid GICS code.)
let possibleSubIndustry_f = GICS.SubIndustry(rawValue: 40203020)
// possibleSubIndustry_f is of type GICS.SubIndustry? and equals GICS.SubIndustry.investmentBankingAndBrokerage
let possibleSubIndustry_g = GICS.SubIndustry(rawValue: 4020)
// possibleSubIndustry_g is of type GICS.SubIndustry? and equals nil
// (While '4020' is valid GICS code, it is an Industry Group level code and not a valid Sub-Industry level code.)
let possibleIndustryGroup_h = GICS.IndustryGroup(rawValue: 4020)
// possibleIndustryGroup_h is of type GICS.IndustryGroup? and equals GICS.IndustryGroup.financialServices
使用已知分类初始化 GICS 实例
let knownGICS_a = GICS.sector(.informationTechnology)
// knownGICS_a is of type GICS and its rawValue equals to '45'
let knownGICS_b = GICS.IndustryGroup.softwareAndServices
// knownGICS_b is of type GICS.IndustryGroup and its rawValue equals to '4510'
let knownGICS_c = GICS.industry(.software)
// knownGICS_c is of type GICS and its rawValue equals to '451030'
let knownGICS_d = GICS.SubIndustry.applicationSoftware
// knownGICS_d is of type GICS.SubIndustry and its rawValue equals to '45103010'
检索 GICS 代码、描述和定义
let gics_a = GICS.SubIndustry.applicationSoftware
// gics_a is of type GICS.SubIndustry and its rawValue equals to '45103010'
gics_a.description
// Application Software
gics_a.definition
// Companies engaged in developing and producing software designed for specialized applications for the business or consumer market. Includes enterprise and technical software, as well as cloud-based software. Excludes companies classified in the Interactive Home Entertainment Sub-Industry. Also excludes companies producing systems or database management software classified in the Systems Software Sub-Industry.
gics_a.id
// 45103010
// (Equivalent to gics_a.rawValue)
GICS 层次结构
let gics_b = GICS(rawValue: 451030)!
// gics_b is of type GICS and equals GICS.industry(.software)
gics_b.isSector
// false
gics_b.isIndustryGroup
// false
gics_b.isIndustry
// true
gics_b.isSubIndustry
// false
查找父分类或子分类
let gics_c = GICS.subIndustry(.investmentBankingAndBrokerage)
// gics_c is a GICS Sub-Industry classification and its rawValue equals to '40203020'
let gics_c_industry = gics_c.industry
// gics_c_industry is of type GICS.Industry? and equals GICS.Industry.capitalMarkets (GICS code: '402030')
let gics_c_industryGroup = gics_c.industryGroup
// gics_c_industryGroup is of type GICS.IndustryGroup? and equals GICS.IndustryGroup.financialServices (GICS code: '4020')
let gics_c_sector = gics_c.sector
// gics_c_sector is of type GICS.Sector and equals GICS.Sector.financials (GICS code: '40')
如果子分类是不确定的,则从父分类查找子分类可能导致 nil
let sector_a = GICS.Sector.financials
// sector_a is a GICS Sector classification and its rawValue equals to '40'
let sector_a_to_industryGroup = sector_a.industryGroup
// sector_a_to_industryGroup is of type GICS.IndustryGroup? and equals to nil
// The value is nil because the GICS Industry Group is indeterminate, i.e. there are more than one possible GICS Industry Group (Banks, Financial Services, Insurance) for the given GICS Sector (GICS.Sector.financials).
let sector_b = GICS.Sector.energy
// sector_b is a GICS Sector classification and its rawValue equals to '10'
let sector_b_to_industryGroup = sector_b.industryGroup
// sector_b_to_industryGroup equals GICS.IndustryGroup.energy (GICS code: '1010')
// The Industry Group (child) of the Energy Sector (parent) can be determined since there is only one GICS Industry Group within the Energy Sector.
let industry_a = GICS.Industry.capitalMarkets
// industry_a is a GICS Industry classification and its rawValue equals to '402030'
let industry_a_to_subIndustry = industry_a.subIndustry
// industry_a_to_subIndustry is of type GICS.SubIndustry? and equals to nil
// The value is nil because the GICS Sub-Industry is indeterminate, i.e. there are more than one possible GICS Sub-Industry (Asset Management & Custody Banks, Investment Banking & Brokerage, Diversified Capital Markets, Financial Exchanges & Data) for the given GICS Industry (GICS.Industry.capitalMarkets).
let industry_b = GICS.Industry.passengerAirlines
// industry_b is a GICS Industry classification and its rawValue equals to '203020'
let industry_b_to_subIndustry = industry_b.subIndustry
// industry_b_to_subIndustry equals GICS.SubIndustry.passengerAirlines (GICS code: '20302010')
// The Sub-Industry (child) of the Passenger Airlines Industry (parent) can be determined since there is only one GICS Sub-Industry within the Passenger Airlines Industry.
确定 GICS 实例是否属于给定的父分类
GICS.IndustryGroup.softwareAndServices.belongs(to: GICS.Sector.informationTechnology)
// true
GICS.Industry.software.belongs(to: GICS.Sector.informationTechnology)
// true
GICS.SubIndustry.applicationSoftware.belongs(to: GICS.Industry.software)
// true
GICS.Industry.software.belongs(to: GICS.SubIndustry.applicationSoftware)
// false
GICS.Industry.software.belongs(to: GICS.IndustryGroup.financialServices)
// false
GICS.Industry.capitalMarkets.belongs(to: GICS.IndustryGroup.financialServices)
// true
确定 GICS 实例是否包含给定的子分类
GICS.IndustryGroup.financialServices.contains(GICS.Industry.capitalMarkets)
// true
GICS.Sector.financials.contains(GICS.SubIndustry.investmentBankingAndBrokerage)
// true
GICS.Sector.financials.contains(GICS.SubIndustry.applicationSoftware)
// false
GICS.SubIndustry.investmentBankingAndBrokerage.contains(GICS.Sector.financials)
// false
访问所有可能的子 GICS 分类集合
let gics_d = GICS.Sector.consumerDiscretionary
// gics_d is of type GICS.Sector and its rawValue equals to '25'
let industryGroups = gics_d.industryGroups
// [Automobiles & Components, Consumer Durables & Apparel, Consumer Services, Consumer Discretionary Distribution & Retail]
let industryGroups_first = industryGroups.first!
// industryGroups_first is of type GICS.IndustryGroup and equals GICS.IndustryGroup.automobilesAndComponents (GICS code: '2510')
let industries = industryGroups_first.industries
// [Automobile Components, Automobiles]
let industries_first = industries.first!
// industries_first is of type GICS.Industry and equals GICS.Industry.automobileComponents (GICS code: '251010')
let subIndustries = industries_first.subIndustries
// [Automotive Parts & Equipment, Tires & Rubber]
let subIndustries_first = subIndustries.first!
// subIndustries_first is of type GICS.SubIndustry and equals GICS.SubIndustry.automotivePartsAndEquipment (GICS code: '25101010')
let subIndustries_first_industryGroups = subIndustries_first.industryGroups
// [Automobiles & Components]
// Retrieving all possible parent classifications from a child classification results in a Collection of One, containing only the parent classification.
使用 allCases
静态属性或相关的 GICS
属性访问所有 GICS 分类的集合
let allSectors = GICS.allSectors
// [Energy, Materials, Industrials, Consumer Discretionary, Consumer Staples, ...]
// (Equivalent to GICS.Sector.allCases)
let allIndustryGroups = GICS.allIndustryGroups
// [Energy, Materials, Capital Goods, Commercial & Professional Services, Transportation, ...]
// (Equivalent to GICS.IndustryGroup.allCases)
let allIndustries = GICS.allIndustries
// [Energy Equipment & Services, Oil, Gas & Consumable Fuels, Chemicals, ...]
// (Equivalent to GICS.Industry.allCases)
let allSubIndustries = GICS.allSubIndustries
// [Oil & Gas Drilling, Oil & Gas Equipment & Services, Integrated Oil & Gas, ...]
// (Equivalent to GICS.SubIndustry.allCases)
GICS 定义和描述在字符串目录中本地化,其中 GICS 代码是本地化键。