-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01_data_retrieval.qmd
70 lines (46 loc) · 3.34 KB
/
01_data_retrieval.qmd
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
# Data Retrieval
## Let's Get Started
To kick things off, we need to import the essential libraries that will empower us to interact with the SEC's data and perform insightful analysis. The magic happens when we source the necessary files via `setup.qmd`.
### Import Required Libraries {#sec-import-libraries}
To start, we need to import the required libraries. These libraries provide functions and tools that enable us to interact with the SEC's data and perform data analysis. The necessary libraries are listed in `setup.qmd`.
The data retrieval process is orchestrated using a set of functions located in separate R script files. We'll be sourcing these files via `setup.qmd` to access the functions for retrieving, processing, and analyzing SEC data.
```{r Functions_source, message=FALSE, warning=FALSE}
source("setup.qmd") # Sourcing necessary libraries
```
This sets the stage for retrieving and working with SEC data efficiently.
## Retrieve Data from SEC {#sec-retrieve-data}
In this example, we will focus on one company, JAKKS Pacific Inc. (AAPL), as the target for our data retrieval.
### Define User Headers {#sec-user-headers}
To access the SEC API, we need to define user headers. These headers will be used for making HTTP requests to the SEC servers. We can set our user agent as an example:
```{r headers, warning=FALSE, message=FALSE}
# Define user headers
headers <- c('User-Agent' = 'email@address.com')
kable(headers, "html", class = "custom-table custom-narrow-table")
```
It's essential to set user headers as a standard practice when accessing web APIs to identify the source of the requests.
## Retrieve Company List {#sec-company-list}
Our first step in data retrieval is to obtain the list of companies available on the SEC. This list contains essential information, including the Central Index Key (CIK), which uniquely identifies each company that files reports with the SEC. We'll make an HTTP request to fetch this list:
```{r company_list, eval=TRUE, warning=FALSE, message=FALSE}
# Retrieve company list
company_List <- retrieve_Company_List(headers)
kable(head(company_List), "html", class = "custom-table custom-narrow-table")
```
## Selecting a Company: JAKKS Pacific Inc. (JAKK)
For our analysis, we'll use JAKKS Pacific Inc. (JAKK) as the company of interest. The CIK for JAKKS Pacific Inc. is 0001009829.
Let's now select JAKKS Pacific Inc. by its CIK and retrieve its data from the SEC. The data we retrieve will be stored in the `company_data` object for further analysis:
```{r company_selecte, eval=TRUE, warning=FALSE, message=FALSE, paged.print=TRUE}
# Select JAKKS Pacific Inc. (AAPL) by CIK
cik <- "0001009829" # CIK for JAKKS Pacific Inc.
company_data <- retrieve_Company_Data(headers, cik)
# this the corresponding row of the company list
company_List %>%
filter(cik_str == cik) %>%
kable("html", class = "custom-table custom-narrow-table")
```
By following these steps, we've imported the necessary libraries, sourced relevant files, and initiated the retrieval of financial data from the SEC. In the subsequent chapters, we will delve deeper into exploring and analyzing the SEC data for JAKKS Pacific Inc.
Before we move to the next chapter we save the files.
```{r save_object1, eval=TRUE, warning=FALSE, message=FALSE}
# Load company_data
saveRDS(company_data, file = "company_data.RDS")
saveRDS(cik, file = "cik.RDS")
```