- Notifications
You must be signed in to change notification settings - Fork7
License
Unknown, MIT licenses found
Licenses found
msperlin/GetTDData
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Information regarding prices and yields of bonds issued by the Braziliangovernment can be downloaded manually as excel files from theTesouroDireto website. However, it ispainful to aggregate all of this data into something useful as theseveral files don’t have an uniform format.
PackageGetTDData makes the process of importing data from Tesourodireto much easier. All that you need in order to download the data isthe name of the assets (LFT, LTN, NTN-C, NTN-B, NTN-B Principal, NTN-F).
# from CRAN (stable version)install.package('GetTDData')# from github (development version)devtools::install_github('msperlin/GetTDData')Suppose you need financial data (prices and yields) for a bond of typeLTN with a maturity (end of contract) at 2023-01-01. This bullet bond isthe most basic debt contract the Brazilian government issues. It doesnot pay any value (coupon) during its lifetime and will pay 1000 R$ atmaturity.
In order to get the data, all you need to do is to run the followingcode in R:
library(GetTDData)assets<-'LTN'# Identifier of assetsfirst_year<-2020last_year<-2022df_td<- td_get(assets,first_year,last_year)#>#> ── Downloading TD files#> ℹ Downloading LTN_2020.xls#> ✔ '/tmp/Rtmpf9eiRh/td-files/LTN/LTN_2020.xls' is found, with size 176.1 kB.#> ℹ Downloading LTN_2021.xls#> ✔ '/tmp/Rtmpf9eiRh/td-files/LTN/LTN_2021.xls' is found, with size 175.1 kB.#> ℹ Downloading LTN_2022.xls#> ✔ '/tmp/Rtmpf9eiRh/td-files/LTN/LTN_2022.xls' is found, with size 175.6 kB.#>#> ── Checking files#> ✔ Found 3 files#>#> ── Reading files#> ℹ Reading '/tmp/Rtmpf9eiRh/td-files/LTN/LTN_2020.xls'#> ✔ Reading Sheet LTN 010121#> ✔ Reading Sheet LTN 010122#> ✔ Reading Sheet LTN 010123#> ✔ Reading Sheet LTN 010125#> ✔ Reading Sheet LTN 010126#> ℹ Reading '/tmp/Rtmpf9eiRh/td-files/LTN/LTN_2021.xls'#> ✔ Reading Sheet LTN 010122#> ✔ Reading Sheet LTN 010123#> ✔ Reading Sheet LTN 010724#> ✔ Reading Sheet LTN 010125#> ✔ Reading Sheet LTN 010126#> ℹ Reading '/tmp/Rtmpf9eiRh/td-files/LTN/LTN_2022.xls'#> ✔ Reading Sheet LTN 010123#> ✔ Reading Sheet LTN 010724#> ✔ Reading Sheet LTN 010125#> ✔ Reading Sheet LTN 010126#> ✔ Reading Sheet LTN 010129
Let’s plot the prices to check if the code worked:
library(ggplot2)library(dplyr)#>#> Attaching package: 'dplyr'#> The following objects are masked from 'package:stats':#>#> filter, lag#> The following objects are masked from 'package:base':#>#> intersect, setdiff, setequal, union# filter LTNmy_asset_code<-"LTN 010123"LTN<-df_td %>% filter(asset_code==my_asset_code)p<- ggplot(data=LTN, aes(x= as.Date(ref_date),y=price_bid,color=asset_code))+ geom_line(size=1)+ scale_x_date()+ labs(title='',x='Dates')#> Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.#> ℹ Please use `linewidth` instead.#> This warning is displayed once every 8 hours.#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was#> generated.print(p)
The latest version ofGetTDData offers functionget.yield.curve todownload the current Brazilian yield curve directly from Anbima. Theyield curve is a tool of financial analysts that show, based on currentprices of fixed income instruments, how the market perceives the futurereal, nominal and inflation returns. You can find more details regardingthe use and definition of a yield curve in[Investopedia][https://www.investopedia.com/terms/y/yieldcurve.asp].
library(GetTDData)df.yield<- get.yield.curve() str(df.yield)
And we can plot it for the derised result:
library(ggplot2)p<- ggplot(df.yield, aes(x=ref.date,y=value) )+ geom_line(size=1)+ geom_point()+ facet_grid(~type,scales='free')+ labs(title= paste0('The current Brazilian Yield Curve'),subtitle= paste0('Date:',df.yield$current.date[1])) print(p)
About
Resources
License
Unknown, MIT licenses found
Licenses found
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.
