Ejemplo n.º 1
0
        public static void GetResults(decimal SumaKredytu, int StrokKredytu, decimal Stawka, bool IsSchemaClassic,
                                      out string Ammount, out string RealRate, out string EffectiveRate)
        {
            List <ProcStawka> ListStawok = new List <ProcStawka>();
            List <Schedule>   ResultList;
            ProcStawka        ps = new ProcStawka();

            ps.Stawka = Stawka; ps.Period = 1000;
            ListStawok.Add(ps);
            DateTime DataRozrahunku       = DateTime.Now; DataRozrahunku = DataRozrahunku.Subtract(DataRozrahunku.TimeOfDay);
            DateTime DataPo4atkuProc      = DataRozrahunku;
            DateTime DataPershogoPlatezhu = DataRozrahunku.AddDays((DataRozrahunku.AddMonths(1) - DataRozrahunku).TotalDays - DataRozrahunku.Day + 1);
            DateTime DataOplatyKredytu    = DataRozrahunku.AddMonths(StrokKredytu).AddDays(-1);

            if (IsSchemaClassic)
            {
                SchedulesClass.ReturnClassicSchedule(SumaKredytu, StrokKredytu, ListStawok, DataRozrahunku, DataPo4atkuProc, DataPershogoPlatezhu, DataOplatyKredytu,
                                                     out ResultList);
            }
            else
            {
                SchedulesClass.ReturnAnnuitySchedule(SumaKredytu, StrokKredytu, ListStawok, 0, DataRozrahunku, DataPo4atkuProc, DataPershogoPlatezhu, DataOplatyKredytu,
                                                     out ResultList);
            }

            Ammount       = MaskNumber.MaskDecimal(ResultList[1].Platizh);
            EffectiveRate = CalculateEffectiveRate(SumaKredytu, 0, DataRozrahunku, ResultList);
            decimal Procenty = 0;

            foreach (Schedule s in ResultList)
            {
                Procenty += s.Proc;
            }
            RealRate = MaskNumber.MaskDecimal(Math.Round(Procenty * 100 * 12 / (SumaKredytu * StrokKredytu), 2));
        }
Ejemplo n.º 2
0
        static string CalculateEffectiveRate(decimal SumaKredytu, decimal Wytraty, DateTime DataRozrahunku, List <Schedule> ResultList)
        {
            SumaKredytu = -1 * SumaKredytu + Wytraty;
            decimal         EffectiveRate = 0.15m;
            decimal         Step          = EffectiveRate;
            List <Schedule> AmountFlow    = new List <Schedule>();
            Schedule        s             = new Schedule();

            s.OplataDateTime = DataRozrahunku;
            s.Platizh        = SumaKredytu;
            AmountFlow.Add(s);
            AmountFlow.AddRange(ResultList);
            while (true)
            {
                decimal Drib = 0;
                for (int i = 0; i < AmountFlow.Count; i++)
                {
                    double dd      = (AmountFlow[i].OplataDateTime - DataRozrahunku).TotalDays;
                    double Platizh = (double)AmountFlow[i].Platizh;
                    double er      = (double)EffectiveRate;
                    Drib += (decimal)(Platizh / Math.Pow(1 + er, dd / 365));
                }
                //Drib = MyMath.Round(Drib, 2);
                if (MyMath.Round(Drib, 1) == 0)
                {
                    break;
                }
                else if (Drib > 0)
                {
                    EffectiveRate += Step;
                }
                else
                {
                    Step           = Step / 2;
                    EffectiveRate -= Step;
                }
            }
            return(MaskNumber.MaskDecimal(Math.Round(EffectiveRate * 100, 2)));
        }