トップ 一覧 検索 ヘルプ RSS ログイン 印刷

yfRの変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
! yfRパッケージ

RでAPIから株価を取得するにはquantmodパッケージがよく使われるが、yfRというパッケージもある。

""
""> library(yfR)
""> yf_get(tickers = '1982.T', first_date = '2022-07-01', last_date = "2022-07-05")

出力例

""── Running yfR for 1 stocks | 2022-07-01 --> 2022-07-05 (4 days) ──
""
""ℹ Downloading data for benchmark ticker ^GSPC
""ℹ (1/1) Fetching data for 1982.T
""! 	- not cached
""✔ 	- cache saved successfully
""✔ 	- got 3 valid rows (2022-07-01 --> 2022-07-05)
""✔ 	- got 100% of valid prices -- Nice!
""ℹ Binding price data
""
""── Diagnostics ────────────────────────────────────────────────────────────────────────────────────────────────────
""✔ Returned dataframe with 3 rows -- Looking good!
""ℹ Using 1.2 kB at /tmp/RtmpW85Gqe/yf_cache for 1 cache files
""ℹ Out of 1 requested tickers, you got 1 (100%)
""# A tibble: 3 × 11
""  ticker ref_date   price_open price_high price_low price_close volume price_adjusted ret_adjusted_prices
""* <chr>  <date>          <dbl>      <dbl>     <dbl>       <dbl>  <dbl>          <dbl>               <dbl>
""1 1982.T 2022-07-01       1943       1943      1904        1916  24100           1916            NA      
""2 1982.T 2022-07-04       1942       1942      1921        1929  17800           1929             0.00678
""3 1982.T 2022-07-05       1937       1937      1918        1923   9200           1923            -0.00311
""# … with 2 more variables: ret_closing_prices <dbl>, cumret_adjusted_prices <dbl>
""
""> 

Tickerを正しいものにしないと当然にエラーになるが、市場をまとめてデータを取得する方法もあるようなので要研究。

今現在はAPIKEYを使わなくても取得できているが、本来はアカウントを取得してAPIにアクセスするのが筋道。
今現在は[Yahoo Finance API|https://www.yahoofinanceapi.com/]のAPIKEYを使わなくても取得できているが、本来はアカウントを取得してAPIにアクセスするのが筋道。

:参考:

* [【Yahoo Finance API】ヤフーファイナンスAPIのアカウント登録とAPIKey取得方法|https://heybro21.com/yahoofinanceapi/]
* https://github.com/ropensci/yfR