Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

msperlin/GetTDData

Repository files navigation

Codecov test coverageProject Status: Active – The project has reached a stable, usable state and is being actively developed.R build (rcmdcheck)

PackageGetTDData

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).

Installation

# from CRAN (stable version)install.package('GetTDData')# from github (development version)devtools::install_github('msperlin/GetTDData')

How to use 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)

Downloading the Brazilian Yield Curve

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

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp