ts_index returns an indexed series, with value of 1 at the base date or range. ts_compound builds an index from percentage change rates, starting with 1 and compounding the rates.

ts_compound(x, denominator = 100)

ts_index(x, base = NULL)

Arguments

x

ts-boxable time series, an object of class ts, xts, zoo, data.frame, data.table, tbl, tbl_ts, tbl_time, tis, irts or timeSeries.

denominator

positive number. Set equal to 1 if percentage change rate is given a decimal fraction

base

base date, character string, Date or POSIXct, at which the index is set to 1. If two dates are provided, the mean in the range is set equal to 1 (see examples).

Value

a ts-boxable object of the same class as x, i.e., an object of class ts, xts, zoo, data.frame, data.table, tbl, tbl_ts, tbl_time, tis, irts or timeSeries.

Examples

x <- ts_pc(ts_c(fdeaths, mdeaths)) ts_compound(x)
#> fdeaths mdeaths #> Jan 1974 1.0000000 1.0000000 #> Feb 1974 0.7647059 0.8730084 #> Mar 1974 0.9178690 0.8795689 #> Apr 1974 0.7513873 0.8795689 #> May 1974 0.5793563 0.6991565 #> Jun 1974 0.4506104 0.5852858 #> Jul 1974 0.4894562 0.5998126 #> Aug 1974 0.4361820 0.5299906 #> Sep 1974 0.4295228 0.5665417 #> Oct 1974 0.6459489 0.6991565 #> Nov 1974 0.6415094 0.7596064 #> Dec 1974 0.7391787 0.8650422 #> Jan 1975 0.9211987 0.9854733 #> Feb 1975 0.8346282 1.0014058 #> Mar 1975 0.8712542 1.0089035 #> Apr 1975 0.7369589 0.8589503 #> May 1975 0.5183130 0.6574508 #> Jun 1975 0.4861265 0.6035614 #> Jul 1975 0.4672586 0.5557638 #> Aug 1975 0.4572697 0.5309278 #> Sep 1975 0.3806881 0.4934396 #> Oct 1975 0.4883463 0.6312090 #> Nov 1975 0.5893452 0.7239925 #> Dec 1975 0.8557159 0.9681350 #> Jan 1976 0.8512764 0.9465792 #> Feb 1976 1.2663707 1.2886598 #> Mar 1976 0.9944506 1.0698219 #> Apr 1976 0.5904550 0.6930647 #> May 1976 0.4961154 0.5571696 #> Jun 1976 0.4661487 0.5435801 #> Jul 1976 0.4173141 0.5215558 #> Aug 1976 0.3662597 0.4545455 #> Sep 1976 0.3962264 0.4681350 #> Oct 1976 0.4938957 0.5660731 #> Nov 1976 0.6059933 0.6874414 #> Dec 1976 0.8479467 0.9648547 #> Jan 1977 0.9567148 1.0496720 #> Feb 1977 0.7325194 0.7656982 #> Mar 1977 0.7358491 0.8069353 #> Apr 1977 0.7136515 0.8439550 #> May 1977 0.5571587 0.5838800 #> Jun 1977 0.4350721 0.5445173 #> Jul 1977 0.4561598 0.5093721 #> Aug 1977 0.3862375 0.4746954 #> Sep 1977 0.4295228 0.4493908 #> Oct 1977 0.4273030 0.5524836 #> Nov 1977 0.4561598 0.5759138 #> Dec 1977 0.7081021 0.7755389 #> Jan 1978 0.8834628 0.9461106 #> Feb 1978 0.9467259 1.0702905 #> Mar 1978 0.8179800 0.9100281 #> Apr 1978 0.6059933 0.6668229 #> May 1978 0.5882353 0.6279288 #> Jun 1978 0.4950055 0.5562324 #> Jul 1978 0.4783574 0.5145267 #> Aug 1978 0.4017758 0.4704780 #> Sep 1978 0.4295228 0.4545455 #> Oct 1978 0.4772475 0.5342081 #> Nov 1978 0.4716981 0.5201500 #> Dec 1978 0.7536071 0.8491097 #> Jan 1979 0.9112098 1.0604499 #> Feb 1979 0.8712542 0.8528585 #> Mar 1979 0.8068812 0.8650422 #> Apr 1979 0.6792453 0.7174321 #> May 1979 0.5305216 0.5693533 #> Jun 1979 0.4761376 0.5037488 #> Jul 1979 0.4495006 0.4948454 #> Aug 1979 0.4206437 0.4568885 #> Sep 1979 0.4361820 0.4404873 #> Oct 1979 0.4561598 0.5065604 #> Nov 1979 0.5405105 0.6063730 #> Dec 1979 0.6370699 0.6283974
y <- ts_df(ts_c(fdeaths, mdeaths)) ts_index(y, "1974-02-01")
#> id time value #> 1 fdeaths 1974-01-01 1.3076923 #> 2 fdeaths 1974-02-01 1.0000000 #> 3 fdeaths 1974-03-01 1.2002903 #> 4 fdeaths 1974-04-01 0.9825835 #> 5 fdeaths 1974-05-01 0.7576197 #> 6 fdeaths 1974-06-01 0.5892598 #> 7 fdeaths 1974-07-01 0.6400581 #> 8 fdeaths 1974-08-01 0.5703919 #> 9 fdeaths 1974-09-01 0.5616836 #> 10 fdeaths 1974-10-01 0.8447025 #> 11 fdeaths 1974-11-01 0.8388970 #> 12 fdeaths 1974-12-01 0.9666183 #> 13 fdeaths 1975-01-01 1.2046444 #> 14 fdeaths 1975-02-01 1.0914369 #> 15 fdeaths 1975-03-01 1.1393324 #> 16 fdeaths 1975-04-01 0.9637155 #> 17 fdeaths 1975-05-01 0.6777939 #> 18 fdeaths 1975-06-01 0.6357039 #> 19 fdeaths 1975-07-01 0.6110305 #> 20 fdeaths 1975-08-01 0.5979681 #> 21 fdeaths 1975-09-01 0.4978229 #> 22 fdeaths 1975-10-01 0.6386067 #> 23 fdeaths 1975-11-01 0.7706821 #> 24 fdeaths 1975-12-01 1.1190131 #> 25 fdeaths 1976-01-01 1.1132075 #> 26 fdeaths 1976-02-01 1.6560232 #> 27 fdeaths 1976-03-01 1.3004354 #> 28 fdeaths 1976-04-01 0.7721335 #> 29 fdeaths 1976-05-01 0.6487663 #> 30 fdeaths 1976-06-01 0.6095791 #> 31 fdeaths 1976-07-01 0.5457184 #> 32 fdeaths 1976-08-01 0.4789550 #> 33 fdeaths 1976-09-01 0.5181422 #> 34 fdeaths 1976-10-01 0.6458636 #> 35 fdeaths 1976-11-01 0.7924528 #> 36 fdeaths 1976-12-01 1.1088534 #> 37 fdeaths 1977-01-01 1.2510885 #> 38 fdeaths 1977-02-01 0.9579100 #> 39 fdeaths 1977-03-01 0.9622642 #> 40 fdeaths 1977-04-01 0.9332366 #> 41 fdeaths 1977-05-01 0.7285922 #> 42 fdeaths 1977-06-01 0.5689405 #> 43 fdeaths 1977-07-01 0.5965167 #> 44 fdeaths 1977-08-01 0.5050798 #> 45 fdeaths 1977-09-01 0.5616836 #> 46 fdeaths 1977-10-01 0.5587808 #> 47 fdeaths 1977-11-01 0.5965167 #> 48 fdeaths 1977-12-01 0.9259797 #> 49 fdeaths 1978-01-01 1.1552975 #> 50 fdeaths 1978-02-01 1.2380261 #> 51 fdeaths 1978-03-01 1.0696662 #> 52 fdeaths 1978-04-01 0.7924528 #> 53 fdeaths 1978-05-01 0.7692308 #> 54 fdeaths 1978-06-01 0.6473149 #> 55 fdeaths 1978-07-01 0.6255443 #> 56 fdeaths 1978-08-01 0.5253991 #> 57 fdeaths 1978-09-01 0.5616836 #> 58 fdeaths 1978-10-01 0.6240929 #> 59 fdeaths 1978-11-01 0.6168360 #> 60 fdeaths 1978-12-01 0.9854862 #> 61 fdeaths 1979-01-01 1.1915820 #> 62 fdeaths 1979-02-01 1.1393324 #> 63 fdeaths 1979-03-01 1.0551524 #> 64 fdeaths 1979-04-01 0.8882438 #> 65 fdeaths 1979-05-01 0.6937591 #> 66 fdeaths 1979-06-01 0.6226415 #> 67 fdeaths 1979-07-01 0.5878084 #> 68 fdeaths 1979-08-01 0.5500726 #> 69 fdeaths 1979-09-01 0.5703919 #> 70 fdeaths 1979-10-01 0.5965167 #> 71 fdeaths 1979-11-01 0.7068215 #> 72 fdeaths 1979-12-01 0.8330914 #> 73 mdeaths 1974-01-01 1.1454643 #> 74 mdeaths 1974-02-01 1.0000000 #> 75 mdeaths 1974-03-01 1.0075148 #> 76 mdeaths 1974-04-01 1.0075148 #> 77 mdeaths 1974-05-01 0.8008588 #> 78 mdeaths 1974-06-01 0.6704240 #> 79 mdeaths 1974-07-01 0.6870639 #> 80 mdeaths 1974-08-01 0.6070853 #> 81 mdeaths 1974-09-01 0.6489533 #> 82 mdeaths 1974-10-01 0.8008588 #> 83 mdeaths 1974-11-01 0.8701020 #> 84 mdeaths 1974-12-01 0.9908749 #> 85 mdeaths 1975-01-01 1.1288245 #> 86 mdeaths 1975-02-01 1.1470746 #> 87 mdeaths 1975-03-01 1.1556629 #> 88 mdeaths 1975-04-01 0.9838969 #> 89 mdeaths 1975-05-01 0.7530864 #> 90 mdeaths 1975-06-01 0.6913580 #> 91 mdeaths 1975-07-01 0.6366076 #> 92 mdeaths 1975-08-01 0.6081589 #> 93 mdeaths 1975-09-01 0.5652174 #> 94 mdeaths 1975-10-01 0.7230274 #> 95 mdeaths 1975-11-01 0.8293076 #> 96 mdeaths 1975-12-01 1.1089640 #> 97 mdeaths 1976-01-01 1.0842727 #> 98 mdeaths 1976-02-01 1.4761138 #> 99 mdeaths 1976-03-01 1.2254428 #> 100 mdeaths 1976-04-01 0.7938808 #> 101 mdeaths 1976-05-01 0.6382179 #> 102 mdeaths 1976-06-01 0.6226516 #> 103 mdeaths 1976-07-01 0.5974235 #> 104 mdeaths 1976-08-01 0.5206656 #> 105 mdeaths 1976-09-01 0.5362319 #> 106 mdeaths 1976-10-01 0.6484165 #> 107 mdeaths 1976-11-01 0.7874396 #> 108 mdeaths 1976-12-01 1.1052067 #> 109 mdeaths 1977-01-01 1.2023618 #> 110 mdeaths 1977-02-01 0.8770800 #> 111 mdeaths 1977-03-01 0.9243156 #> 112 mdeaths 1977-04-01 0.9667203 #> 113 mdeaths 1977-05-01 0.6688137 #> 114 mdeaths 1977-06-01 0.6237252 #> 115 mdeaths 1977-07-01 0.5834675 #> 116 mdeaths 1977-08-01 0.5437466 #> 117 mdeaths 1977-09-01 0.5147611 #> 118 mdeaths 1977-10-01 0.6328502 #> 119 mdeaths 1977-11-01 0.6596887 #> 120 mdeaths 1977-12-01 0.8883521 #> 121 mdeaths 1978-01-01 1.0837359 #> 122 mdeaths 1978-02-01 1.2259796 #> 123 mdeaths 1978-03-01 1.0424047 #> 124 mdeaths 1978-04-01 0.7638218 #> 125 mdeaths 1978-05-01 0.7192700 #> 126 mdeaths 1978-06-01 0.6371444 #> 127 mdeaths 1978-07-01 0.5893720 #> 128 mdeaths 1978-08-01 0.5389157 #> 129 mdeaths 1978-09-01 0.5206656 #> 130 mdeaths 1978-10-01 0.6119163 #> 131 mdeaths 1978-11-01 0.5958132 #> 132 mdeaths 1978-12-01 0.9726248 #> 133 mdeaths 1979-01-01 1.2147075 #> 134 mdeaths 1979-02-01 0.9769189 #> 135 mdeaths 1979-03-01 0.9908749 #> 136 mdeaths 1979-04-01 0.8217928 #> 137 mdeaths 1979-05-01 0.6521739 #> 138 mdeaths 1979-06-01 0.5770263 #> 139 mdeaths 1979-07-01 0.5668277 #> 140 mdeaths 1979-08-01 0.5233494 #> 141 mdeaths 1979-09-01 0.5045625 #> 142 mdeaths 1979-10-01 0.5802469 #> 143 mdeaths 1979-11-01 0.6945786 #> 144 mdeaths 1979-12-01 0.7198068
# \donttest{ ts_plot( `My Expert Knowledge` = ts_chain( mdeaths, ts_compound(ts_bind(ts_pc(mdeaths), 15, 23, 33)) ), `So Far` = mdeaths, title = "A Very Manual Forecast" )
# mean of 1974 = 1 ts_index(mdeaths, c("1974-01-01", "1974-12-31"))
#> Jan Feb Mar Apr May Jun Jul #> 1974 1.3427717 1.1722511 1.1810602 1.1810602 0.9388076 0.7859053 0.8054114 #> 1975 1.3232657 1.3446594 1.3547271 1.1533742 0.8828064 0.8104452 0.7462640 #> 1976 1.2710398 1.7303760 1.4365267 0.9306277 0.7481516 0.7299040 0.7003303 #> 1977 1.4094699 1.0281579 1.0835300 1.1332389 0.7840176 0.7311625 0.6839704 #> 1978 1.2704106 1.4371559 1.2219600 0.8953909 0.8431650 0.7468932 0.6908919 #> 1979 1.4239421 1.1451943 1.1615542 0.9633475 0.7645116 0.6764197 0.6644644 #> Aug Sep Oct Nov Dec #> 1974 0.7116564 0.7607362 0.9388076 1.0199780 1.1615542 #> 1975 0.7129149 0.6625767 0.8475696 0.9721567 1.2999843 #> 1976 0.6103508 0.6285984 0.7601070 0.9230769 1.2955797 #> 1977 0.6374076 0.6034293 0.7418594 0.7733207 1.0413717 #> 1978 0.6317445 0.6103508 0.7173195 0.6984427 1.1401605 #> 1979 0.6134969 0.5914740 0.6801951 0.8142205 0.8437942
# }