Ejemplo n.º 1
0
        internal static double IntTimesPeriod(double intTimes, InterestPeriods iPeriods) // if interest is not accounted Annually.
        {
            switch (iPeriods)
            {
            case InterestPeriods.Daily:
                return(365 / intTimes);

            case InterestPeriods.Weekly:
                return(52 / intTimes);

            case InterestPeriods.Monthly:
                return(12 / intTimes);

            default:
                return(1);
            }
        }
Ejemplo n.º 2
0
            public static string Calculate(decimal interestRate, double intTimes, InterestPeriods iPeriods)
            {
                try
                {
                    decimal eir = (((decimal)Pow((double)(1 + (interestRate / 100) / (decimal)IntTimesPeriod(intTimes, iPeriods)), IntTimesPeriod(intTimes, iPeriods))) - 1) * 100;
                    eir = Round(eir, 2);

                    return($"Effective Interest Rate: {eir}%\n" +
                           "Used formula: [(1 + r%/m)^m-1] × 100\n" +
                           $"Solution: [(1 + {interestRate / 100}/{IntTimesPeriod(intTimes, iPeriods)})^{IntTimesPeriod(intTimes, iPeriods)}-1] × 100 = {eir}%");
                }
                catch (OverflowException)
                {
                    return("Impossible Calculation!");
                }
                catch (DivideByZeroException)
                {
                    return("Dividing by zero error!\n" +
                           "Please check your input.\n" +
                           "If your input is correct and you get this error, then your calculation is impossible.");
                }
            }
Ejemplo n.º 3
0
            public static string CDiscursiveInterest(decimal presentValue, decimal interestRate, double period, double intTimes, InterestPeriods iPeriods)     // if interest is not accounted Annually
            {
                try
                {
                    decimal futureValue = presentValue * (decimal)Pow((double)(1 + ((interestRate / 100) / (decimal)IntTimesPeriod(intTimes, iPeriods))), period * IntTimesPeriod(intTimes, iPeriods));
                    futureValue = Round(futureValue, 2);

                    return($"Future Value: {futureValue:C2}\n" +
                           "Used formula: FV = PV × (1 + r%/m)^(m × n)\n" +
                           $"Solution: {presentValue} × (1 + {interestRate / 100}/{IntTimesPeriod(intTimes, iPeriods)})^({period} × {IntTimesPeriod(intTimes, iPeriods)}) = {futureValue:0.00}");
                }
                catch (OverflowException)
                {
                    return("Impossible Calculation!");
                }
                catch (DivideByZeroException)
                {
                    return("Dividing by zero error!\n" +
                           "Please check your input.\n" +
                           "If your input is correct and you get this error, then your calculation is impossible.");
                }
            }