My GNU Amortiser v.2.0 (beta) 
Author Message
 My GNU Amortiser v.2.0 (beta)

<< A cool thing I'd like to do is make a backward amortiser that takes the
interest, principal, and term to deduce the payment. >>

<< For that task, becuse I don't know calculus, I will have to code in
routines that do it by brute force, wasting CPU cycles. >>

There is a closed-form, quick solution for the problem your program solves.
There is also a closed-form, quick solution to the payment problem.
Knowledge of the Calculus, although always desirable, is not necessary for
this. No need to waste your CPU's cycles.

See www.arachnoid.com/lutusp/finance.html for the formulas and a working
example.

--

Paul Lutus
www.arachnoid.com


<snip>



Tue, 22 Jan 2002 03:00:00 GMT  
 My GNU Amortiser v.2.0 (beta)
This is my beta of my GNU Amortiser Programme v.2.0. I have to add some
error traps, but if you are in a debate on the affordability of homes in a
given metro area on a given income, this version will win your argument.

New features added are the inputs for the auxiliary monthly payments for a
given home minus utilities. Things like property tax, mortgage insurance,
and association fees for condos. I'm posting it here for the entertainment
of C gurus to laugh at a newbie as well as for newbies to learn. :) I does
lack in beta some more good error traps, but I'll add them soon enough. I
so far used the source in chi.general to shut up one poster who was
flaming me with the lame "Get off your arse and WORK" argument. Math is
real good for shutting up an opponent when you show the work!

---begin mortgage-2.0.c---
#include <stdio.h>
#include <math.h>

main()
{
/* This is the GNU Amortiser Programme coded by {*filter*}y Viking.       */
/* This programme may be distributed under the GNU Public Licence    */
/* for all to enjoy. :) All modifications must fall under the GNU    */
/* Public Licence when distributed. Of course, I coded it in my      */
/* classic BASIC-like novice style.                                  */

/* This programme was coded by a C novice for other C novices to     */
/* have fun with. :) If you are a C guru, I apologise for my classic */
/* non-indenting style. After all, I originally learned in BASIC. :) */

float insurance;
float principal;
float monthly;
float principle;
float interest;
float payment;
float tax;
float association;
int duration;
printf("Enter the principal\n");
scanf("%f", &principle);
principal = principle;
printf("Enter the interest in APR\n");
scanf("%f", &interest);
printf("Enter the monthly payment\n");
scanf("%f", &payment);
monthly = payment;
printf("Enter your Tax Multiplier in its percentage format\n");
scanf("%f", &tax);
printf("Enter the Association Fee. For single family homes, enter 0\n");
scanf("%f", &association);
printf("Enter the mortgage insurance monthly payment\n");
scanf("%f", &insurance);
duration = 0;
interest = interest / 100;

/* This is the 'juice loan' error detection portion of the programme. */
/* This part ends the programme in case of a 'juice loan' situation.  */
/* A 'juice loan' is an infinite-length loan. (Chicago slang)         */

if(payment <= ((interest / 12) * principle))
{
printf("Infinite Loan Time Error!\n");
return 0;

Quote:
}

/* This is the negative-interest error trap... */

if(interest < 0)
{
printf("Negative Interest Error!\n");
return 0;

Quote:
}

/* This is the math formula to amortise the loan in question.      */
/* This loop calculates the number of payments for the 3 variables */
/* given as you run the executable file after you compile it.      */

while(principle > 0)
{
duration = duration + 1;
principle = principle - (payment - ((interest / 12) * principle));
printf("Payment No. %d     ", duration);
if(principle > 0)
{
printf("Principal remaining is $%.2f\n",principle);

Quote:
}
}

printf("The Last Payment is $%.2f\n", payment + principle);
printf("The total paid is $%.2f\n", (payment * (duration - 1)) + payment + principle);
printf("\n");
tax = tax / 12 * principal / 100;
printf("     $%f is your mortgage payment\n", monthly);
printf("     $%f is your association fee\n", association);
printf("     $%f is your monthly property tax\n", tax);
printf("     $%f is your mortgage insurance payment\n", insurance);
printf("\n");
printf("     $%f is your total monthly payment on the home\n", monthly + association + tax + insurance);

Quote:
}

---end source---

A cool thing I'd like to do is make a backward amortiser that takes the
interest, principal, and term to deduce the payment. With that, it would
be cool to code in the monthly_income * .28 to determine the real-life
payment after it does its thing then printf "Can you REALLY afford it
after all?" for arguments.

For that task, becuse I don't know calculus, I will have to code in
routines that do it by brute force, wasting CPU cycles. For a novice like
myself, that's fine. For a bank processing lots of mortgages, that
brute-force approach will not be acceptable. :) A typical PC running Linux
will do the brute force method nicely, with the way I want to design it.

I'd design it to first use big incriments for the principal then play
high-low and decade-down with smaller incriments until the absolute max is
reached to the penny. The object is to arrive at exactly the term's worth
of payments and maximise that last one. The initial incriments would be
count-up to avoid "juice loan" errors. (infinite-loan-time errors)

--
CAUTION: Email Spam Killer in use. Leave this line in your reply! 152680
 First Law of Economics: You can't sell product to people without money.

4410744 bytes of spam mail deleted.           http://www.*-*-*.com/ ~nospam/



Wed, 23 Jan 2002 03:00:00 GMT  
 My GNU Amortiser v.2.0 (beta)
Hello,

You can calculate the annual repayment by using the following equation.
You don't need to do lots of loops as another guy has already said.

First let's define a few variables (all floats):

Premium = Yearly mortgage repayment that you want to find out

LoanAmount = the Amount borrowed

interest = annual rate of interest (you call it APR e.g. 10.5 % would be
entered as 10.5)

term = the length in years that the loan lasts (Best to keep this as a whole
number only)

Now for the equation:

Premium = LoanAmount / FactorA

Where FactorA = [ { 1 - ( ( 100 / ( 100 + interest )) ^ term ) } * 100 /
interest ]

I've tried to use different brackets to make it a bit clearer. Use the same
brackets in
the code.

That's it!

The ^ sign means 'raised to the power of'.

There are more complex formulae for finding the 'true' monthly etc
repayments and also the
capital outstanding and amount of capital repaid in a year and so on. E-mail
me if
you want them. Note that in my example I have set the monthly payments as
one
twelth of annual payments (as banks in the UK do), although this is not
correct it's
usually close enough and it's in the bank's favour!!!.

Also it is best to have a function to calculate FactorA separately from the
main{} function
in your program. Firstly it will keep things tidier and also FactorA is used
quite a lot
in the other equations so it will pay to have a ready made function to
calculate FactorA
on demand.

Here is some code which seems to work to give you the annual premium.
Note there are no error catchers.

---code starts----

#include <stdio.h>
#include <conio.h>
#include <math.h>

float factorA(float, float);

 float principal;
 float interest;
 float term;
 float premium;
 float factorA_return;

void main(void)
{
 printf("Enter the principal\n");
 scanf("%f", &principal);
 printf("Enter the interest in APR\n");
 scanf("%f", &interest);
 printf("Enter the term\n");
 scanf("%f", &term);

 premium = principal / factorA(term, interest);

 printf("Annual Premium is %.2f\n",premium);
 printf("Monthly Premium is %.2f\n",premium/12);

Quote:
}

float factorA(float term_1, float interest_1)
{
 factorA_return = (100.0/(100.0+interest_1));
 factorA_return = pow(factorA_return ,term_1);
 factorA_return = 1-factorA_return;
 factorA_return = factorA_return *100.0/interest_1;
 return(factorA_return);

Quote:
}

---code ends----

Best wishes

Ben Davies
London, UK.

www.bendavies.com

Quote:

>This is my beta of my GNU Amortiser Programme v.2.0. I have to add some
>error traps, but if you are in a debate on the affordability of homes in a
>given metro area on a given income, this version will win your argument.

>New features added are the inputs for the auxiliary monthly payments for a
>given home minus utilities. Things like property tax, mortgage insurance,
>and association fees for condos. I'm posting it here for the entertainment
>of C gurus to laugh at a newbie as well as for newbies to learn. :) I does
>lack in beta some more good error traps, but I'll add them soon enough. I
>so far used the source in chi.general to shut up one poster who was
>flaming me with the lame "Get off your arse and WORK" argument. Math is
>real good for shutting up an opponent when you show the work!

>---begin mortgage-2.0.c---
>#include <stdio.h>
>#include <math.h>

>main()
>{
>/* This is the GNU Amortiser Programme coded by {*filter*}y Viking.       */
>/* This programme may be distributed under the GNU Public Licence    */
>/* for all to enjoy. :) All modifications must fall under the GNU    */
>/* Public Licence when distributed. Of course, I coded it in my      */
>/* classic BASIC-like novice style.                                  */

>/* This programme was coded by a C novice for other C novices to     */
>/* have fun with. :) If you are a C guru, I apologise for my classic */
>/* non-indenting style. After all, I originally learned in BASIC. :) */

>float insurance;
>float principal;
>float monthly;
>float principle;
>float interest;
>float payment;
>float tax;
>float association;
>int duration;
>printf("Enter the principal\n");
>scanf("%f", &principle);
>principal = principle;
>printf("Enter the interest in APR\n");
>scanf("%f", &interest);
>printf("Enter the monthly payment\n");
>scanf("%f", &payment);
>monthly = payment;
>printf("Enter your Tax Multiplier in its percentage format\n");
>scanf("%f", &tax);
>printf("Enter the Association Fee. For single family homes, enter 0\n");
>scanf("%f", &association);
>printf("Enter the mortgage insurance monthly payment\n");
>scanf("%f", &insurance);
>duration = 0;
>interest = interest / 100;

>/* This is the 'juice loan' error detection portion of the programme. */
>/* This part ends the programme in case of a 'juice loan' situation.  */
>/* A 'juice loan' is an infinite-length loan. (Chicago slang)         */

>if(payment <= ((interest / 12) * principle))
>{
>printf("Infinite Loan Time Error!\n");
>return 0;
>}

>/* This is the negative-interest error trap... */

>if(interest < 0)
>{
>printf("Negative Interest Error!\n");
>return 0;
>}

>/* This is the math formula to amortise the loan in question.      */
>/* This loop calculates the number of payments for the 3 variables */
>/* given as you run the executable file after you compile it.      */

>while(principle > 0)
>{
>duration = duration + 1;
>principle = principle - (payment - ((interest / 12) * principle));
>printf("Payment No. %d     ", duration);
>if(principle > 0)
>{
>printf("Principal remaining is $%.2f\n",principle);
>}

>}
>printf("The Last Payment is $%.2f\n", payment + principle);
>printf("The total paid is $%.2f\n", (payment * (duration - 1)) + payment +
principle);
>printf("\n");
>tax = tax / 12 * principal / 100;
>printf("     $%f is your mortgage payment\n", monthly);
>printf("     $%f is your association fee\n", association);
>printf("     $%f is your monthly property tax\n", tax);
>printf("     $%f is your mortgage insurance payment\n", insurance);
>printf("\n");
>printf("     $%f is your total monthly payment on the home\n", monthly +

association + tax + insurance);

- Show quoted text -

Quote:

>}
>---end source---

>A cool thing I'd like to do is make a backward amortiser that takes the
>interest, principal, and term to deduce the payment. With that, it would
>be cool to code in the monthly_income * .28 to determine the real-life
>payment after it does its thing then printf "Can you REALLY afford it
>after all?" for arguments.

>For that task, becuse I don't know calculus, I will have to code in
>routines that do it by brute force, wasting CPU cycles. For a novice like
>myself, that's fine. For a bank processing lots of mortgages, that
>brute-force approach will not be acceptable. :) A typical PC running Linux
>will do the brute force method nicely, with the way I want to design it.

>I'd design it to first use big incriments for the principal then play
>high-low and decade-down with smaller incriments until the absolute max is
>reached to the penny. The object is to arrive at exactly the term's worth
>of payments and maximise that last one. The initial incriments would be
>count-up to avoid "juice loan" errors. (infinite-loan-time errors)

>--
>CAUTION: Email Spam Killer in use. Leave this line in your reply! 152680
> First Law of Economics: You can't sell product to people without money.

>4410744 bytes of spam mail deleted.           http://www.*-*-*.com/ ~nospam/



Wed, 23 Jan 2002 03:00:00 GMT  
 My GNU Amortiser v.2.0 (beta)
<<

[Dann]

: Something is wrong.  I tried it out, and it just froze.  The first thing I
: did was type in 8.0 for interest rate.  I was going to enter data in a
: second field, but no soap.  It froze.

[BV]

I compiled my code on a Linux box. With Linux, it does work great.
However, I tried compiling my amortiser (v.1.1) on my ISP's UNIX system
and it didn't work. The problem you have is most likely your exact UNIX
system (if applicable) and your exact compiler. I used the GNU C Compiler
when I compiled it up.

Actually, the "Something is wrong" message refers to my online Java applet,
which had a bug until I received this report, not your program. Crossed
wires...

--

Paul Lutus
www.arachnoid.com


Quote:

> : Something is wrong.  I tried it out, and it just froze.  The first thing
I
> : did was type in 8.0 for interest rate.  I was going to enter data in a
> : second field, but no soap.  It froze.

> I compiled my code on a Linux box. With Linux, it does work great.
> However, I tried compiling my amortiser (v.1.1) on my ISP's UNIX system
> and it didn't work. The problem you have is most likely your exact UNIX
> system (if applicable) and your exact compiler. I used the GNU C Compiler
> when I compiled it up.

> UNIX systems seem to have their own personality. Had my amortiser didn't
> work on my Linux box I wouldn't have posted it. I'm sorry that it didn't
> work on your computer. Are you using a C compiler for DOS or something?
> Icompiled my programme and added it to /usr/bin as mortgage.exe and in my
> case it does work great.

> --
> CAUTION: Email Spam Killer in use. Leave this line in your reply! 152680
>  First Law of Economics: You can't sell product to people without money.

> 4410744 bytes of spam mail deleted.           http://www.wwa.com/~nospam/



Wed, 23 Jan 2002 03:00:00 GMT  
 My GNU Amortiser v.2.0 (beta)
<< Excellent. The way I'd do it would waste CPU cycles like a mother{*filter*}er
as I'd adapt my amortiser to work backwards. >>

Visit my page at www.arachnoid.com/lutusp/finance.html for a full set of
equations for problems like this.

--

Paul Lutus
www.arachnoid.com


<snip>



Wed, 23 Jan 2002 03:00:00 GMT  
 My GNU Amortiser v.2.0 (beta)

: Something is wrong.  I tried it out, and it just froze.  The first thing I
: did was type in 8.0 for interest rate.  I was going to enter data in a
: second field, but no soap.  It froze.

I compiled my code on a Linux box. With Linux, it does work great.
However, I tried compiling my amortiser (v.1.1) on my ISP's UNIX system
and it didn't work. The problem you have is most likely your exact UNIX
system (if applicable) and your exact compiler. I used the GNU C Compiler
when I compiled it up.

UNIX systems seem to have their own personality. Had my amortiser didn't
work on my Linux box I wouldn't have posted it. I'm sorry that it didn't
work on your computer. Are you using a C compiler for DOS or something?
Icompiled my programme and added it to /usr/bin as mortgage.exe and in my
case it does work great.

--
CAUTION: Email Spam Killer in use. Leave this line in your reply! 152680
 First Law of Economics: You can't sell product to people without money.

4410744 bytes of spam mail deleted.           http://www.wwa.com/~nospam/



Thu, 24 Jan 2002 03:00:00 GMT  
 My GNU Amortiser v.2.0 (beta)

: You can calculate the annual repayment by using the following equation.
: You don't need to do lots of loops as another guy has already said.

Excellent. The way I'd do it would waste CPU cycles like a mother{*filter*}er as
I'd adapt my amortiser to work backwards. I'm going to have to try your
code out on my Linux box. Your code looks good and simple, just the way I
like it, just about like a "Learn C" type textbook.

: ---code starts----

: #include <stdio.h>
: #include <conio.h>
: #include <math.h>

: float factorA(float, float);

:  float principal;
:  float interest;
:  float term;
:  float premium;
:  float factorA_return;

: void main(void)
: {
:  printf("Enter the principal\n");
:  scanf("%f", &principal);
:  printf("Enter the interest in APR\n");
:  scanf("%f", &interest);
:  printf("Enter the term\n");
:  scanf("%f", &term);

:  premium = principal / factorA(term, interest);

:  printf("Annual Premium is %.2f\n",premium);
:  printf("Monthly Premium is %.2f\n",premium/12);
: }

: float factorA(float term_1, float interest_1)
: {
:  factorA_return = (100.0/(100.0+interest_1));
:  factorA_return = pow(factorA_return ,term_1);
:  factorA_return = 1-factorA_return;
:  factorA_return = factorA_return *100.0/interest_1;
:  return(factorA_return);
: }

: ---code ends----

: Best wishes

Thank you. I have got to ask you a copyright question. Can I use your code
in a GNU programme if I find it useful? My current pet policy is to GNU
all code I post. I see no problem if I use it for my own purposes but
copyright is a potential problem if I decide to use your code in an
argument. I do sometimes use math (and now my own C code) for the purposes
of debate in the newsgroups. If you get chi.general you can find my
amortiser code plus sample output posted there to shut up a flame
opponent.

If you decide that you don't GNU your code, I'll just sit back and code a
brute-force a de-amortiser. More likely, I'd end up taking my current
amortising code and modifying it for brute-force de-amortising.

--
CAUTION: Email Spam Killer in use. Leave this line in your reply! 152680
 First Law of Economics: You can't sell product to people without money.

4410744 bytes of spam mail deleted.           http://www.*-*-*.com/ ~nospam/



Thu, 24 Jan 2002 03:00:00 GMT  
 My GNU Amortiser v.2.0 (beta)
Yes feel free to use the code as written. Make sure you do checks on the
output, though. I was satisfied that it worked for values of 10%. Also
introduce some error handling into the function. If you had a negative
interest rate for example the output would look quite interesting.

You don't need an iterative process (i.e. loops) to solve any of the
premium, term or principal unknowns. But  you would in order to solve an
unknown interest/APR rate.

My poicy on things I post is that anyone can use them without worrying about
copyright. An acknowledgement would be appreciated.

Ben Davies.

P.S. I have checked out the other site at
www.arachnoid.com/lutusp/finance.html. All the equations are there that you
would need for a mortgage calculator, but in a slightly different format.


Quote:

> : You can calculate the annual repayment by using the following equation.
> : You don't need to do lots of loops as another guy has already said.

> Excellent. The way I'd do it would waste CPU cycles like a mother{*filter*}er as
> I'd adapt my amortiser to work backwards. I'm going to have to try your
> code out on my Linux box. Your code looks good and simple, just the way I
> like it, just about like a "Learn C" type textbook.

> : ---code starts----

> : #include <stdio.h>
> : #include <conio.h>
> : #include <math.h>

> : float factorA(float, float);

> :  float principal;
> :  float interest;
> :  float term;
> :  float premium;
> :  float factorA_return;

> : void main(void)
> : {
> :  printf("Enter the principal\n");
> :  scanf("%f", &principal);
> :  printf("Enter the interest in APR\n");
> :  scanf("%f", &interest);
> :  printf("Enter the term\n");
> :  scanf("%f", &term);

> :  premium = principal / factorA(term, interest);

> :  printf("Annual Premium is %.2f\n",premium);
> :  printf("Monthly Premium is %.2f\n",premium/12);
> : }

> : float factorA(float term_1, float interest_1)
> : {
> :  factorA_return = (100.0/(100.0+interest_1));
> :  factorA_return = pow(factorA_return ,term_1);
> :  factorA_return = 1-factorA_return;
> :  factorA_return = factorA_return *100.0/interest_1;
> :  return(factorA_return);
> : }

> : ---code ends----

> : Best wishes

> Thank you. I have got to ask you a copyright question. Can I use your code
> in a GNU programme if I find it useful? My current pet policy is to GNU
> all code I post. I see no problem if I use it for my own purposes but
> copyright is a potential problem if I decide to use your code in an
> argument. I do sometimes use math (and now my own C code) for the purposes
> of debate in the newsgroups. If you get chi.general you can find my
> amortiser code plus sample output posted there to shut up a flame
> opponent.

> If you decide that you don't GNU your code, I'll just sit back and code a
> brute-force a de-amortiser. More likely, I'd end up taking my current
> amortising code and modifying it for brute-force de-amortising.

> --
> CAUTION: Email Spam Killer in use. Leave this line in your reply! 152680
>  First Law of Economics: You can't sell product to people without money.

> 4410744 bytes of spam mail deleted.           http://www.*-*-*.com/ ~nospam/



Thu, 24 Jan 2002 03:00:00 GMT  
 My GNU Amortiser v.2.0 (beta)

: See www.arachnoid.com/lutusp/finance.html for the formulas and a working
: example.

Too bad I use Lynx as my browser. I took a look at your site and what I
did see was amusing. I noticed you took up sailing and went on that around
the world adventure.

I was in the Navy, so my expierences with ships are different. I didn't
like it becuse of general Navy-ness. (the military sucks anyways) Have you
ever thought of trying one of those 3-wheel sail vehicles? Those "cars"
get great gas mileage as they don't burn fuel while underway unlike normal
cars. Due to my Navy expierences, I'm a land-lubber now. :)

--
CAUTION: Email Spam Killer in use. Leave this line in your reply! 152680
 First Law of Economics: You can't sell product to people without money.

4410744 bytes of spam mail deleted.           http://www.wwa.com/~nospam/



Thu, 24 Jan 2002 03:00:00 GMT  
 My GNU Amortiser v.2.0 (beta)

: My poicy on things I post is that anyone can use them without worrying about
: copyright. An acknowledgement would be appreciated.

Thank you. I asked becuse I have a pet policy and I assume others do too.
My pet policy is to GNU my code when I post it. So, my policy is
essentially like yours except that nobody can profit from it excessively.
Given my crude code, there is little danger of this but I make sure
anyways.

If I find your code useful, I'll GNU it when I add to it. It looks like
you coded your code to look crude for newbies to enjoy.

I have my pet policy of making my code GNU so as to contribute to the
freeware for Linux. I use Linux so I want to give something back to the
people who coded Linux up. If others find my code useful, they are free to
use it and add to it as they please.

A while back, I coded a body fat calculator based on a government formula
and posted it as GNU code. It too is in my crude style.

: P.S. I have checked out the other site at
: www.arachnoid.com/lutusp/finance.html. All the equations are there that you
: would need for a mortgage calculator, but in a slightly different format.

I'll have to check out that site. BTW, are you British? I like your last
name Davies, which sounds British. I'm a Yank myself but I use British
spelling as I'm a user of accents.

--
CAUTION: Email Spam Killer in use. Leave this line in your reply! 152680
 First Law of Economics: You can't sell product to people without money.

4410744 bytes of spam mail deleted.           http://www.wwa.com/~nospam/



Thu, 24 Jan 2002 03:00:00 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. GNU C compiler beta test release

2. Amortiser Programme. :)

3. Low-cost GNU support is available (was: GNU and the issue of support)

4. Problems with GNU C 1.18 and GNU C++ 1.18.1

5. Looking for Gnu C, Gnu Pascal (or other free software)

6. TabStripPanel Control Beta Released - Beta Testers Wanted!

7. List of API Changes from Beta 1 to Beta 2

8. Compile Beta 1 code on Beta 2 with some changes

9. Compile Beta 1 code on Beta 2

10. VS.Net Beta 1 with .Net Beta 2?

11. ProgressBar Value stops recursion in Beta and not in Pre-beta

12. On GNU CC v1.17. Also help on getting GNU C++ 1.18.

 

 
Powered by phpBB® Forum Software