Mortgage Calculation Using z-transforms. Setup the Original Equation Let k=month number: 0,1,2,3...

9
Mortgage Calculation Mortgage Calculation Using z-transforms Using z-transforms

Transcript of Mortgage Calculation Using z-transforms. Setup the Original Equation Let k=month number: 0,1,2,3...

Page 1: Mortgage Calculation Using z-transforms. Setup the Original Equation Let k=month number: 0,1,2,3 etc. Let k=month number: 0,1,2,3 etc. Let y(k)=loan balance.

Mortgage CalculationMortgage Calculation

Using z-transformsUsing z-transforms

Page 2: Mortgage Calculation Using z-transforms. Setup the Original Equation Let k=month number: 0,1,2,3 etc. Let k=month number: 0,1,2,3 etc. Let y(k)=loan balance.

Setup the Original EquationSetup the Original Equation

Let k=month number: 0,1,2,3 etc.Let k=month number: 0,1,2,3 etc. Let y(k)=loan balance in month kLet y(k)=loan balance in month k Let u(k)=payment during month kLet u(k)=payment during month k Let i=interest rate as a proportionLet i=interest rate as a proportion Let m=monthly payment and P=amount of loanLet m=monthly payment and P=amount of loan The loan balance then at month k+1 is: The loan balance then at month k+1 is:

Y(k+1)=y(k)*(1+i/12) – u(k)Y(k+1)=y(k)*(1+i/12) – u(k)

If a=(1+i/12) thenIf a=(1+i/12) then

Y(k+1)=a*y(k) – u(k) (no z transforms yet!!) Y(k+1)=a*y(k) – u(k) (no z transforms yet!!)

Page 3: Mortgage Calculation Using z-transforms. Setup the Original Equation Let k=month number: 0,1,2,3 etc. Let k=month number: 0,1,2,3 etc. Let y(k)=loan balance.

Z-transform Each Term…Z-transform Each Term…

Z(y(k+1))=a*Yz – Uz but u(k) was a steady Z(y(k+1))=a*Yz – Uz but u(k) was a steady unit amount each month, so to find Uz look it up unit amount each month, so to find Uz look it up in the table: Uz=m*z/(z-1)=Z(u(k))in the table: Uz=m*z/(z-1)=Z(u(k))

And using the shift theorem:And using the shift theorem: Z(y(k+1))=z*Yz – z*y(0)Z(y(k+1))=z*Yz – z*y(0)

Note initial values like y(0) are in most cases ignored Note initial values like y(0) are in most cases ignored but can’t be in this example (my bad).but can’t be in this example (my bad).

====================================================Final z-transformed equation:Final z-transformed equation: z*Yz – z*y(0) = a*Yz -m*z/(z-1)z*Yz – z*y(0) = a*Yz -m*z/(z-1)

Page 4: Mortgage Calculation Using z-transforms. Setup the Original Equation Let k=month number: 0,1,2,3 etc. Let k=month number: 0,1,2,3 etc. Let y(k)=loan balance.

Next: Solve for Yz AlgebraicallyNext: Solve for Yz Algebraically

z*Yz – z*y(0) = a*Yz -m*z/(z-1)z*Yz – z*y(0) = a*Yz -m*z/(z-1)z*Yz - a*Yz = + z*y(0) -m*z/(z-1)z*Yz - a*Yz = + z*y(0) -m*z/(z-1)Yz*(z – a) = + z*y(0) -m*z/(z-1)Yz*(z – a) = + z*y(0) -m*z/(z-1)

Yz= + z*y(0) /(z – a) -m*z/((z-1) *(z – a) )Yz= + z*y(0) /(z – a) -m*z/((z-1) *(z – a) )

Page 5: Mortgage Calculation Using z-transforms. Setup the Original Equation Let k=month number: 0,1,2,3 etc. Let k=month number: 0,1,2,3 etc. Let y(k)=loan balance.

Begin the inverse z-transformBegin the inverse z-transform Yz= + z*y(0) /(z – a) - m*z/((z-1) *(z – a) )Yz= + z*y(0) /(z – a) - m*z/((z-1) *(z – a) )

The term z*y(0) /(z – a) can be looked up in the table but the second The term z*y(0) /(z – a) can be looked up in the table but the second half must be expanded using partial fractions:half must be expanded using partial fractions:

==============Notice a trick, multiplying by z======================Notice a trick, multiplying by z========K1*z/(z-1) +k2*z/(z-a)=-m*z/((z-1) *(z – a) )K1*z/(z-1) +k2*z/(z-a)=-m*z/((z-1) *(z – a) )OrOrK1/(z-1) +k2/(z-a)=-m/((z-1) *(z – a) ) K1/(z-1) +k2/(z-a)=-m/((z-1) *(z – a) )

Solving gives: K1=-m/(1-a)=m/(a-1) k2=-m/(a-1)Solving gives: K1=-m/(1-a)=m/(a-1) k2=-m/(a-1)==============Substituting back gives===========================Substituting back gives=============

Yz=z*y(0)/(z – a) + m/(a-1) *(z/(z-1)) -m/(a-1) *(z/(z – a) ) Yz=z*y(0)/(z – a) + m/(a-1) *(z/(z-1)) -m/(a-1) *(z/(z – a) ) Ready, get set, magic happens………Ready, get set, magic happens………

Page 6: Mortgage Calculation Using z-transforms. Setup the Original Equation Let k=month number: 0,1,2,3 etc. Let k=month number: 0,1,2,3 etc. Let y(k)=loan balance.

Solving for Y(k)Solving for Y(k)

Yz=z*y(0)/(z – a) + m/(a-1) *(z/(z-1)) -m/(a-1) *(z/(z – a) )Yz=z*y(0)/(z – a) + m/(a-1) *(z/(z-1)) -m/(a-1) *(z/(z – a) )

Y(k)=y(0)*aY(k)=y(0)*akk +m/(a-1) –m/(a-1 )*a +m/(a-1) –m/(a-1 )*ak k

Or factoring:Or factoring: Y(k)=y(0)*aY(k)=y(0)*akk +m(1- a +m(1- akk )/(a-1) )/(a-1)

If at end of k months the loan is paid off, Y(k)=0 then solve for If at end of k months the loan is paid off, Y(k)=0 then solve for needed monthly payment m:needed monthly payment m:

0=y(0)*a0=y(0)*akk +m(1- a +m(1- akk )/(a-1) )/(a-1) +m(1- a+m(1- akk )/(a-1)= -y(0)* a )/(a-1)= -y(0)* akk but if P=y(0) then:but if P=y(0) then: m= -y(0)* am= -y(0)* akk *(a-1)/(1- a *(a-1)/(1- akk )=-P*(a-1)/(a )=-P*(a-1)/(a-k-k – 1) – 1) or:or:

Page 7: Mortgage Calculation Using z-transforms. Setup the Original Equation Let k=month number: 0,1,2,3 etc. Let k=month number: 0,1,2,3 etc. Let y(k)=loan balance.

Final answer:Final answer: Final Answer (Final Answer (fanfare: “do to do to do to do”fanfare: “do to do to do to do” ) )

m=P*(1-a)/(am=P*(1-a)/(a-k-k – 1) but recall: a=1+i/12 – 1) but recall: a=1+i/12

m=P*(-i/12)/((1+i/12)-k – 1) or or

m=P*(i/12)/(1 - (1+i/12)m=P*(i/12)/(1 - (1+i/12)-k-k) or) or

m=P*(i/12)*(1+i/12)m=P*(i/12)*(1+i/12)kk/((1+i/12)/((1+i/12)kk - 1) - 1)

In C++ and assuming J=i/12 you could write:In C++ and assuming J=i/12 you could write: M = P *J*( (pow(1.0+ J,n))/(pow(1.0+J,n) - 1.0));M = P *J*( (pow(1.0+ J,n))/(pow(1.0+J,n) - 1.0));

Page 8: Mortgage Calculation Using z-transforms. Setup the Original Equation Let k=month number: 0,1,2,3 etc. Let k=month number: 0,1,2,3 etc. Let y(k)=loan balance.

Example:Example:

20 year mortgage, 11% interest, $30000 house:20 year mortgage, 11% interest, $30000 house:

m=P*(-i/12)/((1+i/12)m=P*(-i/12)/((1+i/12)-k-k – 1) – 1) m=30000*(-.11/12)/((1+.11/12)m=30000*(-.11/12)/((1+.11/12)-240-240 – 1) – 1)

m=30000*(-.0091666)/(-.88808)=$309.65m=30000*(-.0091666)/(-.88808)=$309.65

Rent it for 600$/month + utilities Rent it for 600$/month + utilities and begin the joys of landlord/ladyand begin the joys of landlord/lady

ownership……….ownership……….

Page 9: Mortgage Calculation Using z-transforms. Setup the Original Equation Let k=month number: 0,1,2,3 etc. Let k=month number: 0,1,2,3 etc. Let y(k)=loan balance.

Banking Mania 2008Banking Mania 2008

This formula was used in the mortgage This formula was used in the mortgage program that is included here. However, program that is included here. However, the reason for using this formula was the reason for using this formula was never obvious to me. I had simply copied never obvious to me. I had simply copied it from a book and I was amazed, when I it from a book and I was amazed, when I started to learn about z-transforms, at their started to learn about z-transforms, at their power to do this calculation. I had found power to do this calculation. I had found other non transform methods on the other non transform methods on the internet for accomplishing this but they too internet for accomplishing this but they too were complex. were complex.