inflows <- c(30000, 10000, 15000)
i <- c(rep(0.025, 5), rep(0.035, 5), rep(0.04, 17)) 
discount_factors <- c(1, cumprod(1 / (1+i)))

pv_inflows <- sum(inflows * discount_factors[1:3])
print(pv_inflows)
## [1] 54033.31

Here, we calculate the present value (PV) of the loan inflows using the given interest rates. We compute discount factors for each year and multiply them by the corresponding inflows to get the total PV.

n_payments <- 25
payment_t <- 3: 27

pv_payment <- function(X){payments <- X * 0.95^(0:n_payments-1) 
  sum(payments * discount_factors[payment_t + 1])}
  
f <- function(X) pv_payment(X) - pv_inflows
first_payment <- suppressWarnings(uniroot(f, c(0, 20000))$root)
first_payment
## [1] 5003.297

We define a function pv_payment to calculate the present value of the repayment schedule for any first payment X. Payments reduce by 5% annually. We then find the X such that the PV of payments equals the PV of the inflows using the uniroot function.

payments <- first_payment * 0.95^(0:(n_payments - 1))

schedule <- data.frame(
  Year = 1:n_payments,
  Time_t = payment_t,
  Payment_EUR = round(payments, 2))
print(schedule, row.names = FALSE)
##  Year Time_t Payment_EUR
##     1      3     5003.30
##     2      4     4753.13
##     3      5     4515.48
##     4      6     4289.70
##     5      7     4075.22
##     6      8     3871.46
##     7      9     3677.88
##     8     10     3493.99
##     9     11     3319.29
##    10     12     3153.32
##    11     13     2995.66
##    12     14     2845.88
##    13     15     2703.58
##    14     16     2568.40
##    15     17     2439.98
##    16     18     2317.98
##    17     19     2202.08
##    18     20     2091.98
##    19     21     1987.38
##    20     22     1888.01
##    21     23     1793.61
##    22     24     1703.93
##    23     25     1618.73
##    24     26     1537.80
##    25     27     1460.91

Finally, we create a table showing the yearly payments starting from t = 3, with each payment decreasing by 5%. The schedule helps visualize how the loan is repaid over 25 years.