Пример #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 Tan(decimal angle)
        {
            decimal denominator = DecimalMath.Cos(angle);

            if (denominator == 0.0M)
            {
                throw new ArgumentOutOfRangeException(nameof(angle), ErrorMessages.NonZero);
            }
            else
            {
                //tangent is just sine over cosine
                decimal numerator = DecimalMath.Sin(angle);
                return(numerator / denominator);
            }
        }
Пример #3
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));
        }
Пример #4
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);
            }
        }
Пример #5
0
 public static decimal Cos(decimal angle)
 {
     //cosine is just offset sine
     return(DecimalMath.Sin((DecimalMath.PI / 2.0M) - angle));
 }
Пример #6
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));
        }