locked
Problem with -Financial.Pmt RRS feed

  • Question

  • So here is the problem I have a small program that the user inputs an amount say 100 dollars and then the user selects an interest rate and the number of years. The program is supposed to say how much the user must save each month to get to the 100 dollars. But my program does it wrong, it gives the values too high.

    I think I am using financial wrong.., But I'm not sure, the thing is I have to use financial for this. I figured out how to do most of it, its just this part that is giving me trouble.

    Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    'Populate combo box 1 thru 50 For term As Integer = 1 To 50 TermComboBox.Items.Add(term.ToString) Next term 'preselect item 1 TermComboBox.SelectedItem = "1" 'Populate combo box 0.02 to 0.11 at intervals of 0.01 For rate As Double = 0.02 To 0.11 Step 0.01 InterestComboBox.Items.Add(rate.ToString) Next rate 'preselect item 1 InterestComboBox.SelectedItem = "0.02" End Sub Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click 'clear output label OuputLabel.Text = String.Empty 'Calculate monthly payment on loan using interest rate 0.02 to 0.11 'Or user defined Dim term As Integer Dim goal As Double Dim rate As Double Dim savings As Double 'Populate variable Double.TryParse(GoalTextBox.Text, goal) term = Convert.ToInt32(TermComboBox.Text) rate = Convert.ToDouble(InterestComboBox.Text) 'Calculation savings = -Financial.Pmt(rate / 12, term * 12, goal) OuputLabel.Text = savings.ToString("C2") End Sub

    If I enter 100 dollars at interest of say 0.1 for one term it should say: 7.96

    but my program says: 8.79, which is WAY wrong. If anyone could help me it would be very appreciated. I've been stuck on this part for a while, keep in mind I'm fairly new so it might be a simple mistake that I can't see.

    Wednesday, October 24, 2012 10:25 PM

Answers

  • hi Markus

    besides the problem with the formula, if you want to have the first item selected in a ComboBox, use SelectedIndex instead of Item. That way if you ever change what is put in the combobox, it will always select the first item no matter what it is

    TermComboBox.SelectedIndex = 0

    @Shanks

    for a savings plan, isn't the PV supposed to be negative? In this case the formula would be:

    savings = -Financial.Pmt(rate / 12, term * 12, -(pv), goal)

    using the values from the OP, if you don't make the PV negative, a PV of 0 gives 7.96. Then try setting the PV to 50. This will give a savings = 12.35. If you are starting higher than 0, you should have to save less per month.

    Then if you change it to -(pv), the savings per month = 3.56.


    “This forum post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.”

    Saturday, October 27, 2012 5:32 AM

All replies

  • Hi Markus,

    Welcome to the MSDN forum.

    Based on this MSDN library of Financial.Pmt Method. To deposit money, we should set present value (PV As Double) as remainder, future value as the amount you expected (FV As Double). In this sample, you can set PV=0 and FV=100. 

    savings =
                -Financial.Pmt(rate / 12, term * 12, 0,goal)

    Hope this helps. I'm not in finance so if I misunderstood anything, please feel free to let me know.

    Best regards,


    Shanks Zen
    MSDN Community Support | Feedback to us


    Friday, October 26, 2012 7:27 AM
    Moderator
  • hi Markus

    besides the problem with the formula, if you want to have the first item selected in a ComboBox, use SelectedIndex instead of Item. That way if you ever change what is put in the combobox, it will always select the first item no matter what it is

    TermComboBox.SelectedIndex = 0

    @Shanks

    for a savings plan, isn't the PV supposed to be negative? In this case the formula would be:

    savings = -Financial.Pmt(rate / 12, term * 12, -(pv), goal)

    using the values from the OP, if you don't make the PV negative, a PV of 0 gives 7.96. Then try setting the PV to 50. This will give a savings = 12.35. If you are starting higher than 0, you should have to save less per month.

    Then if you change it to -(pv), the savings per month = 3.56.


    “This forum post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.”

    Saturday, October 27, 2012 5:32 AM
  • Thank you, sorry I didn't answer sooner, also your tip for the combo boxes has been a time saver for me.
    Monday, November 19, 2012 6:04 PM