Calculating compound interest with vector of rates

后端 未结 1 1702
陌清茗
陌清茗 2020-12-21 10:05

I\'m trying to see if there is a way to vectorize a calculation I performed. I searched for this answer and couldn\'t find what I needed.

I have a vector of growth r

相关标签:
1条回答
  • 2020-12-21 10:44

    This is a "cumulative product", so ?cumprod is what you need:

    1000000 * cumprod(1 + RateVector)
    # [1] 1020000 1050600 1092624 1147255 1216091 1276895 1327971 1367810 1395166
    #[10] 1409118
    
    cbind(AmountVector, newresult = 1000000 * c(1, cumprod(1 + RateVector)))
    #   Principal newresult
    #1    1000000   1000000
    #2    1020000   1020000
    #3    1050600   1050600
    #4    1092624   1092624
    #5    1147255   1147255
    #6    1216091   1216091
    #7    1276895   1276895
    #8    1327971   1327971
    #9    1367810   1367810
    #10   1395166   1395166
    #11   1409118   1409118
    
    0 讨论(0)
提交回复
热议问题