jgnash.engine
Class AmortizeObject

java.lang.Object
  extended by jgnash.engine.AmortizeObject

public class AmortizeObject
extends java.lang.Object

This class is used to calculate loan payments.

Because BigDecimal is lacking methods of exponentials, calculations are performed using StrictMath to maintain portability. Results are returned as doubles. Results will need to be scaled and rounded.

Version:
$Id$
Author:
Craig Cavanaugh

Field Summary
private  Account bankAccount
           
private  java.util.Date date
          origination date
private  java.math.BigDecimal daysPerYear
          the number of days per year for daily periodic rate
private  java.math.BigDecimal fees
          PMI, escrow, etc
private  Account feesAccount
           
private  Account interestAccount
           
private  java.math.BigDecimal interestRate
          annual interest rate, APR (ex 6.75)
private  int length
          length of loan in months
private  java.lang.String memo
          the memo to use
private  int numCompPeriods
          the number of compounding periods per year
private  int numPayments
          the number of payments per year
private  java.math.BigDecimal originalBalance
          original balance of the loan
private  java.lang.String payee
          the payee to use
private  boolean useDailyRate
          calculate interest based on daily periodic rate
 
Constructor Summary
AmortizeObject()
          Empty constructor to keep reflection happy
 
Method Summary
 Account getBankAccount()
          Returns the id of the principal account
(package private)  double getDailyPeriodicInterestRate()
          Calculates the daily interest rate.
This works for US, can't find any information on Canada
 java.util.Date getDate()
           
 java.math.BigDecimal getDaysPerYear()
          Returns the number of days per year used to calculate a daily periodic interest rate.
(package private)  double getEffectiveInterestRate()
          Calculates the effective interest rate.
Ie = (1 + i/m)^(m/n) - 1
n = payments per period m = number of times compounded per period
 java.math.BigDecimal getFees()
           
 Account getFeesAccount()
          Returns the id of the fees account
 Account getInterestAccount()
          Returns the id of the interest account
 int getInterestPeriods()
           
 double getIPayment(java.math.BigDecimal balance)
          Calculates the interest portion of the next loan payment given the remaining loan balance
 double getIPayment(java.math.BigDecimal balance, java.util.Date start, java.util.Date end)
          Calculates the interest portion of the next loan payment given the remaining loan balance and the dates between payments
 int getLength()
          Gets the length of the loan in months
 java.lang.String getMemo()
           
 java.lang.String getPayee()
           
 double getPayment()
          Calculates the principal and interest plus finance charges
 int getPaymentPeriods()
           
(package private)  double getPIPayment()
          Calculates the principal and interest payment of an equal payment series M = P * ( Ie / (1 - (1 + Ie) ^ -N)) N = total number of periods the loan is amortized over
 double getPPayment(java.math.BigDecimal balance)
          Calculates the principal portion of the next loan payment given the remaining loan balance
 java.math.BigDecimal getPrincipal()
           
 java.math.BigDecimal getRate()
           
(package private)  double getSumWithInterest()
          Calculates the sum of compounded interest and principal S = P(1+Ie)^n*term
 double getTotalInterestPaid()
           
 boolean getUseDailyRate()
          Returns how interest will be calculated.
 void setBankAccount(Account id)
          Set the id of the principal account
 void setDate(java.util.Date date)
           
 void setDaysPerYear(java.math.BigDecimal days)
          Sets the number of days per year used to calculate the daily periodic interest rate.
 void setFees(java.math.BigDecimal fees)
           
 void setFeesAccount(Account id)
          Set the id of the fees account
 void setInterestAccount(Account id)
          Set the id of the interest account
 void setInterestPeriods(int periods)
           
 void setLength(int months)
          Sets the length of the loan (in months)
 void setMemo(java.lang.String memo)
           
 void setPayee(java.lang.String payee)
           
 void setPaymentPeriods(int periods)
           
 void setPrincipal(java.math.BigDecimal principal)
           
 void setRate(java.math.BigDecimal rate)
           
 void setUseDailyRate(boolean daily)
          Determines if interest will be calculate based on a daily periodic rate, or if it is assumed that the interest is paid exactly on the due date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

interestAccount

private Account interestAccount

bankAccount

private Account bankAccount

feesAccount

private Account feesAccount

numPayments

private int numPayments
the number of payments per year


length

private int length
length of loan in months


numCompPeriods

private int numCompPeriods
the number of compounding periods per year


interestRate

private java.math.BigDecimal interestRate
annual interest rate, APR (ex 6.75)


originalBalance

private java.math.BigDecimal originalBalance
original balance of the loan


fees

private java.math.BigDecimal fees
PMI, escrow, etc


payee

private java.lang.String payee
the payee to use


memo

private java.lang.String memo
the memo to use


date

private java.util.Date date
origination date


useDailyRate

private boolean useDailyRate
calculate interest based on daily periodic rate


daysPerYear

private java.math.BigDecimal daysPerYear
the number of days per year for daily periodic rate

Constructor Detail

AmortizeObject

public AmortizeObject()
Empty constructor to keep reflection happy

Method Detail

setDate

public void setDate(java.util.Date date)

getDate

public java.util.Date getDate()

setPaymentPeriods

public void setPaymentPeriods(int periods)

getPaymentPeriods

public int getPaymentPeriods()

setLength

public void setLength(int months)
Sets the length of the loan (in months)

Parameters:
months - length of loan

getLength

public int getLength()
Gets the length of the loan in months

Returns:
length of loan in months

setUseDailyRate

public void setUseDailyRate(boolean daily)
Determines if interest will be calculate based on a daily periodic rate, or if it is assumed that the interest is paid exactly on the due date.

Parameters:
daily - true if interest should be calculated using a daily rate

getUseDailyRate

public boolean getUseDailyRate()
Returns how interest will be calculated.

Returns:
true if interest is calculated using the daily periodic rate

setDaysPerYear

public void setDaysPerYear(java.math.BigDecimal days)
Sets the number of days per year used to calculate the daily periodic interest rate. The value can be a decimal.

Parameters:
days - The number of days in a year

getDaysPerYear

public java.math.BigDecimal getDaysPerYear()
Returns the number of days per year used to calculate a daily periodic interest rate.

Returns:
The number of days per year

setRate

public void setRate(java.math.BigDecimal rate)

getRate

public java.math.BigDecimal getRate()

setPrincipal

public void setPrincipal(java.math.BigDecimal principal)

getPrincipal

public java.math.BigDecimal getPrincipal()

setInterestPeriods

public void setInterestPeriods(int periods)

getInterestPeriods

public int getInterestPeriods()

setFees

public void setFees(java.math.BigDecimal fees)

getFees

public java.math.BigDecimal getFees()

setInterestAccount

public void setInterestAccount(Account id)
Set the id of the interest account

Parameters:
id - the id of the interest account

getInterestAccount

public Account getInterestAccount()
Returns the id of the interest account

Returns:
the id of the interest account

setBankAccount

public void setBankAccount(Account id)
Set the id of the principal account

Parameters:
id - the id of the principal account

getBankAccount

public Account getBankAccount()
Returns the id of the principal account

Returns:
the id of the principal account

setFeesAccount

public void setFeesAccount(Account id)
Set the id of the fees account

Parameters:
id - the id of the fees account

getFeesAccount

public Account getFeesAccount()
Returns the id of the fees account

Returns:
the id of the fees account

setPayee

public void setPayee(java.lang.String payee)

getPayee

public java.lang.String getPayee()

setMemo

public void setMemo(java.lang.String memo)

getMemo

public java.lang.String getMemo()

getEffectiveInterestRate

double getEffectiveInterestRate()
Calculates the effective interest rate.
Ie = (1 + i/m)^(m/n) - 1
n = payments per period m = number of times compounded per period

Returns:
effective interest rate

getDailyPeriodicInterestRate

double getDailyPeriodicInterestRate()
Calculates the daily interest rate.
This works for US, can't find any information on Canada

Returns:
periodic interest rate

getSumWithInterest

double getSumWithInterest()
Calculates the sum of compounded interest and principal S = P(1+Ie)^n*term

Returns:
sum with interest

getTotalInterestPaid

public double getTotalInterestPaid()

getPIPayment

double getPIPayment()
Calculates the principal and interest payment of an equal payment series M = P * ( Ie / (1 - (1 + Ie) ^ -N)) N = total number of periods the loan is amortized over

Returns:
P and I

getPayment

public double getPayment()
Calculates the principal and interest plus finance charges

Returns:
the payment

getIPayment

public double getIPayment(java.math.BigDecimal balance)
Calculates the interest portion of the next loan payment given the remaining loan balance

Parameters:
balance - remaining balance
Returns:
interest

getIPayment

public double getIPayment(java.math.BigDecimal balance,
                          java.util.Date start,
                          java.util.Date end)
Calculates the interest portion of the next loan payment given the remaining loan balance and the dates between payments

Parameters:
balance - balance
start - start date
end - end date
Returns:
interest

getPPayment

public double getPPayment(java.math.BigDecimal balance)
Calculates the principal portion of the next loan payment given the remaining loan balance

Parameters:
balance - balance
Returns:
principal