Get data from Yahoo! Finance to R

前端 未结 2 685
悲哀的现实
悲哀的现实 2020-12-20 10:44

I am trying to get data from Yahoo! Finance to R

I\'ve installed quantmod like that:

install.packages(\"quantmod\", repos=\"http://R-Forge.R-project.         


        
2条回答
  •  礼貌的吻别
    2020-12-20 10:52

    To answer the specific question asked:

    getSymbols("QQQ;SPY", from="1997-12-31", src='yahoo')  
    

    works just fine - you get two xts series, QQQ and SPY (note that QQQQ is "dead" and replaced with QQQ), with 6 columns Open, High, Low, Close, Volume, Adjusted.
    It looks like you only want the close? If so, you can get just that series with

    Cl(QQQ)
    

    If you don't like auto-assignment, you can use

    qqq.data <- getSymbols("QQQ", auto.assign=FALSE, from="1997-12-31", src='yahoo')
    

    to assign the downloaded data to a variable of your choice. Note that most people would probably be interested in the adjusted price instead, if so, you can select it with

    Ad(QQQ)
    

    Finally, indeed, as pointed out, google finance no longer provides data through its API.

提交回复
热议问题