# Montly and total loan payment when monthly interest varies depending on the length of month

Usually, a monthly loan mortgage payment is calculated using the formula (source): $$paymen\_m = P \cdot rate\_y ~ / \left[ 1 - (1 + rate\_y) ^{-n\_months} \right]$$

Here (and later in the text):

• P = Loan principal (Euro)
• Q = Remainder of the principal (Euro)
• rate_y = Yearly interest rate
• paymen_m = interest_m + principal_m
• interest_m = Monthly interest (Euro)
• principal_m = Amount of principal that is returned for that month - (Euro)
• paymen_m = Monthly loan payment (Euro)
• n_months = No. of months of the loan payment
• n_days_in_month = the number of days in a certain month: 28, 29, 30, or 31 depending on the month and if the year is leap or non-leap year.

In the formula, it is assumed that the monthly interest rate is constant. But in the bank of interest monthly interest in Euro depends on the number of days in the month and is calculated using the following formula ("R" code):

P      = 50000        # Loan principal in Euro
Q      = P            # Remainder of the principal for the first month
rate_y = 2.00 / 100   # Yearly interest rate
n_days_in_month = 31  # Let's take only the first month

interest_m = n_days_in_month * round(Q * rate_y / 360, digits = 2)
interest_m

#> 86.18


How to calculate the total sum of money that should be paid to the bank (Total) and the monthly loan payment (paymen_m), which is constant every month? Either analytic or R/Python-based solutions are preferred.

For the illustration, we could use only one year (12 months):

n_days_in_month = c(30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31)

• Consider an annuity of 1 EUR paid at the end of every month. Starting at i=n_months and working backward until i=1 calculate the PV of this annuity with interest in each month given by your formula. Then 50000 (i.e. the initial loan amount) divided by this PV gives you the required monthly payment. Jun 15 at 21:27