function [Oldpaymt, NewBal, RefBal, Newpaymt, Value] = RefExmp(Loan, OldTerm, ...
RefTim, NewTerm, Costs, Points, PayoffTim, OldInt, NewInt, ValInt);
% function calculates present value of future payment stream under
% refinanced loan.
% Loan = original loan amount;
% OldTerm = term of initial loan in years (on monthly payment basis);
% RefTim = time in years after which to refinance;
% New Term = term of refinanced loan;
% Costs = fixed closing costs for refinancing;
% Points = percentage of new balance as additional costs;
% PayoffTim <= New Term is time (from Refinancing-time at which new loan
% balance is to be paid off in cash (eg at house sale);
% the three interest rates are nominal 12-times-per-year
vold = (1 + OldInt/12)^(-12) ;
Oldpaymt = ((Loan * OldInt)/12)/(1 - vold^OldTerm) ;
NewBal = (Loan * (1 - vold^(OldTerm - RefTim)))/(1 - vold^OldTerm);
RefBal = (NewBal + Costs) * (1 + Points);
vnew = (1 + NewInt/12)^(-12);
Newpaymt = ((RefBal * NewInt)/12)/(1 - vnew^NewTerm);
vval = (1 + ValInt/12)^(-12);
Value = (Newpaymt * 12 * (1 - vval^PayoffTim))/ValInt + (RefBal * ...
vval^PayoffTim * (1 - vnew^(NewTerm - PayoffTim)))/(1 - vnew^NewTerm);