in the above formula i have values called npv and c0,c1,c2,c3,c4 and then n values .could u please tell me how to calulate r value in c#
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Nov 1, 2013, 11:28 AM
It's not possible to solve the formula directly for 'r' so you have to use an iterative method which, starting from a guess, (hopefully) converges to an answer after a reasonable number of iterations.
Although there isn't a method to do this in the .NET framework's Math class, there is a method in VB.NET's Financial Module called IRR which is documented here:
http://msdn.microsoft.com/en-US/library/w8h9s5b4(v=vs.90).aspx
This method can be used from C# by first adding a reference to Microsoft.VisualBasic.dll to your project and then using code such as the following.
For convenience, I've used the results of my first post so we can work backwards to obtain r = 0.1. Notice that npv needs to included (negatively) as the first element of the array and also that the first cash flow (at time 0) needs to be added to this as it's paid in advance rather than at the end of the first year as IRR assumes:
As expected the output is:
Interest rate is 0.1 per unit p.a.
VulpesPosted Aug 19, 2014, 10:00 AM
So, if we take the first online calculator, if you put in the following:
Discount Rate 10%
Initial Invest Amount 0
Number of Years 3
Cash flows:
Year 1 = 2
Year 2 = 3
Year 3 = 4
then the net present value is 7.31.
However, you then need to add to this the first cash flow of 1 paid annually in advance (which therefore has a present value of 1) giving a total of 8.31 which is close to the 'exact' answer of 8.30277986476333 we obtained above.
Sumit KumawatPosted Aug 19, 2014, 1:25 AM
i gone through below link
http://msdn.microsoft.com/en-US/library/w8h9s5b4(v=vs.90).aspx
but when i calculate the NPV from some online NPV calculator with same values (given in the above link) the results are different.
below are link where i calculate the NPV
http://easycalculation.com/finance/net-present-value.php
http://www.datadynamica.com/irr.asp
VulpesPosted Aug 15, 2014, 5:35 AM
Admittedly, we're using the function IRR from the VB runtime library but there's nothing wrong with that - it's all .NET :)
Sumit KumawatPosted Aug 15, 2014, 1:45 AM
Thanx for sharing this link...
But i want this in C# so it will be good for me if u can give me code for calculating NPV in c#.
Thanx in advance :)
Sasi ReddyPosted Nov 2, 2013, 2:29 AM
That was working fine for me and thank you so much .The link was very useful for me
http://msdn.microsoft.com/en-US/library/w8h9s5b4(v=vs.90).aspx
VulpesPosted Nov 1, 2013, 10:28 AM
The output is:
Net present value is 8.30277986476333