Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/download_rates.R
The FedInvest data contains one row per bond on a particular date. This function converts that format into an xts frame.
1 | CoerceFedInvest_xts(bond_data)
|
bond_data |
a slice of the FedInvest data |
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)
a list
$rate_table_xts the xts frame
$unique_maturities a numeric vector of the maturities for which there is a column in the xts frame in fractional-year format (1-month = 1/12 = 0.08333333). It should be noted that if bonds in a matruity range of say 15.5-16.5 are not found in the data, there will not be a 16.00000 maturity column in the xts frame.
$modified_data the original data with additional columns
fracyrs fractional-year time to maturity
maturities the regularized fractional-year time to maturity
coupon numeric coupon from percent-format RATE
mid the mid-point between BUY & SELL
YTM yield to maturity
George Fisher
FedInvestData
the function to download the FedInvest data
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.