tests/testthat/testpv.annuity.R

context("Test present value of annuity payments (spending) made in the future (fv)")

test_that("1 test that start of a timeseries is set correct with timeseries on rate but not pmt", {
  rate=ts(rep(0.04,50),start=2017)
  inflation=ts(rep(0.04,40),start=2017)
  nper=10
  pmt=-1000
  pmtinfladj=FALSE
  pmtUltimo=TRUE
  res = pv.annuity(rate,inflation, nper, pmt, pmtinfladj, pmtUltimo)
  true=ts(c(961.53846153846155,1886.09467455621279,2775.09103322712781,3629.89522425685345,4451.82233101620477,5242.13685674635053,6002.05466994841390,
       6732.74487495039830,7435.33161052922878,8110.89577935502712,8760.47671091829579,9385.07376049836057,9985.64784663303908,10563.12292945484478,
       11118.38743216811963,11652.29560785396097,12165.66885370573073,12659.29697471704822,13133.93939876639161,13590.32634496768515,14029.15994708431208,
       14451.11533373491329,14856.84166705280222,15246.96314139692367,15622.07994365088780,15982.76917658739148,16329.58574671864517,16663.06321799869693,
       16983.71463269105516,17292.03330066447597,17588.49355833122536,17873.55149839540900,18147.64567153404641,18411.19776109042868,18664.61323181771877,
       18908.28195367088119,19142.57880160661807,19367.86423231405570,19584.48483876351384,19792.77388342645281,19993.05181098697358,20185.62674133362816,
       20370.79494359002638,20548.84129191348620,20720.03970376296638,20884.65356131054432,21042.93611664475247,21195.13088138918465,21341.47200133575461,
       21482.18461666899384),start = 2017)
  expect_identical(res,true)
})

test_that("1 test that start of a timeseries is set correct with timeseries on inflation but not pmt and rate", {
  rate=0.04
  inflation=ts(rep(0.04,50),start=2017)
  nper=10
  pmt=-1000
  pmtinfladj=FALSE
  pmtUltimo=TRUE
  res = pv.annuity(rate,inflation, nper, pmt, pmtinfladj, pmtUltimo)
  true=ts(c(961.53846153846155,1886.09467455621279,2775.09103322712781,3629.89522425685345,4451.82233101620477,5242.13685674635053,6002.05466994841390,
            6732.74487495039830,7435.33161052922878,8110.89577935502712,8760.47671091829579,9385.07376049836057,9985.64784663303908,10563.12292945484478,
            11118.38743216811963,11652.29560785396097,12165.66885370573073,12659.29697471704822,13133.93939876639161,13590.32634496768515,14029.15994708431208,
            14451.11533373491329,14856.84166705280222,15246.96314139692367,15622.07994365088780,15982.76917658739148,16329.58574671864517,16663.06321799869693,
            16983.71463269105516,17292.03330066447597,17588.49355833122536,17873.55149839540900,18147.64567153404641,18411.19776109042868,18664.61323181771877,
            18908.28195367088119,19142.57880160661807,19367.86423231405570,19584.48483876351384,19792.77388342645281,19993.05181098697358,20185.62674133362816,
            20370.79494359002638,20548.84129191348620,20720.03970376296638,20884.65356131054432,21042.93611664475247,21195.13088138918465,21341.47200133575461,
            21482.18461666899384),start = 2017)
  expect_identical(res,true)
})

test_that("1 test that start of a timeseries is set correct with timeseries on inflation but not pmt and rate", {
  rate=0.04
  inflation=ts(rep(0.04,10),start=2017)
  nper=10
  pmt=-1000
  pmtinfladj=TRUE
  pmtUltimo=TRUE
  res = pv.annuity(rate,inflation, nper, pmt, pmtinfladj, pmtUltimo)
  true=ts(c(961.53846153846155,1923.07692307692287,2884.61538461538430,3846.15384615384573,4807.69230769230671,5769.23076923076860,6730.76923076923049,
            7692.30769230769147,8653.84615384615245,9615.38461538461524),start = 2017)
  expect_identical(res,true)
})
eaoestergaard/UNPIE documentation built on Aug. 23, 2022, 2:28 a.m.