-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathREADME.Rmd
126 lines (83 loc) · 3.46 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
message = F,
warning = F,
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# alphavantager
[![codecov](https://codecov.io/gh/business-science/alphavantager/branch/master/graph/badge.svg)](https://app.codecov.io/gh/business-science/alphavantager)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/alphavantager)](https://cran.r-project.org/package=alphavantager)
![](http://cranlogs.r-pkg.org/badges/alphavantager?color=brightgreen)
![](http://cranlogs.r-pkg.org/badges/grand-total/alphavantager?color=brightgreen)
<!-- <img src="tools/logo.png" width="147" height="170" align="right" /> -->
> A lightweight R interface to the Alpha Vantage API
## Alpha Vantage
Alpha Vantage is a __free service__ that enables users to get __real-time and historical financial data__. New users will need to visit [Alpha Vantage](https://www.alphavantage.co/) and obtain an API key.
## R Interface: Getting Started
The `alphavantager` package provides a convenient and lightweight interface to the Alpha Vantage API.
To get started, install the package from CRAN or from GitHub:
```{r, eval = F}
install.packages("alphavantager")
# Or
devtools::install_github("business-science/alphavantager")
```
Load the package.
```{r}
library(alphavantager)
```
Set your API key (get one from [Alpha Vantage](https://www.alphavantage.co/) if you don't already have one... it's free).
```{r}
av_api_key("YOUR_API_KEY")
print(av_api_key())
```
## Getting Financial Data from Alpha Vantage
Now, you're ready to get financial data via `av_get()`, which accepts the same<sup>1</sup> arguments as the [API Documentation](https://www.alphavantage.co/documentation/) parameters. The function is setup with two primary arguments, `symbol` and `av_fun`, which accepts an equity and one of the API "function" parameters. You can pass additional API parameters via the `...`.
```{r}
# Function is streamlined and user adds additional parameters via ...
args(av_get)
```
Here are a few examples of retrieving __real-time and historical financial data__!
#### Time Series Data
```{r, eval=F}
av_get(symbol = "MSFT",
av_fun = "TIME_SERIES_INTRADAY",
interval = "15min",
outputsize = "full")
```
#### ForEx
```{r, eval=F}
# REAL-TIME QUOTE
av_get("EUR/USD", av_fun = "CURRENCY_EXCHANGE_RATE")
```
```{r, eval=F}
# TIME SERIES
av_get("EUR/USD", av_fun = "FX_DAILY", outputsize = "full")
```
#### Technical Indicators
```{r, eval=F}
av_get(symbol = "MSFT",
av_fun = "AROON",
interval = "monthly",
time_period = 60,
outputsize = "full")
```
#### Sector Performances
```{r, eval=F}
av_get(av_fun = "SECTOR")
```
#### Fundamental Data
```{r, eval=F}
av_get(av_fun = "OVERVIEW")
```
#### Important Notes: av_get()
1. The `av_fun` argument replaces the API parameter "function" because function is a reserved name in R. All other arguments match the Alpha Vantage API parameters.
2. There is no need to specify the `apikey` parameter as an argument to `av_get()`. The required method is to set the API key using `av_api_key("YOUR_API_KEY")`.
3. There is no need to specify the `datatype` parameter as an argument to `av_get()`. The function will return a tibble data frame.
4. Some data sets only return 100 rows by default. Change the parameter `outputsize = "full"` to get the full dataset.