I have a data table that has a balance. The balance is based on deposits / withdrawals of each period. In each period there is an interest rate that should be applied. However, I cannot draw up the interest rate on the balances, mainly applying the interest rate to the balance sheet, and then using the updated balance sheet in the next period to calculate the new value.
Balance_t1 = (0 + Deposit_t1)*(1+Interest_t1) Balance_t2 = (Balance_t1 + Deposit_t2)*(1+Interest_t2) Balance_t3 = (Balance_t2 + Deposit_t3)*(1+Interest_t3)
I have the following data.table
dtCash <- data.table( Deposit = c(100, 100, -300, 0), Balance = c(100, 200, -100, -100), Interest=c(0.1, 0.01, 0.2, 0.1) )
Result:
dtCash <- data.table( Deposit = c(100, 100, -300, 0), Balance = c(100, 200, -100, -100), Interest=c(0.1, 0.01, 0.2, 0.1), BalanceWithInterest = c(110, 212.1, -105.48, -116.028) )
How to update and refer to the updated "Balance" column in each period?