【问题标题】:Getting historical index data for ETF's获取 ETF 的历史指数数据
【发布时间】:2013-04-05 14:37:04
【问题描述】:

有人知道免费的 ETF 历史数据来源吗?我想将数据加载到 R 服务器中进行分析。我查看了雅虎财务表的雅虎 YQL API,但是这些数据是每天的数据,我想根据历史价格进行比较。

谢谢

【问题讨论】:

    标签: r yahoo-finance


    【解决方案1】:

    试试quantmod 包。

    require(quantmod)
    
    SPY <- getSymbols("SPY", from = "2005-01-01", to = "2008-12-31", auto.assign = FALSE)
    
    head(SPY)
    ##            SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
    ## 2005-01-03   121.56   121.76  119.90    120.30   55748000       101.76
    ## 2005-01-04   120.46   120.54  118.44    118.83   69167600       100.52
    ## 2005-01-05   118.74   119.25  118.00    118.01   65667300        99.83
    ## 2005-01-06   118.44   119.15  118.26    118.61   47814700       100.33
    ## 2005-01-07   118.97   119.23  118.13    118.44   55847700       100.19
    ## 2005-01-10   118.34   119.46  118.34    119.00   56563300       100.66
    

    【讨论】:

      【解决方案2】:

      对于像我这样有同样问题的人(只有 WKN 和 Yahoo Finance 没有列出 ETF,我找到了一个采用 WKN 并返回历史价格的网站:

      我使用了网页抓取 (rvest)。以下采用 WKN(或 ISIN,我想)并返回历史价格:

      library(rvest)
      library(purrr)
      
      get_prices <- function(wkn){
          # Download prices for WKN
      
          cat("Quoting", wkn, "\n")
          erg <- html_nodes(read_html(paste0("http://www.quotrix.de/fonds/wkn/", wkn,
                                             "/historische_kurse")), "table") %>% 
              map(html_table, fill=T) 
      
          if(length(erg) != 1) stop("Error with ", wkn, ": Expected 1 table, found ", length(erg))
          return(erg[[1]])
      }
      
      safe_get_prices <- safely(get_prices)
      erg <- safe_get_prices("ETF126")
      #> Quoting ETF126
      str(erg)
      #> List of 2
      #>  $ result:'data.frame':  597 obs. of  6 variables:
      #>   ..$ Datum    : chr [1:597] "17.04.2020" "16.04.2020" "15.04.2020" "14.04.2020" ...
      #>   ..$ Eröffnung: chr [1:597] "34,73" "34,05" "35,16" "35,58" ...
      #>   ..$ Tageshoch: chr [1:597] "34,73" "34,05" "35,16" "35,58" ...
      #>   ..$ Tagestief: chr [1:597] "34,73" "34,05" "35,16" "35,58" ...
      #>   ..$ Schluss  : chr [1:597] "34,73" "34,05" "35,16" "35,58" ...
      #>   ..$ Stücke   : chr [1:597] "-" "-" "-" "-" ...
      #>  $ error : NULL
      

      reprex package (v0.3.0) 于 2020 年 4 月 21 日创建

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-25
        • 2021-12-19
        • 1970-01-01
        • 2010-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-13
        相关资源
        最近更新 更多