Quick Start
This chapter goes over installation instructions and one example call using the EPFR API.
API Login
Please use your EPFR credentials to login to the epfr API.
If you need help with your credentials you can contact the EPFR support team
## [1] "Environment set to: PROD"
## [1] "Previous session closed."
## [1] "Login successful."
API Call
The process of pulling data from the EPFR API follows 3 steps,
1. Create a report using the function epfr.get.reportid(). Parameter inputs can be tailored for desired output.
2. Wait for the API to complete the report.
3. Retrieve data from the report using the function epfr.get.reportoutput().
Below is the function which which checks if a report has been completed and if it’s data is ready to be retrieved.
wait_for_completion <- function(report_id, dataset, inital_time_offset=5, time_offset=10) {
time_taken <- 0
print(paste0("Inital wait for report to complete, delay ", inital_time_offset))
Sys.sleep(inital_time_offset)
time_taken <- time_taken + inital_time_offset
st <- epfr.get.reportstatus(dataset, report_id)$data$status # CHECK STATUS
while (st != "Completed") {
st <- epfr.get.reportstatus(dataset, report_id)$data$status
if (st=="Completed") {
break # REPORT COMPLETE
} else if (st %in% c("Errored","Failed")) {
stop("EPFR job failed") # REPORT FAILED
}
Sys.sleep(time_offset)
time_taken <- time_taken + time_offset
print(paste0("Report ", st, " time taken: ", time_taken))
}
print(paste0("Report complete: ", time_taken, " seconds taken"))
}Example API call
Below is a call to get the total net assets for all equity ETFs in the energy sector from the fund flows database between January 2025 and May 2025.
More information about the available filters, categories, and asset classes in the API Dictionaries section of this notebook.
library(dplyr)
dataset <- "FF"
report <- epfr.get.reportid(dataset = dataset,
from_date = "01-01-2025",
to_date = "05-01-2025",
asset_classes = list("FF100000"), # ALL EQUITY
frequency = "Daily",
level = 0, # AGGREGATE
categories = list(1), # TOTAL NET ASSETS
average_type = NULL,
allocation_ids = NULL,
assets = NULL,
universal_filters = list("U100001"), # ETF
equity_filters = list("E100006"), # ENERGY
bond_filters = NULL,
alternative_filters = NULL)
report_id <- report$data$reportId
wait_for_completion(report_id, dataset)
result <- epfr.get.reportoutput(dataset, report_id) ## [1] "Inital wait for report to complete, delay 5"
## [1] "Report complete: 5 seconds taken"
Output from the example API call.
| Date | Asset Class | Filters | Total Net Assets |
|---|---|---|---|
| 2/20/2025 | All Equity-FF-Equity | ETF Only, Energy | 104413.3 |
| 2/19/2025 | All Equity-FF-Equity | ETF Only, Energy | 103783.8 |
| 1/24/2025 | All Equity-FF-Equity | ETF Only, Energy | 103957.8 |
| 1/23/2025 | All Equity-FF-Equity | ETF Only, Energy | 104698.3 |
| 1/22/2025 | All Equity-FF-Equity | ETF Only, Energy | 104484.4 |
| 1/21/2025 | All Equity-FF-Equity | ETF Only, Energy | 105826.6 |
| 1/20/2025 | All Equity-FF-Equity | ETF Only, Energy | 106284.1 |
| 1/17/2025 | All Equity-FF-Equity | ETF Only, Energy | 106260.8 |
| 1/16/2025 | All Equity-FF-Equity | ETF Only, Energy | 105720.3 |
| 1/15/2025 | All Equity-FF-Equity | ETF Only, Energy | 104548.1 |
API Date Format
The API accepts dates in the form “mm-dd-YYYY” whereas flow dates are written “YYYYmmdd”.
and The API outputs dates in the form “m/d/YYYY” which does not sort chronologically.
Below are 2 helper functions to convert flow dates to the api input dates and api output dates to flow dates.
flow_to_api_date <- function(flow_date) {
y <- substr(flow_date, 1, 4) # INPUT FORMAT "YYYYMMDD"
m <- substr(flow_date, 5, 6)
d <- substr(flow_date, 7, 8)
return(paste0(m, "-", d, "-", y)) #OUTPUT FORMAT "MM-DD-YYYY"
}
chrdate_to_flowdate <- function(date) {
split <- strsplit(date, split="/")[[1]] # INPUT FORMAT "M/D/YYYY"
y <- split[3]
m <- ifelse(nchar(split[1]) == 1, paste0("0", split[1]), split[1])
d <- ifelse(nchar(split[2]) == 1, paste0("0", split[2]), split[2])
return(paste0(y, m, d)) # OUTPUT FORMATT "YYYYMMDD"
}
chrdate_to_flowdate_vec <- Vectorize(chrdate_to_flowdate)Supplemental Libraries
We use the below libraries from tidyverse and EPFR. Please see EPFR.r Library for more information on installing the EPFR.r library.