def main():
    a = Asset(1000)
    normal_loan = Loan(12, 0.3, 1000, a)
    memoizable_loan = MemoizedLoan(12, 0.3, 1000, a)

    print "First normal loan time cost:"
    normal_loan.interestDue(10)
    print "Second normal loan time cost:"
    normal_loan.interestDue(10)

    print "First memoizable loan time cost:"
    memoizable_loan.interestDue(10)
    print "Second memoizable loan time cost:"
    memoizable_loan.interestDue(10)
Beispiel #2
0
def main():


    print ('========== Exersize 2.1.4 ==========\n')

    print('Testing Loan classmethod for monthly payment : {}'.format(Loan.calcMonthlyPmt(100000, .025, 360)))
    print('Testing Loan classmethod for balance: {}'.format(Loan.calcBal(100000, .025, 360, 60)))

    myLoan = Loan(360,.025,100000)
    print("Monthly Payment: {}".format(myLoan.monthlyPayment()))
    print("Balance after 60 periods: {}".format(myLoan.balance(60)))
    print("Interest due on period 60: {}".format(myLoan.interestDue(60)))
    print("Principal due on period 60: {}".format(myLoan.principlaDue(60)))

    print("The total payment should equal interest plus principal which is {}".format(myLoan.interestDue(5) + myLoan.principlaDue(5)))
    print("Total Interest paid is {}".format(myLoan.totalInterest()))
    print("Total Payment is {}".format(myLoan.totalPayments()))
    print("Total Interest paid is {}".format(myLoan.totalInterest()))

    """
    The benefit of the cls level method is that it allows us to compute a payment or balance with out initiating an object
    """

    print("Old rate {}".format(myLoan.rate))
    print("Old term {}".format(myLoan.term))
    print("Old face {}".format(myLoan.face))

    myLoan.rate = .035
    myLoan.term = 60
    myLoan.face = 20000

    print("New rate {}".format(myLoan.rate))
    print("New term {}".format(myLoan.term))
    print("New face {}".format(myLoan.face))
Beispiel #3
0
def main():

    print('========== Exercise 2.1.2 ==========')
    myLoan = Loan(360, .025, 100000)
    print("Monthly Payment: {}".format(myLoan.monthlyPayment()))
    print("Balance after 360 periods: {}".format(myLoan.balance(360)))
    print("Interest due on period 360: {}".format(myLoan.interestDue(360)))
    print("Principal due on period 360: {}".format(myLoan.principlaDue(360)))
    print("The total payment should equal interest plus principal which is {}".
          format(myLoan.interestDue(5) + myLoan.principlaDue(5)))
    print("Total Interest paid is {}".format(myLoan.totalInterest()))
    print("Total Payment is {}".format(myLoan.totalPayments()))

    print("Old rate {}".format(myLoan.rate))
    print("Old term {}".format(myLoan.term))
    print("Old face {}".format(myLoan.face))

    myLoan.rate = .035
    myLoan.term = 60
    myLoan.face = 20000

    print("New rate {}".format(myLoan.rate))
    print("New term {}".format(myLoan.term))
    print("New face {}".format(myLoan.face))
Beispiel #4
0
def main():
    print('========== Exersize 2.1.5 ==========\n')
    print('Testing static method for monthly rate : {}'.format(
        Loan.monthlyRate(.025)))
    print('Testing testing static method for annual rate: {}'.format(
        Loan.annualRate(.01)))
    """
        The benefit of the static method is that neither the class nor the instance is passed in.  This allows us 
        to include functions that may be useful for the class, but do not directly rely on information in the class.
        From an organizational standpoint this makes it easier to organize the code.  For example, the rate conversion is
        not logically part of a loan object, however the loan class is where it makes most sense to include it.
    """

    myLoan = Loan(360, .025, 100000)
    print("Monthly Payment: {}".format(myLoan.monthlyPayment()))
    print("Balance after 60 periods: {}".format(myLoan.balance(60)))
    print("Interest due on period 60: {}".format(myLoan.interestDue(60)))
    print("Principal due on period 60: {}".format(myLoan.principlaDue(60)))

    print("The total payment should equal interest plus principal which is {}".
          format(myLoan.interestDue(5) + myLoan.principlaDue(5)))
    print("Total Interest paid is {}".format(myLoan.totalInterest()))
    print("Total Payment is {}".format(myLoan.totalPayments()))
    print("Total Interest paid is {}".format(myLoan.totalInterest()))

    print("Old rate {}".format(myLoan.rate))
    print("Old term {}".format(myLoan.term))
    print("Old face {}".format(myLoan.face))

    myLoan.rate = .035
    myLoan.term = 60
    myLoan.face = 20000

    print("New rate {}".format(myLoan.rate))
    print("New term {}".format(myLoan.term))
    print("New face {}".format(myLoan.face))
Beispiel #5
0
def main():
    print ('========== Exersize 2.1.3 ==========\n')
    myLoan = Loan(360,.025,100000)
    print("Monthly Payment: {}".format(myLoan.monthlyPayment()))
    t = timer()
    t.start()
    print("Balance after 60 periods: {}".format(myLoan.balance(60)))
    t.end()
    t.start()
    print('Balance in period 60 computed recursivly {}'.format(myLoan.balanceRecursive(60, myLoan.face)))
    t.end()
    t.start()
    print("Interest due on period 60: {}".format(myLoan.interestDue(60)))
    t.end()
    t.start()
    print('Interest in period 60 computed recursivly {}'.format(myLoan.interestDueRecursive(60, myLoan.face)))
    t.end()
    t.start()
    print("Principal due on period 60: {}".format(myLoan.principlaDue(60)))
    t.end()
    t.start()
    print('Principal in period 60 computed recursivly {}'.format(myLoan.principalDueRecursive(60, myLoan.face)))
    t.end()

    """
    On my system, in both instances the direct and recursive versions of the function run to fast to comeup with a time besides 0
    However, I know that the recursive function is likely much slower
    """

    print("The total payment should equal interest plus principal which is {}".format(myLoan.interestDue(5) + myLoan.principlaDue(5)))
    print("Total Interest paid is {}".format(myLoan.totalInterest()))
    print("Total Payment is {}".format(myLoan.totalPayments()))
    print("Total Interest paid is {}".format(myLoan.totalInterest()))

    print("Old rate {}".format(myLoan.rate))
    print("Old term {}".format(myLoan.term))
    print("Old face {}".format(myLoan.face))

    myLoan.rate = .035
    myLoan.term = 60
    myLoan.face = 20000

    print("New rate {}".format(myLoan.rate))
    print("New term {}".format(myLoan.term))
    print("New face {}".format(myLoan.face))