如何使用quantmod或其他函数获取在纽约证券交易所上市的BRK.B股票的数据?

huangapple go评论95阅读模式
英文:

how do I get data on BRK.B that is listed on the NYSE using quantmod or another function?

问题

我想获取在纽约证券交易所上市的伯克希尔-哈撒韦(BRK.B)的数据。

看起来我不能使用getSymbols函数,因为该函数只允许我从雅虎财经获取数据,而BRK.B没有在雅虎财经上市。

我如何获取BRK.B的数据?

谢谢!
Old

我尝试了getSymbols("BRK.B")

我希望获得伯克希尔哈撒韦的数据。

英文:

I want to get data on Birkshire-Hathaway (BRK.B) that is listed on the NYSE.

It seems that I can't use getSymbols because that function allows my to get data from yahoo finance, and BRK.B is not listed on yahoo finance.

How do I get data on BRK.B?

Thanks!
Old

I tried getSymbols("BRK.B")

I hoped for data on Berkshire Hathaway.

答案1

得分: 1

"BRK-B" 在 Yahoo 上的代码为:

  1. brk.b <- getSymbols("BRK-B", auto.assign = FALSE)

在这种情况下,我强烈建议使用 auto.assign = FALSE,并将输出分配给一个值,而不是让 getSymbols() 为您创建一个对象。

否则,getSymbols() 将创建一个名为 BRK-B 的对象,这可能会让人感到困惑,因为您将始终需要使用反引号来访问它。例如:

  1. #
  2. # 不推荐的方式!
  3. #
  4. quantmod::getSymbols("BRK-B")
  5. ## [1] "BRK-B"
  6. head(BRK-B)
  7. ## Error: object 'BRK' not found
  8. head(`BRK-B`)
  9. ## BRK-B.Open BRK-B.High BRK-B.Low BRK-B.Close BRK-B.Volume BRK-B.Adjusted
  10. ## 2007-01-03 73.56 73.72 72.60 72.86 1385000 72.86
  11. ## 2007-01-04 72.86 72.94 72.06 72.20 1070000 72.20
  12. ## 2007-01-05 72.66 72.66 71.26 71.56 930000 71.56
  13. ## 2007-01-08 71.82 71.90 71.50 71.72 760000 71.72
  14. ## 2007-01-09 71.72 73.04 71.66 73.00 610000 73.00
  15. ## 2007-01-10 73.00 73.18 72.30 73.02 775000 73.02
英文:

The ticker is "BRK-B" on Yahoo. You can import it using

  1. brk.b &lt;- getSymbols(&quot;BRK-B&quot;, auto.assign = FALSE)

In this case, I strongly recommend using auto.assign = FALSE and assigning the output to a value instead of letting getSymbols() create an object for you.

Otherwise getSymbols() will create an object named BRK-B which can be confusing to use, because you will always have to use backticks to access it. For example:

  1. #
  2. # not recommended!
  3. #
  4. quantmod::getSymbols(&quot;BRK-B&quot;)
  5. ## [1] &quot;BRK-B&quot;
  6. head(BRK-B)
  7. ## Error: object &#39;BRK&#39; not found
  8. head(`BRK-B`)
  9. ## BRK-B.Open BRK-B.High BRK-B.Low BRK-B.Close BRK-B.Volume BRK-B.Adjusted
  10. ## 2007-01-03 73.56 73.72 72.60 72.86 1385000 72.86
  11. ## 2007-01-04 72.86 72.94 72.06 72.20 1070000 72.20
  12. ## 2007-01-05 72.66 72.66 71.26 71.56 930000 71.56
  13. ## 2007-01-08 71.82 71.90 71.50 71.72 760000 71.72
  14. ## 2007-01-09 71.72 73.04 71.66 73.00 610000 73.00
  15. ## 2007-01-10 73.00 73.18 72.30 73.02 775000 73.02

huangapple
  • 本文由 发表于 2023年7月11日 01:55:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76656201.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定