forked from fdrennan/stockAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stock.R
36 lines (27 loc) · 774 Bytes
/
stock.R
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
#' @param stocks Tickers in JSON format
#' @param DATA bool
#' @export get_stocks
get_stocks <- function(stocks = '["AAPL","DIA"]',
DATA = FALSE,
startDate = "2016-01-01",
endDate = "2017-01-01") {
if (startDate >= endDate) {
stop('startDate must be less than endDate')
}
stocks <- fromJSON(stocks)
mult_stocks <- tq_get(stocks,
get = "stock.prices",
from = startDate,
to = endDate)
if(length(stocks) == 1) {
mult_stocks$symbol = stocks
}
if (DATA) {
return(toJSON(mult_stocks))
}
gg <-
ggplot(mult_stocks) +
aes(x = date, y = close, colour = symbol) +
geom_line()
print(gg)
}