! 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 ""* ""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 , cumret_adjusted_prices "" ""> Tickerを正しいものにしないと当然にエラーになるが、市場をまとめてデータを取得する方法もあるようなので要研究。 今現在は[Yahoo Finance API|https://www.yahoofinanceapi.com/]のAPIKEYを使わなくても取得できているが、本来はアカウントを取得してAPIにアクセスするのが筋道。 :参考: * [【Yahoo Finance API】ヤフーファイナンスAPIのアカウント登録とAPIKey取得方法|https://heybro21.com/yahoofinanceapi/] * https://github.com/ropensci/yfR