Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Finding NPV (net present value) with PHP

Posted on 2011-03-09
9
Medium Priority
?
1,330 Views
Last Modified: 2012-05-11
Hello Experts!

I need some help finding NPV from an array of reruns.

Let say i have an array containing 20 years of payments with array[0] being the capital outlay.

Array ( [0] => -29669.45 [1] => 84862.5 [2] => 84913.414741969 [3] => 84964.360031128 [4] => 85015.335885805 [5] => 85066.342324338 [6] => 85117.379365077 [7] => 85168.447026381 [8] => 85219.545326622 [9] => 85270.674284183 [10] => 85321.833917456 [11] => 85373.024244847 [12] => 85424.245284771 [13] => 85475.497055654 [14] => 85526.779575933 [15] => 85578.092864059 [16] => 85629.436938489 [17] => 85680.811817695 [18] => 85732.21752016 [19] => 85783.654064375 [20] => 85835.121468845 [21] => 354928.55 ) 

Open in new window


Now... let say i wanted to find the net present value in year 10 with a ROR or discount rate of 8.15%

How would I do that?

My current script:
function npv($rate, $values, $year) {
    for ($i=0;$i<=$year;$i+=1) {
        $npv = $values[$year - $i] + $npv / (1 + $rate);
    }
    return '$'.number_format($npv,2,'.',',');
}

echo npv(.0815, $paymentArray, 10);

Open in new window


Any Ideas would be awesome!
0
Comment
Question by:Cybervanes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 2

Author Comment

by:Cybervanes
ID: 35088104
I'm sorry this should have been worth 500 points...
0
 
LVL 2

Author Comment

by:Cybervanes
ID: 35093422
That was no help. Unless I'm missing somthing... Did you look at that page?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35097417
In your code is $rate 8.15 or .0815? It needs to be .0815; if it isn't use $rate/100.
Also, you should not be dividing by (1+$rate) you should multiply by (1-$rate).
If I understand the question correctly, that should be all you need to get it working right.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35097441
Scratch that second part. The division is fine. What is your code doing that you think it shouldn't?
0
 
LVL 2

Author Comment

by:Cybervanes
ID: 35098103
I'm noting getting the same figures that i do when using excel's internal NPV function.
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 2000 total points
ID: 35098298
Ah, I see it. The value that's 10 years old needs to be divided by the rate 10 times. Or (1+rate)^10
If you do this
$npv = ($values[$year - $i] + $npv) / (1 + $rate);
then it should work, since you are already running backward through the array.

By the way, I would do the for loop like this, but it either way is the same.
    for ($i=$year;$i>=0;$i-=1) {
        $npv = ($values[$i] + $npv) / (1 + $rate);
    }

Actually, if array[0] is the capital outlay, shouldn't you run through starting at 0 and going to $year?
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35098338
Er... That last line might not make sense. I don't know NPV that well, I'm just good at figuring formulas out. Doing it the way I suggested matched Excel perfectly.
0
 
LVL 2

Author Closing Comment

by:Cybervanes
ID: 35099178
Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

671 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question