year_frac: The years between two dates for a given day basis convention

Description Usage Arguments Details Value References See Also Examples

View source: R/date-counters.R

Description

This calculates the years between two dates using the given day basis convention.

Usage

1
year_frac(date1, date2, day_basis, maturity_date = NULL)

Arguments

date1

A vector of dates. This will be coerced to a Date class.

date2

A vector of dates. This will be coerced to a Date class.

day_basis

The basis on which the year fraction is calculated. See is_valid_day_basis()

maturity_date

a vector of dates representing the maturity date of the instrument. Only used for 30E/360 ISDA day basis.

Details

The order of date1 and date2 is not important. If date1 is less than date2 then the result will be non-negative. Otherwise, the result will be negative. The parameters will be repeated with recycling such that each parameter's length is equal to maximum length of any of the parameters.

Value

a numeric vector representing the number of years between date1 and date2.

References

http://en.wikipedia.org/wiki/Day_count_convention

See Also

Other counter methods: actual_360, actual_365, actual_actual_isda, is_valid_day_basis, thirty_360_eu_isda, thirty_360_eu_plus, thirty_360_eu, thirty_360_us, thirty_360

Examples

1
2
3
4
5
require(lubridate)
year_frac(ymd("2010-03-31"), ymd("2012-03-31"), "30/360us") # 2
year_frac(ymd("2010-02-28"), ymd("2012-03-31"), "act/360")  # 2.116667
year_frac(ymd("2010-02-28"), ymd("2012-03-31"), "act/365")  # 2.087671
year_frac(ymd("2010-02-28"), ymd("2012-03-31"), "act/actisda")  # 2.086998

imanuelcostigan/fmdates documentation built on March 24, 2020, 8:54 p.m.