Ejemplo n.º 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)));
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
 public static decimal Cos(decimal angle)
 {
     //cosine is just offset sine
     return(DecimalMath.Sin((DecimalMath.PI / 2.0M) - angle));
 }