Computing.Net > Forums > Programming > Financial formula

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Financial formula

Reply to Message Icon

Name: browser
Date: March 18, 2005 at 07:46:56 Pacific
OS: XP
CPU/Ram: Pentium 64MB
Comment:

Hello,

I have a question about a procedure I wrote for a financial planning tool I'm working on in Visual Basic 6.0 (DAO). I set up text boxes to accept the following inputs:

1) Retirement Goal - retgoal (single)
2) Years to Retirement - yrsret (integer)
3) Annual Interest Rate - annrate (integer)
4) Initial Deposit - cav (single)
5) Contribution Years - yrscont (the number of years an annual contibution will be made consecutively starting in year 1, same amount each year - integer)

I then created a formula to calculate the Annual Deposit (dp - single) that one would have to make yearly in order to attain the retirement goal based on the years to retirement, annual interest rate, initial deposit and the number of years a contribution will be made.

this part of my code looks like this:


retgoal = Text1.Text
yrsret = Text2.Text
annrate = Text3.Text
cav = Text4.Text
yrscont = Text5.Text


For dp = 1 To 50000 Step 0.1

For b = 2 To yrscont

For c = yrscont + 1 To yrsret

bal(1) = (cav + dp) * annrate / 100 + (cav + dp) ' the balance in the first year

bal(b) = (bal(b - 1) + dp) * annrate / 100 + bal(b - 1) + dp ' the balance of years 2 to the number of years contributions are made

bal(c) = bal(c - 1) * annrate / 100 + bal(c - 1) ' the balance for the years starting when no more annual contibutions are made

Next c

Next b


If retgoal - bal(yrsret) < Abs(1) Then ' after going through the nested loops, if the difference between the retirement goal and the balance at years to retirement is less than 1 then exit for.

Label19.Caption = Format(bal(yrsret), "#,###,###,###") ' this will show the balance at "years to retirement"

Exit For

End If

Next dp


Text6.Text = dp ' this will show the annual deposit amount


End If

After this, I created code to display the balances for each year untill retirement. My procedure works fine up to a value of 10,000,000 for the retirement goal. When I try to input higher values, I get rather rediculous results for dp (annual deposit amount).

My question is; can anyone provide a better formula (or procedure) to achieve what I am trying to accomplish. I hope I explained what it is I am trying to do in a clear manner, but if not, please let me know. I used these values as a control:

retgoal = $10,000,000
yrsret = 20
annrate = 15%
cav = $600,000
yrscont = 16

Any help would be greatly appreciated. Thanks

Janny



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: March 18, 2005 at 08:45:09 Pacific
Reply:

Don't understand why all the nested loops. There are financial functions built into VB that will do all the dirty work for you.

Look up FV = Future Value

and

PV = Present Value

and

NPV = Net Present Value

Plus loads of other to do with calculating annuities. All you have to do is provide the parameters and format the output. Basically, if the function exits in Excel, it also exists in VB.

All these functions use Double data types which may be where your problem lies.

Stuart


0

Response Number 2
Name: browser
Date: March 18, 2005 at 09:21:57 Pacific
Reply:

Hi Stuart,

You are so right! I can't believe I didn't think of just using built in functions. I used to teach Excel and I know it fairly well. Just think of the time I could have saved. Thanks

browser


0

Response Number 3
Name: wizard-fred
Date: March 18, 2005 at 10:10:47 Pacific
Reply:

Your numeric precision could be higher.

Actually your payment schedule should not be
nested. You do 'b' loop then 'c' loop, your 'c' is within 'b'.
It is awkward to estimate 'dp' by step increment. With your .1 step it would take almost 19000 iterations. A binary or other approximation method would result in faster convergence. Less than 25 tries to $.10

The problem is easier solved in Excel or some other spreadsheet using financial functions.

Your assumptions are extremely agressive. $600,000 compounded at 15% at the end of 20 years is more than $9,800,000. Which leaves an approximate annual payment of $1885 for 16 years. These numbers are guestimates. Since I calculated by parts.


0

Response Number 4
Name: browser
Date: March 19, 2005 at 04:38:12 Pacific
Reply:

Hi Stuart,

With regards to the financial functions, can any of them be used for the following scenerio:

Mr. X will retire in 20 years. At retirement, he wants to have $10,000,000. He makes an initial deposit of $600,000. He wants to make an annaul contribution for 16 consecutive years starting at year 1. The interest rate is 15%. I tried using the PMT and PPMT functions to calculate the annual deposit amount in order to attain his retirement goal, but I think I am a little rusty on it. Can you offer any suggestions? Thanks a lot.

Browser


0

Response Number 5
Name: browser
Date: March 19, 2005 at 04:40:58 Pacific
Reply:

Thanks for your input wizard-fred.
browser


0

Related Posts

See More



Response Number 6
Name: StuartS
Date: March 19, 2005 at 07:33:29 Pacific
Reply:

I don't think there is a specific function to calculate the payments required as you describe. The PMT function is used to calculate how much you would have to pay back on a specific loan.

The way I did it was to use the PV function inside a loop starting of with an assumed monthly payment.

RateGrowth = 15%
payment = 600,000

For a = 1 to 16
sum = PV(RateGrowth, a, -Payment)
next
For a = 17 to 20
sum = PV(RateGrowth, a, 0)
next

You can then do the same using NPV which calculates the future value of the investments based on a particular rate of inflation. $10,000,000 today will not be worth the same as $10,000,000 in twenty years time.

Put the sums into a grid then use a slider of some other method at adjust the payments and interest rates until you achieve the goal required.

Notice that payments are a negative value. Positive values are used when calculating return on investments.

Bear in mind that I am a programmer, not a Finical Adviser. I did this some time ago with the assistance of a Financial Adviser who knew nothing about computers.

Stuart


0

Response Number 7
Name: wizard-fred
Date: March 19, 2005 at 11:33:30 Pacific
Reply:

My approach would be this way.

You have $600,000 at 15% interest compounded annually for 20 years which yields about $9,819,922. =600000*(1+.15)^20

Your goal is $10,000,000, which leaves a shortfall of $180,078 which is the amount of the annual investment has to grow to in the four years of non-contribution (year 17 to 20) = 180,078/(1+.15)^4 = 102,960

You need 16 annual payments + interest to equal 102,960.
=pmt(rate,nper,pv,fv,type) = -1,606.86
rate = .15
nper (periods) = 16
pv (present value) = 0
fv (future value) = 102,960
type = 1 (pmt in advance)

Calculated in Pocket Excel



0

Response Number 8
Name: browser
Date: March 19, 2005 at 22:32:02 Pacific
Reply:

Thanks guys. Everything is ok now.

browser


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Financial formula

Peachtree Formula Issue www.computing.net/answers/programming/peachtree-formula-issue/4703.html

C Program Formula www.computing.net/answers/programming/c-program-formula/9392.html

Excel formula autoupdate www.computing.net/answers/programming/excel-formula-autoupdate/2538.html