So you want to compound the interest and calculate the payments in two periods?
If so, you'll need to use the compound interest formula. This is:
A = P (1 + r/n) ^ nt
Where:
A = the future value of the investment/loan, including interest
P = the principal investment amount (the initial deposit or loan amount)
r = the annual interest rate (decimal)
n = the number of times that interest is compounded per year
t = the number of years the money is invested or borrowed for http://www.thecalculatorsite.com/articles/finance/compound-interest-formula.php To find the fund value at a given point, you could just plug the numbers in to the formula. To get the payment, subtract off the value at the previous payment.
For example, if the fund has a starting value of 100 and a 5% return, the following calculates the value of the forth payment (in Dec-16):
begin
dbms_output.put_line(
round(( 100 * power ( ( 1 + (0.05/2) ), 4) ), 2) -
round(( 100 * power ( ( 1 + (0.05/2) ), 3) ), 2)
);
end;
/
2.69
Or you could write some SQL to calculate the value for all periods. This needs a running product. There isn't an in-built function to do this. So you can cheat by exploiting that a product ~ the exponent of the sum of logarithms:
product ( 1 .. n ) ~ exp ( sum ( ln ( 1 .. n ) ) )
Giving SQL like (again starting 100, 5% annual return):
with rws as (
select add_months(date'2015-01-01', ((rownum*6) - 1)) dt,
100 price,
1 + (0.05/2) return
from dual connect by level <= 8
), interest as (
select dt,
price * exp(sum(ln(return)) over (order by dt)) value
from rws
)
select * from interest;
DT VALUE
01-JUN-2015 00:00:00 102.499999999999999999999999999999999999
01-DEC-2015 00:00:00 105.062499999999999999999999999999999998
01-JUN-2016 00:00:00 107.689062499999999999999999999999999997
01-DEC-2016 00:00:00 110.381289062499999999999999999999999995
01-JUN-2017 00:00:00 113.140821289062499999999999999999999996
01-DEC-2017 00:00:00 115.969341821289062499999999999999999994
01-JUN-2018 00:00:00 118.868575366821289062499999999999999991
01-DEC-2018 00:00:00 121.840289750991821289062499999999999991
To calculate the payment at a given point, use lag() to subtract off the previous value. And filter the results as needed:
with rws as (
select add_months(date'2015-01-01', ((rownum*6) - 1)) dt,
100 price,
1 + (0.05/2) return
from dual connect by level <= 8
), interest as (
select dt,
price * exp(sum(ln(return)) over (order by dt)) value
from rws
)
select * from (
select dt, round(value - lag(value) over (order by dt), 2) payments
from interest
)
where dt between date'2016-08-01' and date'2017-09-01';
DT PAYMENTS
01-DEC-2016 00:00:00 2.69
01-JUN-2017 00:00:00 2.76
Note: These calculation produce a lot of decimals! Make sure you check for rounding issues. You'll need to refer to the calculation the fund provider uses to determine how they handle this.