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

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.

Show the code
source("setup.qmd")           # Sourcing necessary libraries

This sets the stage for retrieving and working with SEC data efficiently.

Retrieve Data from SEC

In this example, we will focus on one company, JAKKS Pacific Inc. (AAPL), as the target for our data retrieval.

Define 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:

Show the code
# Define user headers
headers <- c('User-Agent' = 'email@address.com')
kable(headers, "html", class = "custom-table custom-narrow-table")
x
User-Agent email@address.com

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

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:

Show the code
# Retrieve company list
company_List <- retrieve_Company_List(headers)
kable(head(company_List), "html", class = "custom-table custom-narrow-table")
cik_str ticker title
0 0000789019 MSFT MICROSOFT CORP
1 0000320193 AAPL Apple Inc.
2 0001045810 NVDA NVIDIA CORP
3 0001652044 GOOGL Alphabet Inc.
4 0001018724 AMZN AMAZON COM INC
5 0001326801 META Meta Platforms, Inc.

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:

Show the code
# 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")
cik_str ticker title
4090 0001009829 JAKK JAKKS PACIFIC INC

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.

Show the code
# Load company_data
saveRDS(company_data, file = "company_data.RDS") 
saveRDS(cik, file = "cik.RDS")