Ejemplo n.º 1
0
        public void TestAmortization()
        {
            double result = AmortizationSchedule.getInstance().calculateMonthlyPayment(360, 4.5f, 200000.0f);

            Console.WriteLine("Monthly payment = {0}", result);

            AmortizationSchedule.getInstance().getSchedule(360, 4.5, 200000.0);

            Console.WriteLine("Principle for 1058.42, at 4.5% over 30 years = {0}", AmortizationSchedule.getInstance().calculatePrinciple(360, 4.875, 1058.42));

            Console.WriteLine("APR for 1058.42, for 200,0000 over 30 years = {0}", AmortizationSchedule.getInstance().calculateAPR(360, 200000, 1058.42));

            Loan loan = new Loan("House Loan", new DateTime(2011, 6, 29), 4.5, 2000000.0, 360.0);

            LoanPayment payment = new LoanPayment(1500.0, 1100.0, 400.0, 0.0);

            loan.addPayment(payment);

            Profile profile = new Profile("Brian");
            profile.addLoan(loan);

            // Create a new XmlSerializer instance with the type of the test class
            XmlSerializer SerializerObj = new XmlSerializer(typeof(Profile));

            // Create a new file stream to write the serialized object to a file
            TextWriter WriteFileStream = new StreamWriter("./test.xml");
            SerializerObj.Serialize(WriteFileStream, profile);

            //TextReader ReadStream = new StreamReader("./test.xml");
            //Loan loan2 = (Loan)SerializerObj.Deserialize(ReadStream);

            //Console.WriteLine("Loan apr = {0}", loan.APR);

            //AmortizationPayment p = (AmortizationPayment)loan.PaymentHistory[0];

            //Console.WriteLine("Payment Interest = {0}", p.InterestPaid);

            // Cleanup
            WriteFileStream.Close();
            //ReadStream.Close();
        }
        public ArrayList getSchedule(int months, double yearlyAPR, double principle)
        {
            ArrayList list = new ArrayList();

            double monthlyPayment = calculateMonthlyPayment(months, yearlyAPR, principle);
            double remainingPrinciple = principle;
            double monthlyRate = getMonthlyInterestRate(yearlyAPR);

            for (int i = 0; i < months; i++)
            {
                //Round to the nearest penny
                double interestPaid = monthlyRate * remainingPrinciple;
                interestPaid = (double)roundToNearestPenny((double)interestPaid);

                //Remainder of the payment is principle
                double principlePaid = monthlyPayment - interestPaid;

                //Any extra paid on top of the monthly payment
                double extraPaid = 0;

                //Create a payment with these values
                LoanPayment payment = new LoanPayment(monthlyPayment+extraPaid, interestPaid, principlePaid, extraPaid);

                //Add the payment to the list
                list.Add(payment);

                //Adjust the remaining principle on the loan
                remainingPrinciple -= principlePaid;
            }

            remainingPrinciple = roundToNearestPenny(remainingPrinciple);

            //Tack on the remainder on the last payment
            LoanPayment lastPayment = (LoanPayment)list[months - 1];
            lastPayment.TotalPayment += remainingPrinciple;
            lastPayment.PrinciplePaid += remainingPrinciple;

            double principleSum = 0;
            int num = 0;
            /*
            foreach (LoanPayment payment in list)
            {
                num++;
                Console.WriteLine("{0}: {1}", num, payment);
                principleSum += payment.PrinciplePaid;
            }*/

            for (int i = 0; i < 100; i++)
            {
                LoanPayment payment = (LoanPayment)list[i];
                Console.WriteLine("{0}: {1}", num, payment);
            }

            Console.WriteLine("Principle to be paid = {0}", principle);

            Console.WriteLine("Remaining Principle = {0}", remainingPrinciple);

            Console.WriteLine("Total principle paid = {0}", principleSum);

            return list;
        }
Ejemplo n.º 3
0
        public void addPayment(LoanPayment payment)
        {
            if (payment != null)
            {
                _paymentHistory.Add(payment);
            }

            updateTotals();
        }