-
Notifications
You must be signed in to change notification settings - Fork 0
/
createTickers.R
317 lines (246 loc) · 8.37 KB
/
createTickers.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# =============================================================================.
# Get equity tickers via polygon.io API
# =============================================================================.
# Using this script, equity tickers and their metadata for all underlyings is
# requested from polygon.io API
# =============================================================================.
# Initialization ----
# -----------------------------------------------------------------------------.
rm(list=ls()); gc()
library(devtools); load_all()
library(jsonlite)
library(data.table)
# database
database <- "data/polygonDB.rsqlite"
# API key
apikey <- readLines("data/apikey.txt")
limitedAPIcalls <- F
# objects ----
# -----------------------------------------------------------------------------.
tickers <- data.table()
# functions ----
# -----------------------------------------------------------------------------.
saveTicker <- function(text){
test <- as.data.table(test)
test <- test[ticker == text]
tickers <<- rbind(tickers, test, fill=T)
}
# =============================================================================.
# Search for Tickers ----
# =============================================================================.
# search ticker for JPMorgan Chase
test <- extractPolygonTickers(apikey, "JPMorgan")
saveTicker("JPM")
# search ticker for Bank of America
test <- extractPolygonTickers(apikey, "BAC")
saveTicker("BAC")
# search ticker for Citigroup
test <- extractPolygonTickers(apikey, "Citigroup")
saveTicker("C")
# search ticker for Wells Fargo
test <- extractPolygonTickers(apikey, "Wells")
saveTicker("WFC")
# search ticker for Goldman Sachs
test <- extractPolygonTickers(apikey, "Goldman")
saveTicker("GS")
if(limitedAPIcalls){
cat("\nAPI request limit reached (5 calls per minute), wait for one minute... ")
Sys.sleep(60)
cat("continue!")
}
# search ticker for Morgan Stanley
test <- extractPolygonTickers(apikey, "Stanley")
saveTicker("MS")
# search ticker for U.S. Bancorp
test <- extractPolygonTickers(apikey, "Bancorp")
saveTicker("USB")
# search ticker for PNC Financial Services
test <- extractPolygonTickers(apikey, "PNC")
saveTicker("PNC")
# search ticker for Truist Financial
test <- extractPolygonTickers(apikey, "Truist")
saveTicker("TFC")
# search ticker for Charles Schwab Corporation
test <- extractPolygonTickers(apikey, "Schwab")
saveTicker("SCHW")
if(limitedAPIcalls){
cat("\nAPI request limit reached (5 calls per minute), wait for one minute... ")
Sys.sleep(60)
cat("continue!")
}
# search ticker for TD Bank, N.A.
# test <- extractPolygonTickers(apikey, "TD")
# not found
# search ticker for Capital One
test <- extractPolygonTickers(apikey, "COF")
saveTicker("COF")
# search ticker for The Bank of New York Mellon
test <- extractPolygonTickers(apikey, "Mellon")
saveTicker("BK")
# search ticker for State Street Corporation
test <- extractPolygonTickers(apikey, "Street")
saveTicker("STT")
# search ticker for American Express
test <- extractPolygonTickers(apikey, "Express")
saveTicker("AXP")
# search ticker for Citizens Financial Group
test <- extractPolygonTickers(apikey, "Citizens")
saveTicker("CFG")
if(limitedAPIcalls){
cat("\nAPI request limit reached (5 calls per minute), wait for one minute... ")
Sys.sleep(60)
cat("continue!")
}
# search ticker for HSBC Bank USA
test <- extractPolygonTickers(apikey, "HSBC")
saveTicker("HSBC")
# search ticker for SVB Financial Group
test <- extractPolygonTickers(apikey, "SVB")
saveTicker("SIVBQ")
# search ticker for First Republic Bank
test <- extractPolygonTickers(apikey, "FRCB")
saveTicker("FRCB")
# search ticker for Fifth Third Bank
test <- extractPolygonTickers(apikey, "FITB")
saveTicker("FITB")
# search ticker for Bank of Montreal
test <- extractPolygonTickers(apikey, "BMO")
saveTicker("BMO")
if(limitedAPIcalls){
cat("\nAPI request limit reached (5 calls per minute), wait for one minute... ")
Sys.sleep(60)
cat("continue!")
}
# search ticker for United Services Automobile Association
# test <- extractPolygonTickers(apikey, "USAA")
# not traded publicly
# search ticker for UBS
test <- extractPolygonTickers(apikey, "UBS")
saveTicker("UBS")
# search ticker for M&T Bank
test <- extractPolygonTickers(apikey, "MTB")
saveTicker("MTB")
# search ticker for Ally Financial
test <- extractPolygonTickers(apikey, "Ally")
saveTicker("ALLY")
# search ticker for KeyCorp
test <- extractPolygonTickers(apikey, "KeyCorp")
saveTicker("KEY")
# search ticker for Huntington Bancshares
test <- extractPolygonTickers(apikey, "Huntington")
saveTicker("HBAN")
if(limitedAPIcalls){
cat("\nAPI request limit reached (5 calls per minute), wait for one minute... ")
Sys.sleep(60)
cat("continue!")
}
# search ticker for Barclays
test <- extractPolygonTickers(apikey, "Barclays")
saveTicker("BCS")
# search ticker for Santander Bank
test <- extractPolygonTickers(apikey, "Santander")
saveTicker("SAN")
# search ticker for RBC Bank (subsidy of Royal Bank of Canada, RY)
test <- extractPolygonTickers(apikey, "RY")
saveTicker("RY")
# search ticker for Ameriprise
test <- extractPolygonTickers(apikey, "Ameriprise")
saveTicker("AMP")
# search ticker for Regions Financial Corporation
test <- extractPolygonTickers(apikey, "RF")
saveTicker("RFpB")
if(limitedAPIcalls){
cat("\nAPI request limit reached (5 calls per minute), wait for one minute... ")
Sys.sleep(60)
cat("continue!")
}
# search ticker for Northern Trust
test <- extractPolygonTickers(apikey, "Northern")
saveTicker("NTRS")
# search ticker for BNP Paribas
test <- extractPolygonTickers(apikey, "paribas")
saveTicker("BNPQF")
# search ticker for Discover Financial
test <- extractPolygonTickers(apikey, "Discover")
saveTicker("DFS")
# search ticker for First Citizens BancShares
test <- extractPolygonTickers(apikey, "BancShares")
saveTicker("FCNCA")
# search ticker for Synchrony Financial
test <- extractPolygonTickers(apikey, "Synchrony")
saveTicker("SYF")
if(limitedAPIcalls){
cat("\nAPI request limit reached (5 calls per minute), wait for one minute... ")
Sys.sleep(60)
cat("continue!")
}
# search ticker for Deutsche Bank
test <- extractPolygonTickers(apikey, "Deutsche")
saveTicker("DB")
# search ticker for New York Community Bank
test <- extractPolygonTickers(apikey, "NYCB")
saveTicker("NYCB")
# search ticker for Comerica
test <- extractPolygonTickers(apikey, "Comerica")
saveTicker("CMA")
# search ticker for First Horizon National Corporation
test <- extractPolygonTickers(apikey, "FHN")
saveTicker("FHN")
# search ticker for Raymond James Financial
test <- extractPolygonTickers(apikey, "Raymond")
saveTicker("RJF")
# search ticker for Webster Bank
test <- extractPolygonTickers(apikey, "Webster")
saveTicker("WBS")
if(limitedAPIcalls){
cat("\nAPI request limit reached (5 calls per minute), wait for one minute... ")
Sys.sleep(60)
cat("continue!")
}
# search ticker for Western Alliance Bank
test <- extractPolygonTickers(apikey, "western")
saveTicker("WAL")
# search ticker for Popular, Inc.
test <- extractPolygonTickers(apikey, "popular")
saveTicker("BPOP")
# search ticker for CIBC Bank USA
test <- extractPolygonTickers(apikey, "CM")
saveTicker("CM")
# search ticker for East West Bank
test <- extractPolygonTickers(apikey, "EWBC")
saveTicker("EWBC")
# search ticker for East West Bank
test <- extractPolygonTickers(apikey, "EWBC")
saveTicker("EWBC")
if(limitedAPIcalls){
cat("\nAPI request limit reached (5 calls per minute), wait for one minute... ")
Sys.sleep(60)
cat("continue!")
}
# search ticker for Synovus
test <- extractPolygonTickers(apikey, "Synovus")
saveTicker("SNV")
# search ticker for Valley National Bank
test <- extractPolygonTickers(apikey, "Valley")
saveTicker("VLY")
# search ticker for Credit Suisse
test <- extractPolygonTickers(apikey, "Suisse")
saveTicker("CS")
# search ticker for Mizuho Financial Group
test <- extractPolygonTickers(apikey, "Mizuho")
saveTicker("MFG")
# search ticker for Wintrust Financial
test <- extractPolygonTickers(apikey, "Wintrust")
saveTicker("WTFC")
if(limitedAPIcalls){
cat("\nAPI request limit reached (5 calls per minute), wait for one minute... ")
Sys.sleep(60)
cat("continue!")
}
# search ticker for Cullen/Frost Bankers, Inc.
test <- extractPolygonTickers(apikey, "cullen")
saveTicker("CFR")
# =============================================================================.
# Save Tickers ----
# =============================================================================.
saveRDS(tickers, "data/tickers.rds")