Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB Expert!

Join 244,306 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 790 people online right now. Registration is fast and FREE... Join Now!




Pricipal Interest part of Loan Calculator PMT method not computing cor

 
Reply to this topicStart new topic

Pricipal Interest part of Loan Calculator PMT method not computing cor

Zuelin
24 Dec, 2008 - 01:29 PM
Post #1

New D.I.C Head
*

Joined: 24 Dec, 2008
Posts: 5


My Contributions
CODE
Option Strict Off
Option Explicit On


Public Class frmMain
    'declaring the  module-level variables
    Private mdblDownPaymentTotal, mdblClosingCostTotal, mdblCashtoCloseTotal, mdblPrincipalInterestTotal, mdblPropertytaxesTotal, _
         mdblInsuranceTotal, mdblMonthlyPaymentTotal, mdblperiod As Double

    Private mdblPurchasePrice, mdblInterestRate As Double


    Private Sub btnCalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

        'accept the purchase price input
        mdblPurchasePrice = System.Convert.ToDouble(txtPurchasePrice.Text)
        txtPurchasePrice.Text = mdblPurchasePrice.ToString("c")

        'accept the Interest rate input, send to mdblinterestrate as #.## while display full number
        mdblInterestRate = System.Convert.ToDouble(txtInterestRate.Text / 100)
        txtInterestRate.Text = mdblInterestRate * 100.ToString("##")

        'determines the downpayment
        mdblDownPaymentTotal = (mdblPurchasePrice * 0.2)
        lblDownPaymentTotal.Text = mdblDownPaymentTotal.ToString("c")

        ''determines the closing cost
        mdblClosingCostTotal = (mdblPurchasePrice * 0.025)
        lblClosingCostTotal.Text = mdblClosingCostTotal.ToString("c")

        ' determines cash to close
        mdblCashtoCloseTotal = (mdblClosingCostTotal + mdblDownPaymentTotal)
        lblCashtoCloseTotal.Text = mdblCashtoCloseTotal.ToString("c")

        'determine the  principal and interest

        mdblperiod = 360

        'mdblPrincipalInterestTotal = Financial.Pmt(0.07, 360, 1000, 0)
        mdblPrincipalInterestTotal = Financial.Pmt(mdblInterestRate, mdblperiod, mdblPurchasePrice, 0)
        mdblPrincipalInterestTotal = System.Math.Abs(mdblPrincipalInterestTotal)
        lblPrincipalInterestTotal.Text = mdblPrincipalInterestTotal.ToString("c")

        'determine property taxes
        mdblPropertytaxesTotal = ((mdblPurchasePrice * 0.025) / 12)
        lblPropertyTaxesTotal.Text = mdblPropertytaxesTotal.ToString("c")

        'determine insurance
        mdblInsuranceTotal = ((mdblPurchasePrice * 0.008) / 12)
        lblInsuranceTotal.Text = mdblInsuranceTotal.ToString("c")

        'determine monthly payment
        mdblMonthlyPaymentTotal = mdblPrincipalInterestTotal + mdblPropertytaxesTotal + mdblInsuranceTotal
        lblMonthlyPaymentTotal.Text = mdblMonthlyPaymentTotal.ToString("c")


    End Sub


    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'Close the Application

        Me.Close()


    End Sub

    Private Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        'Clears the labels and input boxes and puts focus back on purchase price box

        txtPurchasePrice.Focus()
        txtPurchasePrice.Text = ""
        txtInterestRate.Text = ""

        lblDownPaymentTotal.Text = ""
        lblClosingCostTotal.Text = ""
        lblCashtoCloseTotal.Text = ""
        lblPrincipalInterestTotal.Text = ""
        lblPropertyTaxesTotal.Text = ""
        lblInsuranceTotal.Text = ""
        lblMonthlyPaymentTotal.Text = ""

    End Sub
End Class


Ok, the problem that I'm having is this:

When I enter $1000 for PurchasePrice and 7% for Interest rate the PrincipalInterest returns $70.00 instead of the correct answer which is $466.67

Am I missing something but I thought the PMT function was supposed to take care of all the computations.

I've tried both formats:

Literal: PMT(.07, 360, 1000, 0)
and
Variable mdblPrincipalInterestTotal = Financial.Pmt(mdblInterestRate, mdblperiod, mdblPurchasePrice, 0)
and neither one is returning the correct value.

I'm using VB .NET 2005.

Thanks,
Zuelin

User is offlineProfile CardPM
+Quote Post


n8wxs
RE: Pricipal Interest Part Of Loan Calculator PMT Method Not Computing Cor
24 Dec, 2008 - 05:52 PM
Post #2

--... ...-- -.. . -. ---.. .-- -..- ...
Group Icon

Joined: 6 Jan, 2008
Posts: 1,609



Thanked: 223 times
My Contributions
$70 is the correct answer for your values. Borrowing $1000 for 30 years at 7% per month yields a total note of $25,200 of which $24,200 is interest!

The 7% value you are using is the per-month interest rate, not the annual rate - APR. Divide the 7% by 12 to get the monthly rate. Which gives a $6.65 monthly payment for 30 years. The note is now $2,394.

The principal must be close to $70,000 for the monthly payment to be $466.67. ($70, 000 for 30 years at 7% yields a payment of $465.71 (rounded down))

See

How To Calculate Mortgage Payments

This post has been edited by n8wxs: 24 Dec, 2008 - 07:37 PM
User is offlineProfile CardPM
+Quote Post

acory
RE: Pricipal Interest Part Of Loan Calculator PMT Method Not Computing Cor
25 Dec, 2008 - 09:34 AM
Post #3

New D.I.C Head
*

Joined: 22 Dec, 2008
Posts: 10

I've haven't messed around with financial functions yet but did you try playing with a blend of IPmt + PPmt (interst + principal) to see if it gave you a diiferent answer? Seems like it would be a quick/easy test of any function that claims to blend the two answers, and if it works (this manual blending) you can perhaps Labda Express or create Function that does the combine, if using the expression becomes tedious...just a thought from a real newbie.
User is offlineProfile CardPM
+Quote Post

Zuelin
RE: Pricipal Interest Part Of Loan Calculator PMT Method Not Computing Cor
25 Dec, 2008 - 02:27 PM
Post #4

New D.I.C Head
*

Joined: 24 Dec, 2008
Posts: 5


My Contributions
QUOTE(n8wxs @ 24 Dec, 2008 - 05:52 PM) *

$70 is the correct answer for your values. Borrowing $1000 for 30 years at 7% per month yields a total note of $25,200 of which $24,200 is interest!

The 7% value you are using is the per-month interest rate, not the annual rate - APR. Divide the 7% by 12 to get the monthly rate. Which gives a $6.65 monthly payment for 30 years. The note is now $2,394.

The principal must be close to $70,000 for the monthly payment to be $466.67. ($70, 000 for 30 years at 7% yields a payment of $465.71 (rounded down))

See

How To Calculate Mortgage Payments


Thanks, but I'm still not understanding something. In this lesson I'm working on they provided a working Loan Calculator that when i enter 1000 for Purchase Price and 7% interest the Principal and Interest box reads : $466.67. So, if my 70.00 is correct for the amounts I'm entering then how do I get that Principal and Interest box to read $466.67 when i hit calculate.

Thanks.

User is offlineProfile CardPM
+Quote Post

n8wxs
RE: Pricipal Interest Part Of Loan Calculator PMT Method Not Computing Cor
25 Dec, 2008 - 04:13 PM
Post #5

--... ...-- -.. . -. ---.. .-- -..- ...
Group Icon

Joined: 6 Jan, 2008
Posts: 1,609



Thanked: 223 times
My Contributions
I dunno what the loan calculator you are provided with is doing. smile.gif

For the function you are using see

Financial.Pmt Method
User is offlineProfile CardPM
+Quote Post

Zuelin
RE: Pricipal Interest Part Of Loan Calculator PMT Method Not Computing Cor
27 Dec, 2008 - 09:42 AM
Post #6

New D.I.C Head
*

Joined: 24 Dec, 2008
Posts: 5


My Contributions
QUOTE(n8wxs @ 25 Dec, 2008 - 04:13 PM) *

I dunno what the loan calculator you are provided with is doing. smile.gif

For the function you are using see

Financial.Pmt Method


Thanks for all your help so far. After reviewing the Loan Calculator and the lesson notes, it would appear that specific directions on how to enter the data were not clear which was throwing off my calculations. I have now completely changed my coding and I've gotten my results to pretty much come inline with the Loan calculator that was provided.

I'm still having one problem, as you can see in the picture (link below), My Loan Calculator is on the LEFT and the one that was provided with the course is on the RIGHT.

http://www.zuelin.com/Pictures/LoanCalc.jpg

Notice that my Principal and Interest box results do not match the one provided, which is utimately throwing the reults off in the monthly payment box. Now, I would like to believe that my coding is correct but I'm just unsure.
I have included the new coding schema that I'm using. Again, thanks for all your help.

CODE


Public Class frmMain
    'declaring the  module-level variables
    Private msngDownPaymentTotal As Single
    Private msngClosingCostTotal As Single
    Private msngCashtoCloseTotal As Single
    Private msngPrincipalInterestTotal As Single
    Private msngPropertytaxesTotal As Single
    Private msngInsuranceTotal As Single
    Private msngMonthlyPaymentTotal As Single
    Private msngPurchasePrice As Single
    Private msnginterestrate As Single


    Private msngPrincipal As Single
    Private mshoNumberPeriod As Short

    Private Sub btnCalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

        'Figures Interest Rate
        msnginterestrate = System.Convert.ToSingle(txtInterestRate.Text) / 12 / 100

        'receives input of purchase price
        msngPurchasePrice = System.Convert.ToSingle(txtPurchasePrice.Text)

        'sets the Period of loan
        mshoNumberPeriod = System.Convert.ToInt32(30 * 12)

        'figures out the Interest
        msngPrincipalInterestTotal = System.Convert.ToSingle(Pmt(msnginterestrate, mshoNumberPeriod, msngPurchasePrice))

        'Changes the final number to a positive
        msngPrincipalInterestTotal = System.Math.Abs(msngPrincipalInterestTotal)

        'Figures out the principal
        msngPrincipal = msngPurchasePrice / mshoNumberPeriod

        'display Principal and Interest
        lblPrincipalInterestTotal.Text = (msngPrincipalInterestTotal + msngPrincipal).ToString("c")



        'determines the downpayment
        msngDownPaymentTotal = (msngPurchasePrice * 0.2)
        lblDownPaymentTotal.Text = msngDownPaymentTotal.ToString("c")

        ''determines the closing cost
        msngClosingCostTotal = (msngPurchasePrice * 0.025)
        lblClosingCostTotal.Text = msngClosingCostTotal.ToString("c")

        ' determines cash to close
        msngCashtoCloseTotal = (msngClosingCostTotal + msngDownPaymentTotal)
        lblCashtoCloseTotal.Text = msngCashtoCloseTotal.ToString("c")



        'determine property taxes
        msngPropertytaxesTotal = ((msngPurchasePrice * 0.025) / 12)
        lblPropertyTaxesTotal.Text = msngPropertytaxesTotal.ToString("c")

        'determine insurance
        msngInsuranceTotal = ((msngPurchasePrice * 0.008) / 12)
        lblInsuranceTotal.Text = msngInsuranceTotal.ToString("c")

        'determine monthly payment
        'msngprincipalinterest = System.Convert.ToSingle(lblPrincipalInterestTotal.Text)
        lblMonthlyPaymentTotal.Text = (msngPrincipalInterestTotal + msngPrincipal + msngPropertytaxesTotal + msngInsuranceTotal + msnginterestrate).ToString("c")



    End Sub


    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'Close the Application

        Me.Close()


    End Sub

    Private Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        'Clears the labels and input boxes and puts focus back on purchase price box

        txtPurchasePrice.Focus()
        txtPurchasePrice.Text = ""
        txtInterestRate.Text = ""

        lblDownPaymentTotal.Text = ""
        lblClosingCostTotal.Text = ""
        lblCashtoCloseTotal.Text = ""
        lblPrincipalInterestTotal.Text = ""
        lblPropertyTaxesTotal.Text = ""
        lblInsuranceTotal.Text = ""
        lblMonthlyPaymentTotal.Text = ""

    End Sub
End Class


User is offlineProfile CardPM
+Quote Post

n8wxs
RE: Pricipal Interest Part Of Loan Calculator PMT Method Not Computing Cor
28 Dec, 2008 - 02:45 PM
Post #7

--... ...-- -.. . -. ---.. .-- -..- ...
Group Icon

Joined: 6 Jan, 2008
Posts: 1,609



Thanked: 223 times
My Contributions
Comments are in the code
CODE

//  'declaring the  module-level variables
    Private msngDownPaymentTotal As Single
    Private msngClosingCostTotal As Single
    Private msngCashtoCloseTotal As Single
    Private msngPrincipalInterestTotal As Single
    Private msngPropertytaxesTotal As Single
    Private msngInsuranceTotal As Single
    Private msngMonthlyPaymentTotal As Single
    Private msngPurchasePrice As Single
    Private msnginterestrate As Single

    Private msngPrincipal As Single
    Private mshoNumberPeriod As Short

////////////////////////////////////////////
// The mortgage is calculated on the amount financed, not the purchase price
    Private amountFinanced As Single

    Private Sub btnCalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

//     'Figures Interest Rate
        msnginterestrate = System.Convert.ToSingle(txtInterestRate.Text) / 12 / 100

//      'receives input of purchase price
        msngPurchasePrice = System.Convert.ToSingle(txtPurchasePrice.Text)

///////// moved downpayment here //////////////////////
//      'determines the downpayment
        msngDownPaymentTotal = (msngPurchasePrice * 0.2)
        lblDownPaymentTotal.Text = msngDownPaymentTotal.ToString("c")

//////////////////////////////////////////////////////
//      'adjust purchase price for downpayment
        amountFinanced = msngPurchasePrice - msngDownPaymentTotal

//      'sets the Period of loan
        mshoNumberPeriod = System.Convert.ToInt32(30 * 12)

/////////////////////////////////// uses amountFinanced
//      'figures out the Interest
        msngPrincipalInterestTotal = System.Convert.ToSingle(Pmt(msnginterestrate, mshoNumberPeriod, amountFinanced))

//      'Changes the final number to a positive
        msngPrincipalInterestTotal = System.Math.Abs(msngPrincipalInterestTotal)

/////////////////////// unused
//      'Figures out the principal
//      msngPrincipal = msngPurchasePrice / mshoNumberPeriod

//      'display Principal and Interest
//      'lblPrincipalInterestTotal.Text = (msngPrincipalInterestTotal + msngPrincipal).ToString("c")
        lblPrincipalInterestTotal.Text = msngPrincipalInterestTotal.ToString("c")

//      'determines the closing cost
        msngClosingCostTotal = (msngPurchasePrice * 0.025)
        lblClosingCostTotal.Text = msngClosingCostTotal.ToString("c")

//      ' determines cash to close
        msngCashtoCloseTotal = (msngClosingCostTotal + msngDownPaymentTotal)
        lblCashtoCloseTotal.Text = msngCashtoCloseTotal.ToString("c")

//      'determine property taxes
        msngPropertytaxesTotal = ((msngPurchasePrice * 0.025) / 12)
        lblPropertyTaxesTotal.Text = msngPropertytaxesTotal.ToString("c")

//      'determine insurance
        msngInsuranceTotal = ((msngPurchasePrice * 0.008) / 12)
        lblInsuranceTotal.Text = msngInsuranceTotal.ToString("c")

//      'determine monthly payment
//      'msngprincipalinterest = System.Convert.ToSingle(lblPrincipalInterestTotal.Text)

/////////////////// This next line is wrong - the interest rate is not part of the monthly payment
/////////////////// neither is the monthly principle
/////   lblMonthlyPaymentTotal.Text = (msngPrincipalInterestTotal + msngPrincipal + msngPropertytaxesTotal + msngInsuranceTotal + msnginterestrate).ToString("c")

     lblMonthlyPaymentTotal.Text = (msngPrincipalInterestTotal + msngPropertytaxesTotal + msngInsuranceTotal).ToString("c")

    End Sub
...


This post has been edited by n8wxs: 28 Dec, 2008 - 04:29 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 06:31PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month