Created
April 13, 2012 14:45
-
-
Save tylermorten/2377376 to your computer and use it in GitHub Desktop.
Calculate XNPV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace CalculateXNPV | |
{ | |
class Calculate | |
{ | |
IEnumerable<DateTime> dates; | |
IEnumerable<int> payments; | |
public Calculate(IEnumerable<DateTime> dates, IEnumerable<int> payments) | |
{ | |
this.dates = dates; | |
this.payments = payments; | |
} | |
public double CalcXnpv(int period, double rate) | |
{ | |
if (period == 0) | |
{ | |
return payments.ElementAt(0); | |
} | |
TimeSpan span = dates.ElementAt(period) - dates.ElementAt(0); | |
return CalcXnpv(period - 1, rate) + (payments.ElementAt(period) / Math.Pow((1 + (rate/365)), span.Days)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment