예제 #1
0
        static void Main(string[] args)
        {
            var parameters = new CreditParameters
            {
                 CreditValue = 196879.95d,
                 InstallmentsCount = 48,
                 InstallmentsPerYear = 12,
                 WiborRate = 0.0164d,
                 Start = 0.075d,
                 End = 0.080d,
                 Delta = 0.0005d
            };

            var tasks = new List<Task>();
            for (var i = parameters.Start; i <= parameters.End; i += parameters.Delta)
            {
                var margin = i;
                tasks.Add(Task.Factory.StartNew(() =>
                    {
                        CalculateInstallmentValue(parameters, margin);
                    }));
            }

            Task.WaitAll(tasks.ToArray());

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
        }
예제 #2
0
 static void CalculateInstallmentValue(CreditParameters parameters, double m)
 {
     //Console.WriteLine(String.Format("Margin: {0:F4}", margin));
     var q = 1.0d + (parameters.WiborRate + m) / parameters.InstallmentsPerYear;
     var w1 = Math.Pow(q, parameters.InstallmentsCount);
     var w2 = Math.Pow(q, parameters.InstallmentsCount) - 1.0d;
     var r = parameters.CreditValue * w1 * (q - 1) / w2;
     Console.WriteLine(String.Format("m:{0,-10:F6}q:{1,-10:F6}r:{2,-10:F6}", m, q, r));
 }
        public static CreditResult DoCalculation(CreditParameters creditParameters)
        {
            var q = 1.0d + creditParameters.TotalLoanRate / (double)creditParameters.InstallmentsPerYear;
            var qPowN = Math.Pow(q, creditParameters.InstallmentsCount);
            var singleRate = creditParameters.CreditValue * qPowN * (q - 1) / (qPowN - 1);

            return new CreditResult
            {
                InstallmentValue = singleRate,
                TotalCredit = creditParameters.InstallmentsCount * singleRate,
            };
        }
        public static void DoSimulationWithFixedInstallmentValue(CreditParameters creditParameters, Action<int, double, double, double, double, double> displayAction)
        {
            var multiplier = creditParameters.LoanRate / creditParameters.InstallmentsPerYear;
            var remainingCapital = creditParameters.CreditValue;
            var installmentValue = creditParameters.InstallmentValue;

            var counter = 0;
            do
            {
                var interest = multiplier * remainingCapital;
                var capitalPart = installmentValue - interest;
                displayAction(++counter, installmentValue, interest, capitalPart, remainingCapital, remainingCapital -= capitalPart);
            }
            while (installmentValue <= remainingCapital);

            displayAction(++counter, remainingCapital, 0.0d, 0.0d, remainingCapital, 0.0d);
        }
예제 #5
0
        //static void Main(string[] args)
        //{
        //    ConsoleKeyInfo key;
        //    do
        //    {
        //        try
        //        {
        //            string line = string.Empty;
        //            Console.Write("Credit value: ");
        //            var creditParameters = new CreditParameters
        //            {
        //                CreditValue = Double.Parse(Console.ReadLine()),
        //            };

        //            Console.Write("Total installments: ");
        //            creditParameters.InstallmentsCount = Int32.Parse(Console.ReadLine());

        //            Console.Write("Installments per year: ");
        //            creditParameters.InstallmentsPerYear = Int32.Parse(Console.ReadLine());

        //            Console.Write("Loan rate (e.g. 5% = 0.05):");
        //            creditParameters.LoanRate = Double.Parse(Console.ReadLine());

        //            var res = KLSystems.Finances.Commons.CreditCalculator.DoCalculation(creditParameters);
        //            Console.WriteLine(String.Format("Installment value: {0:F4}", res.InstallmentValue));
        //            Console.WriteLine(String.Format("Total credit value: {0:F4}", res.TotalCredit));
        //        }
        //        catch(Exception excep)
        //        {
        //            Console.WriteLine(excep.Message);
        //        }

        //        Console.WriteLine("Do you want to continue ? ('Y' or 'y')");
        //        key = Console.ReadKey();
        //    }
        //    while (Char.ToUpper(key.KeyChar) == 'Y');
        //}

        static void Main(string[] args)
        {
            ConsoleKeyInfo key;
            do
            {
                try
                {
                    string line = string.Empty;
                    Console.Write("Credit value: ");
                    var creditParameters = new CreditParameters
                    {
                        CreditValue = Double.Parse(Console.ReadLine()),
                    };

                    Console.Write("Installments per year: ");
                    creditParameters.InstallmentsPerYear = Int32.Parse(Console.ReadLine());

                    Console.Write("Loan rate (e.g. 5% = 0.05): ");
                    creditParameters.LoanRate = Double.Parse(Console.ReadLine());

                    Console.Write("Fixed installment value: ");
                    creditParameters.InstallmentValue = Double.Parse(Console.ReadLine());


                    Commons.CreditCalculator.DoSimulationWithFixedInstallmentValue(creditParameters, DisplaySimulationRow);
                }
                catch (Exception excep)
                {
                    Console.WriteLine(excep.Message);
                }

                Console.WriteLine("Do you want to continue ? ('Y' or 'y')");
                key = Console.ReadKey();
            }
            while (Char.ToUpper(key.KeyChar) == 'Y');
        }