Gossamer Forum
Home : Products : DBMan : Customization :

Mortgage calculation

Quote Reply
Mortgage calculation
Hi. I would like to add a math function to my database. It would calculate the monthly payment of a loan and
the formula below is the one I've been told to use. The interst rate, and length(months) of loan
will be the same for all calculations(I would like to have two routines, one for 30 years and one for 15 years).
The loan "amount" needs to be pulled from the "Price" field.

I would like to be able to display the "monthly payment"(with some explanatory text) along with the desired fields
when a record is retreived, so the "monthly payment" could be assigned to a variable and does not need to be in a "field".
All records in this particular database would use this option, so there is no need to try and make it
only apply to specific records.

The interest rate would need to be changed manually when it changes, but that's no problem.
There may be a way around that too, but that's something for another time.

Formula:

Monthly payment = Loan amount x interest rate/12 x
(1+interest rate/12)(length of loan in months) (1+ interest rate/12)(length of loan in months) - 1

Any help would be really appreciated,

Spike
Quote Reply
Re: Mortgage calculation In reply to
If it's just going to be something that is printed out with search results, you would place the code in sub html_record.

I need to be sure of some things, though. You say that the interest rate would change and you'd need to manually change that. You probably would need to. But I need to know for sure that the other variables are within the records:

Loan amount
length of loan in months

Also, it makes it easier to give you the code if I know what the field names are for these variables.


------------------
JPD





Quote Reply
Re: Mortgage calculation In reply to
Ok .... The interest would change, probably weekly for now. I ssume I would have to go into html.pl and make the change where it is assigned to a string, no problem.

The loan amount would be pulled from my "Price" field in the database which would have been entered by me earlier. The database is set up where I make all of the entries.

The length of the loan would be a constant, 15 years or or 180 months, and 30 years or 360 months. This is where two uses of the mod come in, to display two different loan amounts depending on loan length. I don't see this being changed very often, if at all.

So, the only item actually pulled from the database would be the amount in the "Price" field.

And right, this would be something that is printed out with search results. Ideally, the results would be displayed under the selected fields I have selected to display in the html.pl file.

The idea behind adding this function is to enhance user value by adding some useful info for user reference. The results don't even need to be 100% accurate as the results will be stated as being "an approximate monthly payment".

Hope this helps and thanks for your time,

Spike

Quote Reply
Re: Mortgage calculation In reply to
Hi, again. One more thing ..... I have the "Price" field as an alpha field so that I can add a comma for a more aesthetic look to the number.

Is this a problem or can the price be converted to a numerical value, dropping the commam, for the calculation?

Thanks,
Spike
Quote Reply
Re: Mortgage calculation In reply to
You do need to take out the comma. It will interfere with your calculation. But, for esthetic purposes, you can put the comma back in.

After you do your computations, which will be before you print out anything, use

Code:
1 while $rec{'Price'} =~ s/(\d)(\d{3})\b/$1,$2/;

That'll stick the commas into the right places.

For your interest rate, it might be easier to edit the .cfg file than the html.pl file -- easier to find what you need to change and a shorter file to upload. So, in your .cfg file, add

$interest_rate = .07;

If you enter it as a decimal, it's easier to do the computation.

I tried to translate your equation into Perl and tested it out. It ended up to be larger than the full amount of the house. I'm pretty sure I have the parentheses in the wrong places, but I'm not sure where they are.

Can you try working a sample out with a calculator to make sure the equation is right?



------------------
JPD





Quote Reply
Re: Mortgage calculation In reply to
Hi. My apologies for nto getting back with you sooner. I managed to find a piece of code for the calculator thing. I finally gave up trying to use a calculator to get it right.

The code for adding the comma back is working fine.

Now, a problem. I can't seem to enter any more fields without getting an "invalid format" error when adding or modifying a record.

I've tried several different field additions and still get the error. There are 36 fields now.

Everything works fine, just can't add any more fields??? I've checked the cfg and html.pl files numerous times but can't find anything out of the ordinary.

Is there a limit on db length that you know of(just fishing here)?

Thanks,
spike

Quote Reply
Re: Mortgage calculation In reply to
No real limit to the fields, except that browsers might crash if you get over 150 or so.

Very odd about your "invalid format" error. Off the top of my head, I can think of only one possibility -- that you copied and pasted another field and there's some formatting in there that you don't want.

If you'd like, I'll take a look at your .cfg file. Just copy it to a web-accessible directory -- one where you would place html files and rename it to default_cfg.txt. Then come back here and let me know where it is.
I'll be glad to take a look and see what I can find.

------------------
JPD





Quote Reply
Re: Mortgage calculation In reply to
Ok, thanks. First, though, it seems that I can add fields that don't use the "option select" option. The problem starts when I use the " for a field.

The urlfor the cfg file is:

http://www.meadville.com/test/default_cfg.txt

Thanks,
Mike
Quote Reply
Re: Mortgage calculation In reply to
Forgot to mention ..... the last field - "pool" is one that doesn't work and gives the "invalid Format error".

spike
Quote Reply
Re: Mortgage calculation In reply to
You need to get rid of

State => [26, 'alpha', 2, 2, 0, 'PA', 'PA'],
Heat => [28, 'alpha', 8, 8, 0, 'Gas', 'Gas'],
Basement => [29, 'alpha', 3, 3, 0, 'Yes', 'Yes'],
Levels => [34, 'alpha', 1, 1, 0, '2', '2'],
Pool => [38, 'alpha', 4, 4, 0, 'No', 'No'],

By having those values in the Valid Expression field, the script will only accept those values in a record. Also, take off the comma after the last field definition.

One other thing (although it won't matter if you have made your own form), technically you're supposed to have a field length of 0 when you have an option field. Not a biggie, though.


------------------
JPD





Quote Reply
Re: Mortgage calculation In reply to
Many thanks! All is better now. Funny how the other select option fields were working with the double notation in the cfg file.

Have a nice weekend,

spike