Movatterモバイル変換


[0]ホーム

URL:


rnbp

Intro

The National Bank of Poland (NBP) is the central bank of Polandresponsible for issuing the polish currency, the złoty. NBP exposes apublic API providing data regarding current and previous exchange ratesand gold prices. The goal of thernbp package is to provideaccess to the API from R.

The goal of this document is to present the functionalities of thepackage along with examples on how the retrieved data can be used. Allof the endpoints expose the same set of of functionalities:

Exchange rate tables

The NBP API exposes endpoints for retrieving exchange rate tables. Atthe time of writing this document three tables are available:

An example of retrieving the currently effective exchange rate tableis presented below:

library(ggplot2)library(rnbp)## Retrieve current C exchange rate tableresponse<-get_current_exchangerate_table("C")## Retrieve content from the responsecurrent_exchangerate_table<- response$content$rates[[1]]knitr::kable(current_exchangerate_table)

This data can be then easily used for plotting:

ggplot(current_exchangerate_table,aes(x = code,y = bid,fill = code))+geom_bar(stat ="identity")

Exchange rates

The API exposes endpoints for fetching exchange rates for specificcurrencies. An example of fetching the last 20 exchange rates of eurosand dollars is presented bellow:

## Retrieve last 20 exchange rates for euroseuros_response<-get_last_n_exchangerates("A","EUR",20)## Retrieve last 20 exchange rates for eurosdollars_response<-get_last_n_exchangerates("A","USD",20)## Retrieve rates dataeuros_data<- euros_response$content$ratesdollars_data<- dollars_response$content$rates## Add currency code columnseuros_data$code<- euros_response$content$codedollars_data$code<- dollars_response$content$codecurrency_data<-rbind(euros_data, dollars_data)ggplot(currency_data,aes(x = effectiveDate,y = mid,col = code))+geom_line()+geom_point()

Gold prices

The API also exposes endpoints providing information regarding thegold prices calculated by the National Bank of Poland. An example ofretrieving gold prices from the last 90 days is presented below:

current_date<-Sys.Date()response<-get_goldprice_from_interval(current_date-90, current_date)ggplot(response$content,aes(x = data,y = cena))+geom_point()+geom_line()+geom_smooth()

[8]ページ先頭

©2009-2025 Movatter.jp