- Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathPresentValue.cs
28 lines (23 loc) · 761 Bytes
/
PresentValue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
namespaceAlgorithms.Financial;
/// <summary>
/// PresentValue is the value of an expected income stream determined as of the date of valuation.
/// </summary>
publicstaticclassPresentValue
{
publicstaticdoubleCalculate(doublediscountRate,List<double>cashFlows)
{
if(discountRate<0)
{
thrownewArgumentException("Discount rate cannot be negative");
}
if(cashFlows.Count==0)
{
thrownewArgumentException("Cash flows list cannot be empty");
}
doublepresentValue=cashFlows.Select((t,i)=>t/Math.Pow(1+discountRate,i)).Sum();
returnMath.Round(presentValue,2);
}
}