Comounding interest with monlthy payments and government bonus

2 次查看(过去 30 天)
In the UK there are saving products (called a LISA) which adds a bonus of 25% at the end of each year depening on the amount invested over the proceeding 12 months. The bonus only applies to funds added over the previous. These products also have interest rates which compound over time. After the bonus is paid interest applies to it in the subsequent year like the rest of the balance.
For example if I had an account which paid 5% interest, started with an initial £1000, added £100 a month, the value after one year would be something like (1000*(1+0.05)) +(12*(100)*monthly interest)+ (12*100*0.25).
I am trying to create a function I can call up with a for loop to calculate the amount in the account after Y years. I want to tabulate the amount in the account every year and ploy the balance over the years.
function lisa_calc(I,M,G,Y)
% I = initial amount put into savings when account opens
% M = monthly amount added
% G = growth rate or interest rate
% Y = number of years money is saved for
monthly_interest = 1+(G/12)
monthly_payments = 12*M*(monthly_interest);
gov_bonus = (I+(M*12))*0.25;
for year=1:Y
balance = zeros(Y,1);
balance(year) = I*(1+G)+ monthly_payments + gov_bonus;
end
plot(balance)
tabulate(balance)
end
I can only get it to calculate one year accurately and then it runs into difficulties. Getting it to tabulate the amounts per year is also a challenge! Sorry for the (probably) dumb question.
Thanks for any help.

回答(1 个)

BhaTTa
BhaTTa 2024-7-16
I have modified your function to calculate the balance for each year correctly, taking into account the compounded interest, monthly deposits, and the annual government bonus. We will also tabulate the balance for each year and plot the balance over the years.
Here's the updated function:
function lisa_calc(I, M, G, Y)
% I = initial amount put into savings when account opens
% M = monthly amount added
% G = growth rate or interest rate (annual)
% Y = number of years money is saved for
% Convert annual growth rate to monthly growth rate
monthly_interest = (1 + G)^(1/12) - 1;
% Initialize balance array to store balance for each year
balance = zeros(Y+1, 1);
% Set initial balance
balance(1) = I;
% Loop through each year
for year = 1:Y
% Calculate balance at the end of the year with monthly contributions and interest
for month = 1:12
balance(year+1) = balance(year+1) + M; % Add monthly contribution
balance(year+1) = balance(year+1) * (1 + monthly_interest); % Apply monthly interest
end
% Add government bonus at the end of the year
gov_bonus = M * 12 * 0.25;
balance(year+1) = balance(year+1) + gov_bonus;
% Apply annual interest to the entire balance including the initial amount and bonus
balance(year+1) = balance(year+1) + balance(year) * (1 + G) - balance(year);
end
% Plot the balance over the years
figure;
plot(0:Y, balance, '-o');
xlabel('Years');
ylabel('Balance (£)');
title('LISA Account Balance Over Time');
grid on;
% Tabulate the balance for each year
disp('Yearly Balance:');
disp(table((0:Y)', balance, 'VariableNames', {'Year', 'Balance'}));
end

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by