Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating the Present Value

Present Value is the value on a given date of a future payment or series of future payments, discounted to reflect the time value of money and other factors such as investment risk. And yes, I know it's formula so don't need that.

But I am wondering if this method is already predefined within the .NET libraries. I can't find it. (And I guess .NET doesn't contain this function so I will just have to use my own function instead.)

I have no use for any nice third-party components or samples written in C#. I have to use some third-party scripting solution which allows any standard .NET library. I can add custom references to third-party libraries and even write my own add-on modules, but am trying to avoid this.

like image 742
Wim ten Brink Avatar asked Feb 12 '26 16:02

Wim ten Brink


1 Answers

You could use the Microsoft.VisualBasic library, but this doesn't seem like a very elegant solution to me. I wouldn't be surprised if it were deprecated in the future anyway.

A simple extension would be a nice solution:

public decimal PresentValue(this decimal value, decimal interestRate, 
    decimal years)
{
    return value / Math.Pow(1 + interestRate, years);
}

This is of course based off the simple definition of compound interest. There are variations on the present value which you could calculate similarly.

Note the use of the decimal type to preserve base 10 accuracy. It also allows a fractional time length by using Math.Pow.

like image 72
Noldorin Avatar answered Feb 15 '26 12:02

Noldorin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!