An open API service indexing awesome lists of open source software.

https://github.com/rsquaredacademy/yahoofinancer

Obtain historical and near real time data from Yahoo Finance
https://github.com/rsquaredacademy/yahoofinancer

api api-wrapper finance market-data rstats stock-market yahoo-finance yahoo-finance-api

Last synced: 6 months ago
JSON representation

Obtain historical and near real time data from Yahoo Finance

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# yahoofinancer

[![CRAN status](https://www.r-pkg.org/badges/version/yahoofinancer)](https://CRAN.R-project.org/package=yahoofinancer)
[![R-CMD-check](https://github.com/rsquaredacademy/yahoofinancer/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rsquaredacademy/yahoofinancer/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/rsquaredacademy/yahoofinancer/branch/master/graph/badge.svg)](https://app.codecov.io/gh/rsquaredacademy/yahoofinancer?branch=master)

Obtain historical and near real time data related to stocks, index and currencies from the Yahoo Finance API.

## Installation

```{r gh-installation, eval = FALSE}
# Install rfm from CRAN
install.packages("yahoofinancer")

# Or the development version from GitHub
# install.packages("pak")
pak::pak("rsquaredacademy/yahoofinancer")
```

## Quick Start

```{r load_yfr, echo=FALSE, message=FALSE, warning=FALSE}
library(yahoofinancer)
```

### Ticker

To retrieve data from Yahoo Finance for a single stock, create an instance of the `Ticker` class by passing the company's ticker symbol as an argument:

```{r ticker}
aapl <- Ticker$new('aapl')

# get historical market data
head(aapl$get_history(start = '2024-10-20', interval = '1d'))

# meta info
# regular market price
aapl$regular_market_price

# 52 week high
aapl$fifty_two_week_high

# previous close
aapl$previous_close
```

### Index

To retrieve data from Yahoo Finance for an index, create an instance of the `Index` class by passing the index symbol as an argument:

```{r index}
nifty_50 <- Index$new('^NSEI')

# get historical data
head(nifty_50$get_history(start = '2024-01-20', interval = '1d'))
```

### Currency

```{r currency}
head(currency_converter('GBP', 'USD', '2024-01-20', '2024-01-30'))
```

## IMPORTANT LEGAL DISCLAIMER

**Yahoo!, Y!Finance, and Yahoo! finance are registered trademarks of
Yahoo, Inc.**

yahoofinancer is **not** affiliated, endorsed, or vetted by Yahoo, Inc. It's
an open-source tool that uses Yahoo's publicly available APIs, and is
intended for research and educational purposes.

**You should refer to Yahoo!'s terms of use**
([here](https://policies.yahoo.com/us/en/yahoo/terms/product-atos/apiforydn/index.htm),
[here](https://legal.yahoo.com/us/en/yahoo/terms/otos/index.html), and
[here](https://policies.yahoo.com/us/en/yahoo/terms/index.htm)) **for
details on your rights to use the actual data downloaded. Remember - the
Yahoo! finance API is intended for personal use only.**

## Code of Conduct

Please note that the yahoofinancer project is released with a [Contributor Code of Conduct](https://yahoofinancer.rsquaredacademy.com/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.