예제 #1
0
        public static decimal MonthlyPayment(decimal rate, int periods, decimal presentValue, decimal futureValue, PaymentType type)
        {
            if (rate == 0)
            {
                return((presentValue - futureValue) / periods);
            }

            decimal t = (int)type;

            return(((presentValue * DecimalMath.Pow(1 + rate, periods)) - futureValue) / ((1 + (rate * t)) * ((DecimalMath.Pow(1 + rate, periods) - 1) / rate)));
        }
예제 #2
0
        public static decimal PresentValue(decimal rate, int periods, int elapsedPeriods, decimal monthlyPayment, decimal futureValue, PaymentType type)
        {
            if (rate == 0)
            {
                return(futureValue + (monthlyPayment * (periods - elapsedPeriods)));
            }

            if (elapsedPeriods == periods)
            {
                return(futureValue);
            }

            decimal t = (int)type;

            return(((monthlyPayment * (1 + (rate * t)) * ((DecimalMath.Pow(1 + rate, periods - elapsedPeriods) - 1) / rate)) + futureValue) / DecimalMath.Pow(1 + rate, periods - elapsedPeriods));
        }
예제 #3
0
        public static decimal Rate(int periods, decimal presentValue, decimal futureValue, decimal monthlyPayment, PaymentType type)
        {
            decimal t     = (int)type;
            decimal N0    = periods;
            decimal guess = ((monthlyPayment * periods) - presentValue) / presentValue;

            try
            {
                return(NewtonRaphson.Iterate(
                           (decimal r0) => (((presentValue * DecimalMath.Pow(1M + r0, periods)) - futureValue) / ((1M + (r0 * t)) * ((DecimalMath.Pow(1M + r0, periods) - 1) / r0))) - monthlyPayment,
                           (decimal r0) => ((futureValue * ((N0 * r0 * r0 * t * DecimalMath.Pow(1M + r0, periods)) + (periods * r0 * DecimalMath.Pow(1M + r0, periods)) - (r0 * DecimalMath.Pow(1M + r0, periods)) - DecimalMath.Pow(1M + r0, periods) + r0 + 1)) + (presentValue * DecimalMath.Pow(1M + r0, periods) * ((-N0 * r0 * r0 * t) + DecimalMath.Pow(1M + r0, periods) + (r0 * (DecimalMath.Pow(1 + r0, periods) - periods - 1)) - 1))) / ((r0 + 1) * (DecimalMath.Pow(1 + r0, periods) - 1) * (DecimalMath.Pow(1 + r0, periods) - 1) * ((r0 * t) + 1) * ((r0 * t) + 1)),
                           guess));
            }
            catch (IterationsExceededException <decimal> exc)
            {
                return(exc.LastValue);
            }
        }
예제 #4
0
        public static decimal FutureValue(int periods, decimal presentValue, decimal rate, decimal monthlyPayment, PaymentType type)
        {
            decimal t = (int)type;

            return(Math.Round(-1 * (((1 + (rate * t)) * ((DecimalMath.Pow(1 + rate, periods) - 1) / rate) * monthlyPayment) - (presentValue * DecimalMath.Pow(1 + rate, periods))), 8));
        }