CoerceFedInvest_xts: Coerce a slice of FedInvest data to xts

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/download_rates.R

Description

The FedInvest data contains one row per bond on a particular date. This function converts that format into an xts frame.

Usage

1

Arguments

bond_data

a slice of the FedInvest data

Details

The FedInvest data has one row per date, per bond. For analyses such as Nelson Seigel and Svensson we need the data in an xts frame with the format of one row per date and one column per maturity.

This function performs this primary transformation: The bond data has a continuous set of maturities; a fixed xts table needs discrete maturities. So, for example, the 1-year maturity data comprises the average YTM for all the bonds with maturities between 0.5 and 1.5 years.

A number of minor transformations are also performed such as converting the RATE data from a character percent format (7.82%) to decimal (0.0782)

Value

a list

Author(s)

George Fisher

See Also

FedInvestData the function to download the FedInvest data

Examples

 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
library(ustreasuries)
library(magrittr)

start.date <- Sys.Date() - 25
end.date   <- Sys.Date()

rate_table_list <- dplyr::filter(FedInvestData(),
                                  Date >= start.date &
                                  Date <= end.date   &
                                  SECURITY.TYPE != "TIPS") %>%
    CoerceFedInvest_xts()

rate_table_xts    <- rate_table_list$rate_table_xts
unique_maturities <- rate_table_list$unique_maturities
modified_data     <- rate_table_list$modified_data

unique_maturities

knitr::kable(as.data.frame(modified_data[30:32, c(2:4,10:14)]),
caption="Sample of FedInvest Data with additional Data",
row.names=FALSE)

knitr::kable(as.data.frame(rate_table_xts[1:3, 1:5]),
caption="Sample of FedInvest Data after Coersion to xts Format",
row.names=TRUE)

grfiv/ustreasuries documentation built on May 17, 2019, 8:36 a.m.