context("Test the present value of an single payment (pv) and annuity payments (spending) made in the future")
test_that("1 test that start of a timeseries is set correct with timeseries on inflation but not rate", {
fv = -10000
r1=0.02
r2=ts(rep(0.02,30),start = 2000)
nper=30
infl = ts(rep(0.02,30),start = 2000)
res = pv(r1,infl,nper,fv)-pv(r2,infl,nper,fv)
expect_identical(res,ts(rep(0,30),start =2000))
})
test_that("2 test that start of a timeseries is set correct with timeseries on inflation but not rate", {
fv = -123654
r1=0.02
nper=30
infl = ts(rep(0.02,30),start = 2000)
res = pv(r1,infl,nper,fv)
true= ts(c(118852.364475201830,114237.182309882584,109801.213292851375,105537.498359142046,
101439.348672762455,97500.335133374130,93714.278290440328,90075.238649019928,
86577.507351999157,83215.597224143741,79984.234163921312,76878.348869589885,
73893.068886572350,71023.710963641250,68265.773705921994,65614.930513189145,
63067.022792377109,60618.053433657347,58264.180539847519,56001.711399315180,
53827.096692921165,51736.924925914223,49727.917076042118,47796.921449482994,
45940.908736527294,44156.967259253455,42442.298403742265,40794.212229663841,
39210.123250349716,37687.546376729828),start=2000)
expect_identical(res,true)
})
test_that("3 test that start of a timeseries is set correct with timeseries on pmt ", {
fv = -123654
pmt=ts(rep(-1000,30),start = 2000)
r1=0.04
nper=30
infl = ts(rep(0.02,30),start = 2000)
res = pv(r1,infl,nper,fv,pmt)
true= ts(c(117528.280542986424, 111771.786681954356, 106362.658913504405, 101280.317434171331,
96505.387762685205, 92019.630664880766, 87805.876133121885, 83847.961186388420,
80130.671270632956, 76639.685051700159, 73361.522405059630, 70283.495417871411,
67393.662229526177, 64680.783546812636, 62134.281679300271, 59744.201949418959,
57501.176340098071, 55396.389250727923, 53421.545239651459, 51568.838638411369,
49830.924929591558, 48200.893786324697, 46672.243677412698, 45238.857947543125,
43894.982287303043, 42635.203512609405, 41454.429577810282, 40347.870751079048,
39311.021884840709, 38339.645717849293),start=2000)
expect_identical(res,true)
})
test_that("3 test both pmt and fv ", {
fv = -123654
pmt=-1000
r1=0.04
nper=30
infl = ts(rep(0.02,30),start = 2000)
res = pv(r1,infl,nper,fv,pmt)
true= ts(c(117528.280542986424, 111771.786681954356, 106362.658913504405, 101280.317434171331,
96505.387762685205, 92019.630664880766, 87805.876133121885, 83847.961186388420,
80130.671270632956, 76639.685051700159, 73361.522405059630, 70283.495417871411,
67393.662229526177, 64680.783546812636, 62134.281679300271, 59744.201949418959,
57501.176340098071, 55396.389250727923, 53421.545239651459, 51568.838638411369,
49830.924929591558, 48200.893786324697, 46672.243677412698, 45238.857947543125,
43894.982287303043, 42635.203512609405, 41454.429577810282, 40347.870751079048,
39311.021884840709, 38339.645717849293),start=2000)
expect_identical(res,true)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.