# Difference between revisions of "Example:Amortized loan calculator"

author Amortized loan calculator Leif Roschier File:Amortized loan.pdf

## Theory and background

This approach of constructing an amortized loan calculator is similar to one in Ref. [1]

Equation for amortized loan [2] is:

$\frac{a}{A} = \frac{\frac{p}{100\times 12}}{1-\frac{1}{(1-\frac{p}{100\times 12})^{12n}}},$

where $A$ is the amount of loan, $a$ is monthly payment amount, $p$ interest rate per year (monthly interest rate is taken as $p/12$)[3] and $n$ is number of years for payment.

This equation of four variables is probably impossible to present with line and grid nomographs. For this reason a "Type 5" contour nomogram is constructed of the right hand side of the equation and left hand equation is just N-nomogram (Type 2). The two equations for nomogram construction are:

$x = \frac{a}{A}$

and

$x = \frac{\frac{p}{100\times 12}}{1-\frac{1}{(1-\frac{p}{100\times 12})^{12n}}}.$

In practice $x$ is the x-coordinate of the canvas where nomogram is constructed.

#### Right hand side of equation

By defining coordinates $x\,$ and $y\,$:

$x = \frac{\frac{p}{100\times 12}}{1-\frac{1}{(1-\frac{p}{100\times 12})^{12n}}},$

$y = 12n, \,$ we may solve $y\,$ in terms of $x\,$ and $n\,$:

$y = \frac{\log (\frac{x}{x-\frac{p}{100\times 12}})}{\log (1+\frac{p}{100 \times 12})} \,$

The previous two equations are of correct form

$y = f_1(v) \,$

and

$y = f_2(x,u) \,$

for type 5 nomogram. For compressing time axis ($y$-axis), we transform $y \rightarrow \log y$ and find

$y = \log \left( \frac{\log (\frac{x}{x-\frac{p}{100\times 12}})}{\log (1+\frac{p}{100 \times 12})} \right)\,$

$y = \log( 12n ). \,$

#### Left hand side of equation

Left hand side of equation

$x = \frac{a}{A}$

is just N-nomogram

$F_1(u_1) = F_2(u_2)F_3(u_3) \,$

## Generated nomograph

Amortized loan calculator
Generated portable document file (pdf): amortized_loan.pdf

## Source code

"""
ex_amortized_loan.py

Amortized loan calculator

Copyright (C) 2007-2008  Leif Roschier

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
import sys
sys.path.insert(0, "..")
from pynomo.nomographer import *

# Type 5 grid
def f1(x,u):
return log(log(x/(x-u/(100.0*12.0)))/log(1+u/(100.0*12.0)))

block_1_params={
'width':10.0,
'height':5.0,
'block_type':'type_5',
'u_func':lambda u:log(u*12.0),
'v_func':f1,
'u_values':[10.0,11.0,12.0,13.0,14.0,15.0,20.0,25.0,30.0,40.0,50.0,60.0],
'v_values':[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],
'wd_tag':'A',
'u_title':'years',
'v_title':r'interest rate = ',
'u_text_format':r"$%3.0f$ ",
'v_text_format':r"$%3.0f$ \%% ",
}

# this is non-obvious trick to find bottom edge coordinates of the grid in order
# to align it with N nomogram
block1_dummy=Nomo_Block_Type_5(mirror_x=False)
block1_dummy.define_block(block_1_params)
block1_dummy.set_block()

# Let's define the N-nomogram
N_params_3={
'u_min':block1_dummy.grid_box.params_wd['u_min'],
'u_max':block1_dummy.grid_box.params_wd['u_max'],
'function':lambda u:u,
'title':'',
'tag':'A',
'tick_side':'right',
'tick_levels':2,
'tick_text_levels':2,
'reference':False,
'tick_levels':0,
'tick_text_levels':0,
'title_draw_center':True
}
N_params_2={
'u_min':30.0,
'u_max':1000.0,
'function':lambda u:u,
'title':'Loan',
'tag':'none',
'tick_side':'left',
'tick_levels':3,
'tick_text_levels':2,
'title_draw_center':True,
'text_format':r"$%3.0f$ ",
}
N_params_1={
'u_min':0.2,
'u_max':3.0,
'function':lambda u:u,
'title':'monthly payment',
'tag':'none',
'tick_side':'right',
'tick_levels':3,
'tick_text_levels':2,
'title_draw_center':True
}

block_2_params={
'block_type':'type_2',
'width':10.0,
'height':20.0,
'f1_params':N_params_1,
'f2_params':N_params_2,
'f3_params':N_params_3,
}

main_params={
'filename':'amortized_loan.pdf',
'paper_height':20.0,
'paper_width':20.0,
'block_params':[block_1_params,block_2_params],
'transformations':[('rotate',0.01),('scale paper',)],
'title_str':r'Amortized loan calculator    \copyright    Leif Roschier  2008',
'title_x': 17,
'title_y': 21,
'title_box_width': 5
}
Nomographer(main_params)