-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
100 lines (70 loc) · 2.97 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# yahoofinancer
<!-- badges: start -->
[![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)
<!-- badges: end -->
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.