Skip to content

industry

import "github.com/wnjoon/go-yfinance/pkg/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:

i.ClearCache()

Custom Client

Provide a custom HTTP client:

c, _ := client.New()
i, _ := industry.New("semiconductors", industry.WithClient(c))

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

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.

type Industry struct {
    // contains filtered or unexported fields
}

func New

func New(key string, opts ...Option) (*Industry, error)

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

func NewWithPredefined(ind models.PredefinedIndustry, opts ...Option) (*Industry, error)

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

func (i *Industry) ClearCache()

ClearCache clears the cached industry data. The next call to any data method will fetch fresh data.

func (*Industry) Close

func (i *Industry) Close()

Close releases resources used by the Industry instance.

func (*Industry) Data

func (i *Industry) Data() (*models.IndustryData, error)

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

func (i *Industry) Key() string

Key returns the industry key.

func (*Industry) Name

func (i *Industry) Name() (string, error)

Name returns the industry name.

Example:

name, err := i.Name()
fmt.Println(name) // "Semiconductors"

func (*Industry) Overview

func (i *Industry) Overview() (models.IndustryOverview, error)

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

func (i *Industry) Region() string

Region returns the Yahoo region used to scope regional lists.

func (*Industry) ResearchReports

func (i *Industry) ResearchReports() ([]models.ResearchReport, error)

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

func (i *Industry) SectorKey() (string, error)

SectorKey returns the key of the parent sector.

Example:

sectorKey, err := i.SectorKey()
fmt.Println(sectorKey) // "technology"

func (*Industry) SectorName

func (i *Industry) SectorName() (string, error)

SectorName returns the name of the parent sector.

Example:

sectorName, err := i.SectorName()
fmt.Println(sectorName) // "Technology"

func (*Industry) Symbol

func (i *Industry) Symbol() (string, error)

Symbol returns the industry symbol.

func (*Industry) TopCompanies

func (i *Industry) TopCompanies() ([]models.IndustryTopCompany, error)

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

func (i *Industry) TopGrowthCompanies() ([]models.GrowthCompany, error)

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

func (i *Industry) TopPerformingCompanies() ([]models.PerformingCompany, error)

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.

type Option func(*Industry)

func WithClient

func WithClient(c *client.Client) Option

WithClient sets a custom HTTP client for the Industry instance.

func WithRegion

func WithRegion(region string) Option

WithRegion scopes regional lists to a Yahoo region such as "US", "GB", or "JP".