An RE Partners financial planning workflow needs to estimate the future balance of an investment. Given an initial principal, an annual interest rate, a compounding frequency, and a duration, calculate the final balance using compound interest.
Use the formula A = P * (1 + r / n) ** (n * t), where P is the principal, r is the annual interest rate as a decimal, n is the number of compounding periods per year, and t is the number of years. Return the balance rounded to two decimal places.
Implement calculate_compound_interest(principal, annual_rate, compounds_per_year, years).
principal is a nonnegative number representing the initial balance.annual_rate is a nonnegative percentage, such as 5 for 5% annual interest.compounds_per_year is a positive integer.years is a nonnegative integer.def calculate_compound_interest(principal, annual_rate, compounds_per_year, years):