gpt4 book ai didi

r - 查找股票属于哪个行业

转载 作者:行者123 更新时间:2023-12-02 22:03:50 25 4
gpt4 key购买 nike

给定标准普尔 500 指数中的股票,我如何找到每只股票属于哪个行业,例如财务、能源....、使用 R 包或其他来源?

最佳答案

术语“部门”本身就是一个模棱两可的术语。一个数据提供者称为“消费者服务”的东西可能被另一个称为“餐馆”。也就是说,TTR提供一个名为 stockSymbols 的函数,它返回一些信息,包括 NASDAQ 的 ~6400 NMS 股票的行业信息。

library(TTR)
ss <- stockSymbols()
#Fetching AMEX symbols...
#Fetching NASDAQ symbols...
#Fetching NYSE symbols...
head(ss)
# Symbol Name LastSale MarketCap IPOyear Sector Industry Exchange
#1 AA-P Alcoa Inc. 92.300 0 NA Capital Goods Metal Fabrications AMEX
#2 AAU Almaden Minerals, Ltd. 1.620 97228060 NA Basic Industries Precious Metals AMEX
#3 ACU Acme United Corporation. 12.984 40798351 1988 Capital Goods Industrial Machinery/Components AMEX
#4 ACY AeroCentury Corp. 20.280 31297252 NA Technology Diversified Commercial Services AMEX
#5 ADGE American DG Energy Inc. 1.720 83404061 NA Energy Electric Utilities: Central AMEX
#6 ADK Adcare Health Systems Inc 5.800 85018494 NA Health Care Hospital/Nursing Management AMEX

如果您只想要标准普尔 500 指数中的股票,您可以作弊并使用 SPY 的持股(或者有很多地方可以找到标准普尔 500 指数的持股,包括标准普尔网站)

#install.packages("qmao", repos="http://r-forge.r-project.org")
library(qmao)
spyh <- getHoldings("SPY", auto.assign=FALSE)
head(ss[ss$Symbol %in% rownames(spyh), ])
# Symbol Name LastSale MarketCap IPOyear Sector
#455 AAPL Apple Inc. 452.97 425179837530 1980 Technology
#490 ADBE Adobe Systems Incorporated 44.02 22095230291 1986 Technology
#493 ADI Analog Devices, Inc. 46.79 14317018779 NA Technology
#495 ADP Automatic Data Processing, Inc. 70.03 33980125863 NA Technology
#500 ADSK Autodesk, Inc. 39.75 8896050000 NA Technology
#535 AKAM Akamai Technologies, Inc. 46.70 8333728621 1999 Miscellaneous
# Industry Exchange
#455 Computer Manufacturing NASDAQ
#490 Computer Software: Prepackaged Software NASDAQ
#493 Semiconductors NASDAQ
#495 EDP Services NASDAQ
#500 Computer Software: Prepackaged Software NASDAQ
#535 Business Services NASDAQ

关于r - 查找股票属于哪个行业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16432512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com