/
secDetails.R
259 lines (216 loc) · 6.37 KB
/
secDetails.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#' Pull security rating
#'
#' Provides current and historical rating for one or more securities
#'
#' @inheritParams fmpc_security_profile
#' @param limit limit results for each ticker
#'
#' @return data frame of ratings data
#' @export
#'
#' @examples
#'
#'
#'\dontrun{
#'
#' # Demo can pull AAPL
#' fmpc_set_token()
#' fmpc_security_ratings('AAPL')
#'
#' # For multiple symbols, set a valid API Token
#' fmpc_set_token('FMPAPIKEY')
#' fmpc_security_ratings(c('AAPL','MSFT','SPY'))
#'
#' }
#'
fmpc_security_ratings <- function(symbols = c('AAPL'),
limit = 100) {
# Confirm Bulk API Request
symbReq = hlp_symbolCheck(symbols)
# Use custom function to collapse requests into data frame
ratingDF = hlp_bindURLs(paste0('historical-rating/',symbReq,'?limit=',limit,'&'))
# Send warning for symbols not pulled
hlp_respCheck(symbReq,ratingDF$symbol,'fmpc_security_ratings: ')
ratingDF
}
#' Pull market capitalization
#'
#' Provides current and historical market cap for one or more securities
#'
#' @inheritParams fmpc_security_ratings
#'
#' @return data frame of ratings data
#' @export
#'
#' @examples
#'
#'
#'\dontrun{
#'
#' # Demo can pull AAPL
#' fmpc_set_token()
#' fmpc_security_mrktcap('AAPL')
#'
#' # For multiple symbols, set a valid API Token
#' fmpc_set_token('FMPAPIKEY')
#' fmpc_security_mrktcap(c('AAPL','MSFT','SPY'))
#'
#' }
#'
fmpc_security_mrktcap <- function(symbols = c('AAPL'),
limit = 100) {
# Confirm Bulk API Request
symbReq = hlp_symbolCheck(symbols)
# Use custom function to collapse requests into data frame
ratingDF = hlp_bindURLs(paste0('historical-market-capitalization/',symbReq,'?limit=',limit,'&'))
# Send warning for symbols not pulled
hlp_respCheck(symbReq,ratingDF$symbol,'fmpc_security_mrktcap: ')
ratingDF
}
#' Delisted companies
#'
#' Shows companies that have been delisted
#'
#' @param limit set limit of results returned
#'
#' @return data frame of delisted companies
#' @export
#'
#' @examples
#'
#' \dontrun{
#'
#' # Must set a valid API token
#' fmpc_set_token('FMPAPIKEY')
#' fmpc_security_delisted()
#'
#' }
#'
fmpc_security_delisted <- function(limit = 100) {
# Make GET request
Result <- fmpc_get_url(paste0('delisted-companies?limit=',limit,'&'))
Result <- hlp_chkResult(Result)
dplyr::as_tibble(Result)
}
#'Get current news
#'
#'Provides current and historical News. Can enter securities to pull news for
#'specific securities
#'
#' @param symbols one or more symbols. Use NULL for general latest news
#' @inheritParams fmpc_security_ratings
#'
#' @return data frame of news for tickers
#' @export
#'
#' @examples
#'
#'\dontrun{
#'
#' # For multiple symbols, set a valid API Token
#' fmpc_set_token('FMPAPIKEY')
#' fmpc_security_news(c('AAPL','MSFT','SPY'))
#' fmpc_security_news()
#'
#' }
#'
fmpc_security_news <- function(symbols = NULL,
limit = 100) {
# Confirm Bulk API Request
symbReq = hlp_symbolCheck(symbols)
# symbURL = ifelse(length(symbReq)==0,'',paste0('tickers=',paste0(symbReq,collapse = ','),'&'))
if (length(symbReq)==0) {
symbURL = ''
} else {
symbURL = paste0('tickers=',symbReq,'&')
}
# Use custom function to collapse requests into data frame
newsDF = hlp_bindURLs(paste0('stock_news?',symbURL,'limit=',limit,'&'))
# Send warning for symbols not pulled
hlp_respCheck(symbReq,newsDF$symbol,'fmpc_security_mrktcap: ')
newsDF
}
#' Pull analyst outlook for one or more securities
#'
#' Analyst details for one or more securities includes earnings estimates,
#' earnings surprises, stock grade, analyst recommendations, and company press
#' releases
#'
#' @inheritParams fmpc_security_ratings
#' @param outlook can be one of: 'surprise' for earnings surprise, 'grade' for
#' stock grade', 'estimateAnnl' for analysts annual estimates, 'estimateQtr'
#' for analysts quarterly estimate, 'recommend' for analyst recommendations,
#' and 'press' for company press releases
#'
#' @return data frame of ratings data
#' @export
#'
#' @examples
#'
#'\dontrun{
#'
#' # Demo can pull AAPL
#' fmpc_set_token()
#' fmpc_analyst_outlook('AAPL')
#'
#' # For multiple symbols, set a valid API Token
#' fmpc_set_token('FMPAPIKEY')
#' fmpc_analyst_outlook(c('AAPL','MSFT','SPY'))
#'
#' }
#'
fmpc_analyst_outlook <- function(symbols = c('AAPL'),
outlook = c('surprise','grade','estimate','recommend','press'),
limit = 100) {
# Confirm Bulk API Request
symbReq = hlp_symbolCheck(symbols)
# Verify outlook
analysisOp = c('surprise','grade','estimateAnnl','estimateQtr','recommend','press')
if (missing(outlook)) outlook = 'surprise'
if (!(outlook %in% analysisOp)) {
stop('Please enter a metric value of: ',paste0(analysisOp, collapse = ', '), call. = FALSE)
}
outURL = switch(outlook,'surprise' = 'earnings-surpises', 'grade' = 'grade',
'estimateAnnl' = 'analyst-estimates', 'estimateQtr' = 'analyst-estimates',
'press' = 'press-releases', 'recommend' = 'analyst-stock-recommendations')
qtrAdd = ifelse(outlook == 'estimateQtr','period=quarter&','')
# Use custom function to collapse requests into data frame
outlookDF = hlp_bindURLs(paste0(outURL,'/',symbReq,'?limit=',limit,'&',qtrAdd))
# Send warning for symbols not pulled
hlp_respCheck(symbReq,outlookDF$symbol,'fmpc_security_mrktcap: ')
outlookDF
}
#' Full transcript of earnings call
#'
#' @inheritParams fmpc_security_ratings
#' @param quarter earnings year quarter
#' @param year earnings call year
#'
#' @return earnings call transcript in data frame
#' @export
#'
#' @examples
#'
#'\dontrun{
#'
#' # Demo can pull AAPL
#' fmpc_set_token()
#' fmpc_earning_call_transcript('AAPL',quarter = 1, year = 2019)
#'
#' # For multiple symbols, set a valid API Token
#' fmpc_set_token('FMPAPIKEY')
#' fmpc_earning_call_transcript(c('AAPL','MSFT','SPY'))
#'
#' }
#'
fmpc_earning_call_transcript <- function(symbols = c('AAPL'),
quarter = 2,
year = 2020) {
symbReq = hlp_symbolCheck(symbols)
callURL = paste0('earning_call_transcript/',symbReq,'?quarter=',quarter,'&year=',year,'&')
# Use custom function to collapse requests into data frame
callDF = hlp_bindURLs(callURL)
# Send warning for symbols not pulled
hlp_respCheck(symbReq,callDF$symbol,'fmpc_earning_call_transcript: ')
callDF
}