industry
Package industry provides Yahoo Finance industry data functionality.
Overview
The industry package allows retrieving financial industry information including overview data, top companies, sector information, top performing companies, and top growth companies. This is useful for industry-based analysis and screening.
Basic Usage
i, err := industry.New("semiconductors")
if err != nil {
log.Fatal(err)
}
defer i.Close()
// Get industry overview
overview, err := i.Overview()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Companies: %d\n", overview.CompaniesCount)
fmt.Printf("Market Cap: $%.2f\n", overview.MarketCap)
Sector Information
Get the parent sector of an industry:
sectorKey, err := i.SectorKey()
sectorName, err := i.SectorName()
fmt.Printf("Part of: %s (%s)\n", sectorName, sectorKey)
Top Performing Companies
Get companies with highest year-to-date returns:
companies, err := i.TopPerformingCompanies()
if err != nil {
log.Fatal(err)
}
for _, c := range companies {
fmt.Printf("%s: YTD %.2f%%, Target: $%.2f\n",
c.Symbol, c.YTDReturn*100, c.TargetPrice)
}
Top Growth Companies
Get companies with highest growth estimates:
companies, err := i.TopGrowthCompanies()
if err != nil {
log.Fatal(err)
}
for _, c := range companies {
fmt.Printf("%s: Growth Estimate: %.2f%%\n",
c.Symbol, c.GrowthEstimate*100)
}
Predefined Industries
Common industry identifiers are available as constants:
i, _ := industry.NewWithPredefined(models.IndustrySemiconductors)
i, _ := industry.NewWithPredefined(models.IndustryBiotechnology)
i, _ := industry.NewWithPredefined(models.IndustryBanksDiversified)
Available predefined industries (grouped by sector):
Technology:
- IndustrySemiconductors
- IndustrySoftwareInfrastructure
- IndustrySoftwareApplication
- IndustryConsumerElectronics
- IndustryComputerHardware
Healthcare:
- IndustryBiotechnology
- IndustryDrugManufacturersGeneral
- IndustryMedicalDevices
- IndustryHealthcarePlans
Financial Services:
- IndustryBanksDiversified
- IndustryBanksRegional
- IndustryAssetManagement
- IndustryCapitalMarkets
Energy:
- IndustryOilGasIntegrated
- IndustryOilGasEP
- IndustryOilGasMidstream
Caching
Industry data is cached after the first fetch. To refresh:
Custom Client
Provide a custom HTTP client:
Thread Safety
All Industry methods are safe for concurrent use from multiple goroutines.
Python Compatibility
This package implements the same functionality as Python yfinance's Industry class:
Python | Go
------------------------------------|------------------------------------
yf.Industry("semiconductors") | industry.New("semiconductors")
industry.key | i.Key()
industry.name | i.Name()
industry.symbol | i.Symbol()
industry.sector_key | i.SectorKey()
industry.sector_name | i.SectorName()
industry.overview | i.Overview()
industry.top_companies | i.TopCompanies()
industry.top_performing_companies | i.TopPerformingCompanies()
industry.top_growth_companies | i.TopGrowthCompanies()
industry.research_reports | i.ResearchReports()
Index
- type Industry
- func New(key string, opts ...Option) (*Industry, error)
- func NewWithPredefined(ind models.PredefinedIndustry, opts ...Option) (*Industry, error)
- func (i *Industry) ClearCache()
- func (i *Industry) Close()
- func (i *Industry) Data() (*models.IndustryData, error)
- func (i *Industry) Key() string
- func (i *Industry) Name() (string, error)
- func (i *Industry) Overview() (models.IndustryOverview, error)
- func (i *Industry) Region() string
- func (i *Industry) ResearchReports() ([]models.ResearchReport, error)
- func (i *Industry) SectorKey() (string, error)
- func (i *Industry) SectorName() (string, error)
- func (i *Industry) Symbol() (string, error)
- func (i *Industry) TopCompanies() ([]models.IndustryTopCompany, error)
- func (i *Industry) TopGrowthCompanies() ([]models.GrowthCompany, error)
- func (i *Industry) TopPerformingCompanies() ([]models.PerformingCompany, error)
- type Option
- func WithClient(c *client.Client) Option
- func WithRegion(region string) Option
type Industry
Industry provides access to financial industry data from Yahoo Finance.
Industry allows retrieving industry-related information such as overview, top companies, sector information, and performing/growth companies.
func New
New creates a new Industry instance for the given industry key.
Industry keys are lowercase with hyphens, e.g., "semiconductors", "software-infrastructure". Use predefined constants from models package for convenience.
Example:
i, err := industry.New("semiconductors")
if err != nil {
log.Fatal(err)
}
defer i.Close()
overview, err := i.Overview()
fmt.Printf("Industry has %d companies\n", overview.CompaniesCount)
func NewWithPredefined
NewWithPredefined creates a new Industry instance using a predefined industry constant.
Example:
i, err := industry.NewWithPredefined(models.IndustrySemiconductors)
if err != nil {
log.Fatal(err)
}
func (*Industry) ClearCache
ClearCache clears the cached industry data. The next call to any data method will fetch fresh data.
func (*Industry) Close
Close releases resources used by the Industry instance.
func (*Industry) Data
Data returns all industry data.
This fetches and returns the complete industry information including overview, top companies, sector info, and performing/growth companies.
Example:
data, err := i.Data()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Industry: %s in Sector: %s\n", data.Name, data.SectorName)
func (*Industry) Key
Key returns the industry key.
func (*Industry) Name
Name returns the industry name.
Example:
func (*Industry) Overview
Overview returns the industry overview information.
Example:
overview, err := i.Overview()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Companies: %d\n", overview.CompaniesCount)
fmt.Printf("Market Cap: $%.2f\n", overview.MarketCap)
func (*Industry) Region
Region returns the Yahoo region used to scope regional lists.
func (*Industry) ResearchReports
ResearchReports returns research reports for the industry.
Example:
reports, err := i.ResearchReports()
if err != nil {
log.Fatal(err)
}
for _, r := range reports {
fmt.Printf("%s: %s\n", r.Provider, r.Title)
}
func (*Industry) SectorKey
SectorKey returns the key of the parent sector.
Example:
func (*Industry) SectorName
SectorName returns the name of the parent sector.
Example:
func (*Industry) Symbol
Symbol returns the industry symbol.
func (*Industry) TopCompanies
TopCompanies returns the top companies in the industry.
Example:
companies, err := i.TopCompanies()
if err != nil {
log.Fatal(err)
}
for _, c := range companies {
fmt.Printf("%s: %s (Weight: %.2f%%)\n",
c.Symbol, c.Name, c.MarketWeight*100)
}
func (*Industry) TopGrowthCompanies
TopGrowthCompanies returns the top growth companies in the industry.
Returns companies with highest growth estimates.
Example:
companies, err := i.TopGrowthCompanies()
if err != nil {
log.Fatal(err)
}
for _, c := range companies {
fmt.Printf("%s: YTD %.2f%%, Growth Estimate: %.2f%%\n",
c.Symbol, c.YTDReturn*100, c.GrowthEstimate*100)
}
func (*Industry) TopPerformingCompanies
TopPerformingCompanies returns the top performing companies in the industry.
Returns companies with highest year-to-date returns.
Example:
companies, err := i.TopPerformingCompanies()
if err != nil {
log.Fatal(err)
}
for _, c := range companies {
fmt.Printf("%s: YTD %.2f%%, Last: $%.2f, Target: $%.2f\n",
c.Symbol, c.YTDReturn*100, c.LastPrice, c.TargetPrice)
}
type Option
Option is a function that configures an Industry instance.
func WithClient
WithClient sets a custom HTTP client for the Industry instance.
func WithRegion
WithRegion scopes regional lists to a Yahoo region such as "US", "GB", or "JP".