This is a reviw of the package SimFinR.

This package was released to CRAN at the end of 2019 for v 0.1.0, and is a wrapper for the SimFin project, whose mission statement of of prodiving cleaned, standardized data from EDGAR and stock information to help reduce barriers for learning algorithms and new investors. If you are interested in the SimFin API information, that can be found here.

If you would like this RMarkdown document, that can be found here.

Please download the .rmd file and play around with this package, it looks like it will be a solid addition to any finance R user.

The first step you will need to use the package is to acquire an API key. All you will need to do is register an account and then going to the API tab for your account’s API key. The API allows for 2,000 calls per day for a free user, and signing up for SimFin+ for more calls.

We will use an API from a dummy account.

APIkey = "zgPAQaE9G5MdYHDFTbeKtQMR3u4iUgp5"

First we are going to get a list of all the companies available on SimFin.

CompList = simfinR_get_available_companies(APIkey)

# see top companies
head(CompList)
##    simId ticker                          name
## 1 171401   ZYXI                     ZYNEX INC
## 2 901704   ZYNE Zynerba Pharmaceuticals, Inc.
## 3 901866    ZVO                     Zovio Inc
## 4  45730   ZUMZ                    Zumiez Inc
## 5 378251    ZTS                        Zoetis
## 6 896477     ZS                 Zscaler, Inc.

Company Information

The data consist of 3 fields, a unique serial key for each company, the ticker symbol, and the company name. For this review, we will look at Pepsi. And if you want to see a good summary of their data.

CompList[CompList$name == "PEPSICO INC",]
##       simId ticker        name
## NA       NA   <NA>        <NA>
## 752  218222    PEP PEPSICO INC
## NA.1     NA   <NA>        <NA>
CompanyID = 218222
TickerSymbol = "PEP"
CompanyName = "PEPSICO INC"

SimFin provides the information for the company and name if you just have the serial key. Not sure if the specific use case for that call, but hey, it’s available!

simfinR_get_info_company(CompanyID, APIkey)
## $simId
## [1] 218222
## 
## $ticker
## [1] "PEP"
## 
## $name
## [1] "PEPSICO INC"
## 
## $fyearEnd
## [1] 12
## 
## $employees
## [1] 267000
## 
## $sectorName
## [1] "Beverages - Non-Alcoholic"
## 
## $sectorCode
## [1] 102005
simfinR_id_to_name(CompanyID, APIkey)
## [1] "PEPSICO INC"

Financial Statements

We can call the fill document list for all available statemets that SimFin has available on Pepsi.

DocumentList = simfinR_get_available_statements(CompanyID, APIkey, silent = TRUE)

# Look at a couple of the entries in the list
head(DocumentList)
##     period fyear calculated statement id_sim    name_sim
## 1      TTM  2019       TRUE        pl 218222 PEPSICO INC
## 2 TTM-0.25  2019       TRUE        pl 218222 PEPSICO INC
## 3       H1  2019      FALSE        pl 218222 PEPSICO INC
## 4       Q2  2019       TRUE        pl 218222 PEPSICO INC
## 5       Q1  2019      FALSE        pl 218222 PEPSICO INC
## 6    TTM-1  2018       TRUE        pl 218222 PEPSICO INC

We can see that SimFin provides not just EDGAR filings, but also calculated fields like trailing twelve months [TTM] information and quarterly information depending on how its presented from EDGAR. With Pepsi their 2nd 10Q is presented in 3 months & 8 months for Income Statement but just 8 months for Cash Flow.

The data returned is the period of the reported data, fiscal year, calculated flag, statement type, serial key for the comapny, and company name.

If we want to pull out just the financial statements, we can do that and call out the specific types. pl = income statement (profit/loss) bs = balance sheet cf = cash flow

FinStatements = simfinR_get_fin_statements(
  CompanyID,
  APIkey,
  type_statements = c("pl", "bs", "cf"),
  periods = "FY",
  years = 2018,
  cache_folder = "simfin_cache"
)
## Fetching data for companies: 218222
## Fetching data for years: 2018
## Periods: FY
## 
## Making sure all company ids are available
##  - all good
## 
## Start grabbing data
## Fetching data for PEPSICO INC (218222) | type=pl | period=FY | year=2018
##  Table found. Fetching it..
## Fetching data for PEPSICO INC (218222) | type=bs | period=FY | year=2018
##  Cant find data..
## Fetching data for PEPSICO INC (218222) | type=cf | period=FY | year=2018
##  Table found. Fetching it..
head(FinStatements)
##   company_name            company_sector type_statement period year   ref_date
## 1  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
## 2  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
## 3  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
## 4  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
## 5  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
## 6  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
##                   acc_name   acc_value tid uid parent_tid display_level
## 1                  Revenue  6.4661e+10   1   1          4             0
## 2 Sales & Services Revenue          NA   3   0          1             1
## 3        Financing Revenue          NA   5   0          1             1
## 4            Other Revenue          NA   6   0          1             1
## 5          Cost of revenue -2.9381e+10   2   2          4             0
## 6 Cost of Goods & Services          NA   7   0          2             1
##   check_possible
## 1          FALSE
## 2          FALSE
## 3          FALSE
## 4          FALSE
## 5          FALSE
## 6          FALSE

This will pull out all the in the financial statements: * Company Name * Company Sector * Statement Type * Fiscal Period * Year * Reference Date * Account Name * Account Value

JSON parase data from the call: * tid * uid * Display Level * Check Possible

You will see that this does not return Balance Sheet data for Pepsi. This is because they balance sheet data is stored by quarter, and there is no FY level return for that information. So we would get that with this call:

PEPBalSheet = simfinR_get_fin_statements(
  CompanyID,
  APIkey,
  type_statements = "bs",
  periods = c("Q1","Q2","Q3","Q4"),
  years = 2018,
  cache_folder = "simfin_cache"
)
## Fetching data for companies: 218222
## Fetching data for years: 2018
## Periods: Q1, Q2, Q3, Q4
## 
## Making sure all company ids are available
##  - all good
## 
## Start grabbing data
## Fetching data for PEPSICO INC (218222) | type=bs | period=Q1 | year=2018
##  Table found. Fetching it..
## Fetching data for PEPSICO INC (218222) | type=bs | period=Q2 | year=2018
##  Table found. Fetching it..
## Fetching data for PEPSICO INC (218222) | type=bs | period=Q3 | year=2018
##  Table found. Fetching it..
## Fetching data for PEPSICO INC (218222) | type=bs | period=Q4 | year=2018
##  Table found. Fetching it..
head(PEPBalSheet)
##   company_name            company_sector type_statement period year   ref_date
## 1  PEPSICO INC Beverages - Non-Alcoholic             bs     Q1 2018 2018-03-31
## 2  PEPSICO INC Beverages - Non-Alcoholic             bs     Q1 2018 2018-03-31
## 3  PEPSICO INC Beverages - Non-Alcoholic             bs     Q1 2018 2018-03-31
## 4  PEPSICO INC Beverages - Non-Alcoholic             bs     Q1 2018 2018-03-31
## 5  PEPSICO INC Beverages - Non-Alcoholic             bs     Q1 2018 2018-03-31
## 6  PEPSICO INC Beverages - Non-Alcoholic             bs     Q1 2018 2018-03-31
##                                          acc_name  acc_value tid uid parent_tid
## 1 Cash, Cash Equivalents & Short Term Investments 2.0610e+10   1   1         21
## 2                         Cash & Cash Equivalents 1.3443e+10   2   2          1
## 3                          Short Term Investments 7.1670e+09   3   3          1
## 4                     Accounts & Notes Receivable 7.1710e+09   4   4         21
## 5                        Accounts Receivable, Net         NA   5   5          4
## 6                           Notes Receivable, Net         NA   6   6          4
##   display_level check_possible
## 1             0          FALSE
## 2             1          FALSE
## 3             1          FALSE
## 4             0          FALSE
## 5             1          FALSE
## 6             1          FALSE

We can also pull a specific financial statement and its information.

SingleStatement = simfinR_get_single_fin_statement(
  CompanyID,
  type_statement = "pl",
  period_in = "FY",
  year = 2018,
  APIkey,
  cache_folder = "simfim_cache" # This is just a named cache, nothing preset
  )
## Fetching data for PEPSICO INC (218222) | type=pl | period=FY | year=2018
##  Table found. Fetching it..
head(SingleStatement)
##   company_name            company_sector type_statement period year   ref_date
## 1  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
## 2  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
## 3  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
## 4  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
## 5  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
## 6  PEPSICO INC Beverages - Non-Alcoholic             pl     FY 2018 2018-12-31
##                   acc_name   acc_value tid uid parent_tid display_level
## 1                  Revenue  6.4661e+10   1   1          4             0
## 2 Sales & Services Revenue          NA   3   0          1             1
## 3        Financing Revenue          NA   5   0          1             1
## 4            Other Revenue          NA   6   0          1             1
## 5          Cost of revenue -2.9381e+10   2   2          4             0
## 6 Cost of Goods & Services          NA   7   0          2             1
##   check_possible
## 1          FALSE
## 2          FALSE
## 3          FALSE
## 4          FALSE
## 5          FALSE
## 6          FALSE

Stock History

You can call the stock price history for a company, or more than one company if you want to pull a list.

StockPrice = simfinR_get_price_data(CompanyID, APIkey)
## Fetching price data for 218222
head(StockPrice)
##     ref_date close_adj split_coef share_class_id share_class_name
## 1 2020-01-31    142.02         NA         442104    Common shares
## 2 2020-01-30    143.83         NA         442104    Common shares
## 3 2020-01-29    141.73         NA         442104    Common shares
## 4 2020-01-28    142.44         NA         442104    Common shares
## 5 2020-01-27    142.14         NA         442104    Common shares
## 6 2020-01-24    142.92         NA         442104    Common shares
##   share_class_type currency company_name
## 1           common      USD  PEPSICO INC
## 2           common      USD  PEPSICO INC
## 3           common      USD  PEPSICO INC
## 4           common      USD  PEPSICO INC
## 5           common      USD  PEPSICO INC
## 6           common      USD  PEPSICO INC

This call provides standard stock information: * Date * Adjusted Close * Split Coeffienct * Share count in class * Class Name * Call Type * Currency * Company Name

You can also call just a specific company’s stock information. This method makes use of a cache folder for easier handling.

SingleStock = simfinR_get_single_price_data(CompanyID, APIkey, cache_folder = "simfim_cache")
## Fetching price data for 218222
head(SingleStock)
##     ref_date close_adj split_coef share_class_id share_class_name
## 1 2020-01-31    142.02         NA         442104    Common shares
## 2 2020-01-30    143.83         NA         442104    Common shares
## 3 2020-01-29    141.73         NA         442104    Common shares
## 4 2020-01-28    142.44         NA         442104    Common shares
## 5 2020-01-27    142.14         NA         442104    Common shares
## 6 2020-01-24    142.92         NA         442104    Common shares
##   share_class_type currency company_name
## 1           common      USD  PEPSICO INC
## 2           common      USD  PEPSICO INC
## 3           common      USD  PEPSICO INC
## 4           common      USD  PEPSICO INC
## 5           common      USD  PEPSICO INC
## 6           common      USD  PEPSICO INC

This call provides the same stock information: * Date * Adjusted Close * Split Coeffienct * Share count in class * Class Name * Call Type * Currency * Company Name

Let’s take a look at the stock call with Coke as well.

# Coke ID = 156024
StockList = c(218222,156024)

StockPricePC = simfinR_get_price_data(StockList, APIkey)
## Fetching price data for 218222
## Fetching price data for 156024
head(StockPricePC)
##     ref_date close_adj split_coef share_class_id share_class_name
## 1 2020-01-31    142.02         NA         442104    Common shares
## 2 2020-01-30    143.83         NA         442104    Common shares
## 3 2020-01-29    141.73         NA         442104    Common shares
## 4 2020-01-28    142.44         NA         442104    Common shares
## 5 2020-01-27    142.14         NA         442104    Common shares
## 6 2020-01-24    142.92         NA         442104    Common shares
##   share_class_type currency company_name
## 1           common      USD  PEPSICO INC
## 2           common      USD  PEPSICO INC
## 3           common      USD  PEPSICO INC
## 4           common      USD  PEPSICO INC
## 5           common      USD  PEPSICO INC
## 6           common      USD  PEPSICO INC

This call provides the same stock information, but both in the same return.

nrow(StockPrice)
## [1] 3293
nrow(StockPricePC)
## [1] 6586

Other call

You can also use the API to help you out with some time periods if you are not used to financial timeframes. This call provides the last date for a given period and year

Time_Period = "Q1"
Time_Year = 2018
simfinR_period_to_date(period_in = Time_Period, year_in = Time_Year)
## [1] "2018-03-31"