%
% Defined Benefit Pensions 
%
% r is the interest rate
%
r=0.04;
%
% R = number of years of service, exp(g*R)=3.0
%
R=40;
%
% Assumption: Final salary/initial salary =  exp(gR)
%
% g=log(3.0)/R;
g=log(2.0)/R;
% g = log(1.7)/R;
%g = log(400/27)/R;
%
% D = number of years in retirement (i.e. before death)
% Employer pays 18% and employee pays 8% of gross salary
%
% 
D=20;
c=0.26;
%
printf('Interest rate r = %d, service length R = %d years\n', r, R)
printf('Final salary/Initial salary = exp(g*R) = %d\n', exp(g*R))
%
% F1 is multiplied by c to obtain the actual
% pension fund total
%
F1=(1-exp(-(g-r)*R))/(g-r);
%
% We first find the annuity base cost required
% for D years of retirement, together with the
% corresponding contribution rate.
%
P=1.5 + (R/80)*(1-exp(-r*D))/r;
c1=P/F1;
%
printf('The contribution percentage needed for D = %d funded years c = %d\n', D, c1)
%
% We next compute the number D1 of retirement years
% our fund can actually provide for the USS contribution rate c.
%
F=c*F1;
D1=-(1.0/r)*log(1-r*(F-3/2)/(R/80));
printf("The number of funded years for the USS contribution rate is %d\n", D1)
