convert_currencies: Convert Currencies

convert_currenciesR Documentation

Convert Currencies

Description

Vectorized approach to converting prices across potentially different dates and between different currencies.

Usage

convert_currencies(
  price_start,
  from,
  to,
  date = lubridate::today(),
  floor_unit = "day"
)

Arguments

price_start

Numeric vector of prices in terms of 'from' currenc(ies).

from

Character vector of currenc(ies) of 'price_start'.

to

Character vector of currenc(ies) to convert 'price_start' to.

date

Date vector specifying date of exchange rate to use.

floor_unit

Character string. Default is "day" meaning that 'date' will be converted based on daily conversion rates. Changing to "week" will change conversions to be based on the start of the week of 'date'.

Value

Numeric vector of 'price_start' now in the 'to' currenc(ies).

Examples

## Not run: 
library(dplyr)

sales_transactions <- tibble(
  local_price = c(100, 80, 9200, 90),
  local_currency = c("USD", "EUR", "JPY", "USD"),
  final_currency = c("EUR", "USD", "USD", "JPY"),
  date_transaction = lubridate::ymd(c(20200601, 20200609, 20200614, 20200623))
)
# Some made-up sales transactions of different values and currencies
sales_transactions %>%
  mutate(
    converted_price = convert_currencies(
      price_start = local_price,
      from = local_currency,
      to = final_currency,
      date = date_transaction
    )
  )

## End(Not run)

priceR documentation built on Oct. 22, 2023, 1:10 a.m.