| Title: | Get Data for Brazilian Bonds (Tesouro Direto) |
|---|---|
| Description: | Downloads and aggregates data for Brazilian government issued bonds directly from the website of Tesouro Direto <https://www.tesourodireto.com.br/>. |
| Authors: | Marcelo Perlin [aut, cre] |
| Maintainer: | Marcelo Perlin <marceloperlin@gmail.com> |
| License: | MIT + file LICENSE |
| Version: | 1.7.2 |
| Built: | 2026-10-13 19:45:06 UTC |
| Source: | https://github.com/msperlin/gettddata |
Provides metadata for Brazilian government bond types, including their official names, indexers (e.g., IPCA, SELIC, Fixed rate), payment frequency, and description.
get_asset_info(asset_codes = NULL)get_asset_info(asset_codes = NULL)
asset_codes |
Optional character vector of asset codes (e.g. 'LTN', 'NTN-B'). If 'NULL', returns info for all assets. |
A tibble with asset metadata.
get_asset_info() get_asset_info("LTN")get_asset_info() get_asset_info("LTN")
Returns the cache directory path
get_cache_folder(persistent = getOption("GetTDData.persistent_cache", FALSE))get_cache_folder(persistent = getOption("GetTDData.persistent_cache", FALSE))
persistent |
Logical. If 'TRUE', uses a user-persistent directory via 'tools::R_user_dir'. If 'FALSE', defaults to session temporary directory. Can also be set globally via 'options(GetTDData.persistent_cache = TRUE)'. Defaults to 'FALSE'. |
A character string representing the folder path.
get_cache_folder()get_cache_folder()
Returns the available asset names at the Tesouro Direto (TD) website
get_td_names(online = FALSE)get_td_names(online = FALSE)
online |
Logical. If 'TRUE', attempts to query the Tesouro Direto CDN server for live asset names. Defaults to 'FALSE'. |
A character vector of names.
get_td_names()get_td_names()
Downloads and parses information about the current Brazilian yield curve from Anbima.
get_yield_curve() get.yield.curve()get_yield_curve() get.yield.curve()
A data frame with information about the yield curve.
## Not run: df_yield <- get_yield_curve() str(df_yield) ## End(Not run)## Not run: df_yield <- get_yield_curve() str(df_yield) ## End(Not run)
Starts a Model Context Protocol (MCP) server that exposes a curated set of 'GetTDData' functions as tools for LLM clients such as OpenCode, Claude Desktop, Claude Code, or Positron Assistant. The suggested package 'mcptools' is required.
mcp_server( tools = mcp_tools(), type = c("stdio", "http"), session_tools = FALSE, ... )mcp_server( tools = mcp_tools(), type = c("stdio", "http"), session_tools = FALSE, ... )
tools |
Either a list of 'ellmer::tool()' objects, or the path to an R file that evaluates to such a list. Defaults to the tool definitions shipped with the package (see [mcp_tools()]). |
type |
Transport type: '"stdio"' (default) for clients that launch the process, or '"http"' for an HTTP server. |
session_tools |
Logical. Whether to expose mcptools' built-in R session discovery tools ('list_r_sessions', 'select_r_session'). Defaults to 'FALSE' because GetTDData tools run self-contained in the server process. |
... |
Further arguments passed on to 'mcptools::mcp_server()', such as 'host' or 'port'. |
Register the server with an MCP client by running 'Rscript -e "GetTDData::mcp_server()"'. For example, in OpenCode:
“'json
"mcp": "servers": "GetTDData": "type": "local", "command": ["Rscript", "-e", "GetTDData::mcp_server()"]
“'
Called for its side effect of blocking the R process while the server runs. It does not return.
## Not run: # Requires the mcptools, ellmer, and jsonlite packages GetTDData::mcp_server() ## End(Not run)## Not run: # Requires the mcptools, ellmer, and jsonlite packages GetTDData::mcp_server() ## End(Not run)
Sources the MCP tool definitions shipped with the package ('inst/mcp/tools.R') and returns them as a list of 'ellmer::tool()' objects. These tools wrap a curated set of 'GetTDData' functions so that MCP-enabled LLM clients can fetch Brazilian government bond data.
mcp_tools(path = system.file("mcp", "tools.R", package = "GetTDData"))mcp_tools(path = system.file("mcp", "tools.R", package = "GetTDData"))
path |
Path to an R file that, when sourced, evaluates to a list of 'ellmer::tool()' objects. Defaults to the definitions shipped with the package. This argument is mainly useful for testing custom tool sets. |
The suggested packages 'ellmer' and 'jsonlite' are required. The tool set currently exposes: 'get_td_data()', 'get_td_current()', 'get_yield_curve()', 'get_asset_info()', and 'get_td_names()'.
A named list of 'ellmer::tool()' objects.
## Not run: # Requires the ellmer and jsonlite packages tools <- mcp_tools() names(tools) ## End(Not run)## Not run: # Requires the ellmer and jsonlite packages tools <- mcp_tools() names(tools) ## End(Not run)
Plots price or yield time series trajectories for Tesouro Direto assets downloaded using td_get.
plot_td_series(df_td, type = c("price", "yield"))plot_td_series(df_td, type = c("price", "yield"))
df_td |
A data frame or tibble returned by |
type |
Character string indicating what to plot: |
A ggplot object.
## Not run: df_td <- td_get("LTN", 2020, 2022) plot_td_series(df_td, type = "price") ## End(Not run)## Not run: df_td <- td_get("LTN", 2020, 2022) plot_td_series(df_td, type = "price") ## End(Not run)
Plots the yield curve data frame downloaded using get_yield_curve.
plot_yield_curve(df_yc)plot_yield_curve(df_yc)
df_yc |
A data frame or tibble returned by |
A ggplot object.
## Not run: df_yc <- get_yield_curve() plot_yield_curve(df_yc) ## End(Not run)## Not run: df_yc <- get_yield_curve() plot_yield_curve(df_yc) ## End(Not run)
'r lifecycle::badge("deprecated")'
td_get( asset_codes = "LTN", first_year = 2005, last_year = as.numeric(format(Sys.Date(), "%Y")), dl_folder = get_cache_folder() )td_get( asset_codes = "LTN", first_year = 2005, last_year = as.numeric(format(Sys.Date(), "%Y")), dl_folder = get_cache_folder() )
asset_codes |
A character vector identifying the assets (one or more) in the names of the Excel files (e.g., 'LTN'). If 'NULL', downloads all available assets. |
first_year |
The first year of data (minimum of 2005). |
last_year |
The last year of data. |
dl_folder |
Path of the folder to save Excel files from Tesouro Direto (will create if it does not exist). Defaults to a session-temporary directory. To avoid redownloading files across different R sessions, you can pass a persistent path (e.g., a local folder path, or using tools::R_user_dir("GetTDData", which = "cache")). |
This function looks into the Tesouro Direto website (<https://www.tesourodireto.com.br/>) and downloads all files containing prices and yields of government bonds. You can use the input 'asset_codes' to restrict the downloads to specific bonds.
Due to the closure of the Tesouro Direto data application in August 2026, 'td_get()' is deprecated and resulting data will only go as far as August 2026. Users should use 'td_get2()', a new function that will be developed soon.
A data frame containing the asset data (prices and yields).
## Not run: df_td <- td_get("LTN", 2020, 2022) ## End(Not run)## Not run: df_td <- td_get("LTN", 2020, 2022) ## End(Not run)
Fetches current prices and yields of Tesouro Direto (TD) assets by downloading the latest daily data available from the website.
td_get_current(asset_codes = NULL, dl_folder = get_cache_folder())td_get_current(asset_codes = NULL, dl_folder = get_cache_folder())
asset_codes |
A character vector identifying the assets (e.g., 'LTN', 'NTN-B'). If 'NULL', returns all available assets. |
dl_folder |
Path of the folder to save files. Defaults to a session-temporary directory. |
A tibble with current asset prices, yields, and maturity dates.
## Not run: df_current <- td_get_current() head(df_current) ## End(Not run)## Not run: df_current <- td_get_current() head(df_current) ## End(Not run)
This function downloads historical prices and yields of Brazilian government bonds
directly from the Tesouro Transparente CKAN open data portal
(<https://www.tesourotransparente.gov.br/ckan/dataset/taxas-dos-titulos-ofertados-pelo-tesouro-direto/>).
It serves as the modern replacement for td_get, which relied on the
legacy Tesouro Direto application shut down in August 2026.
td_get2( asset_codes = "LTN", first_year = 2005, last_year = as.numeric(format(Sys.Date(), "%Y")), dl_folder = get_cache_folder(), force_download = FALSE, dataset_url = get_default_ckan_url() )td_get2( asset_codes = "LTN", first_year = 2005, last_year = as.numeric(format(Sys.Date(), "%Y")), dl_folder = get_cache_folder(), force_download = FALSE, dataset_url = get_default_ckan_url() )
asset_codes |
A character vector identifying the assets to download (e.g., 'LTN', 'NTN-B', 'LFT', 'NTN-B Principal', 'NTN-F', 'NTN-C', 'NTN-B1', 'Educa+', 'RendA+'). You can also pass official names such as 'Tesouro Prefixado', 'Tesouro Selic', etc. If ‘NULL', downloads all available assets. Defaults to ’LTN'. |
first_year |
The first year of data (minimum of 2005). Defaults to 2005. |
last_year |
The last year of data. Defaults to the current year. |
dl_folder |
Path of the folder to save data files from Tesouro Transparente.
Defaults to |
force_download |
Logical. If 'TRUE', forces redownloading the data even if a cached version from today is present. Defaults to 'FALSE'. |
dataset_url |
The URL to the CKAN dataset page or direct CSV file. Defaults to "https://www.tesourotransparente.gov.br/ckan/dataset/taxas-dos-titulos-ofertados-pelo-tesouro-direto/". |
A tibble (data frame) containing the asset data:
Reference date (Date)
Annual purchase yield / rate in decimal format (numeric, e.g. 0.1183 for 11.83%)
Unit purchase price in BRL (numeric)
Standard bond identifier (character, e.g. 'LTN 010123')
Maturity date of the bond (Date)
## Not run: df_td <- td_get2("LTN", 2020, 2022) head(df_td) ## End(Not run)## Not run: df_td <- td_get2("LTN", 2020, 2022) head(df_td) ## End(Not run)