Venice 0.7beta

org.mov.portfolio
Class Transaction

java.lang.Object
  extended by org.mov.portfolio.Transaction
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable

public class Transaction
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable

Representation of a single transaction on the portfolio. A transaction is ANY kind of financial action from trading a stock to receiving credit interest. Transactions are used to build up a portfolio, the user does not enter how many shares they own but rather their share transactions and their current total is calculated from that.

Author:
Andrew Leppard

Field Summary
static int ACCUMULATE
          Accumulate (buy) shares
static int DEPOSIT
          Deposit cash
static int DIVIDEND
          Dividend
static int DIVIDEND_DRP
          Dividend DRP (Dividend Reinvestment Programme)
static int FEE
          Fee (FID, TAX etc)
static int INTEREST
          Credit/Debit interest
static int REDUCE
          Reduce (sell) shares
static int TRANSFER
          Transfer money between two cash accounts
static int WITHDRAWAL
          Withdrawl cash
 
Constructor Summary
Transaction(int type, TradingDate date, Money amount, Symbol symbol, int shares, Money tradeCost, CashAccount cashAccount, CashAccount cashAccount2, ShareAccount shareAccount)
          Create a new generic transaction.
 
Method Summary
 java.lang.Object clone()
           
 int compareTo(java.lang.Object object)
          Compare this transaction to another one.
 boolean equals(java.lang.Object object)
          Compares this transaction to another.
 Money getAmount()
          Return the amount of this transaction if applicable.
 CashAccount getCashAccount()
          Return the associated cash account if any.
 CashAccount getCashAccount2()
          Return the second associated cash account if any.
 TradingDate getDate()
          Return the date this transaction occured on.
 ShareAccount getShareAccount()
          Return the associated share account if any.
 int getShares()
          Return the shares traded if this transaction was a share transaction.
 Symbol getSymbol()
          Return the symbol traded if this transaction was a share transaction.
 Money getTradeCost()
          Return the cost of the trade if this transaction was a share transaction.
 int getType()
          Return the type of this transaction.
static Transaction newAccumulate(TradingDate date, Money amount, Symbol symbol, int shares, Money tradeCost, CashAccount cashAccount, ShareAccount shareAccount)
          Create a new accumulate transaction.
static Transaction newDeposit(TradingDate date, Money amount, CashAccount account)
          Create a new deposit transaction.
static Transaction newDividend(TradingDate date, Money amount, Symbol symbol, CashAccount cashAccount, ShareAccount shareAccount)
          Create a new dividend transaction.
static Transaction newDividendDRP(TradingDate date, Symbol symbol, int shares, ShareAccount shareAccount)
          Create a new dividend transaction.
static Transaction newFee(TradingDate date, Money amount, CashAccount account)
          Create a new fee transaction.
static Transaction newInterest(TradingDate date, Money amount, CashAccount account)
          Create a new interest transaction.
static Transaction newReduce(TradingDate date, Money amount, Symbol symbol, int shares, Money tradeCost, CashAccount cashAccount, ShareAccount shareAccount)
          Create a new reduce transaction.
static Transaction newTransfer(TradingDate date, Money amount, CashAccount cashAccount, CashAccount cashAccount2)
          Create a new transfer transaction.
static Transaction newWithdrawal(TradingDate date, Money amount, CashAccount account)
          Create a new withdrawal transaction.
 void setCashAccount(CashAccount cashAccount)
          Set the associated cash account.
 void setCashAccount2(CashAccount cashAccount2)
          Set the secondary associated cash account.
 void setShareAccount(ShareAccount shareAccount)
          Set the associated share account.
static int stringToType(java.lang.String type)
          Convert between a transaction type string and its transaction type.
 java.lang.String toString()
          Convert this transaction to a tab-separated value string.
static java.lang.String typeToString(int type)
          Convert between a given transaction type and a text string.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WITHDRAWAL

public static final int WITHDRAWAL
Withdrawl cash

See Also:
Constant Field Values

DEPOSIT

public static final int DEPOSIT
Deposit cash

See Also:
Constant Field Values

INTEREST

public static final int INTEREST
Credit/Debit interest

See Also:
Constant Field Values

FEE

public static final int FEE
Fee (FID, TAX etc)

See Also:
Constant Field Values

ACCUMULATE

public static final int ACCUMULATE
Accumulate (buy) shares

See Also:
Constant Field Values

REDUCE

public static final int REDUCE
Reduce (sell) shares

See Also:
Constant Field Values

DIVIDEND

public static final int DIVIDEND
Dividend

See Also:
Constant Field Values

DIVIDEND_DRP

public static final int DIVIDEND_DRP
Dividend DRP (Dividend Reinvestment Programme)

See Also:
Constant Field Values

TRANSFER

public static final int TRANSFER
Transfer money between two cash accounts

See Also:
Constant Field Values
Constructor Detail

Transaction

public Transaction(int type,
                   TradingDate date,
                   Money amount,
                   Symbol symbol,
                   int shares,
                   Money tradeCost,
                   CashAccount cashAccount,
                   CashAccount cashAccount2,
                   ShareAccount shareAccount)
Create a new generic transaction.

Parameters:
type - type of the transaction, e.g. INTEREST
date - date the transaction took place
amount - the amount/value/cost of the transaction
symbol - for share trades and dividends, the symbol traded
shares - for share trades and dividend DRPs, the number of symbols bought/solded/re-invested
tradeCost - for shares trades, the cost of the trade including any GST, Stamp Duty, Taxes etc
cashAccount - related cash account (if any)
cashAccount2 - second related cash account (if any)
shareAccount - related share account (if any)
Method Detail

newWithdrawal

public static Transaction newWithdrawal(TradingDate date,
                                        Money amount,
                                        CashAccount account)
Create a new withdrawal transaction. Money has been withdrawn from a CashAccount.

Parameters:
date - date the transaction took place
amount - the amount withdrawn
account - cash account

newDeposit

public static Transaction newDeposit(TradingDate date,
                                     Money amount,
                                     CashAccount account)
Create a new deposit transaction. Money has been deposited into a CashAccount.

Parameters:
date - date the transaction took place
amount - the amount deposited
account - cash account

newInterest

public static Transaction newInterest(TradingDate date,
                                      Money amount,
                                      CashAccount account)
Create a new interest transaction. CashAccount has received credit interest.

Parameters:
date - date the transaction took place
amount - the amount deposited
account - cash account

newFee

public static Transaction newFee(TradingDate date,
                                 Money amount,
                                 CashAccount account)
Create a new fee transaction. CashAccount has been debited with some sort of fee.

Parameters:
date - date the transaction took place
amount - the amount withdrawn
account - cash account

newAccumulate

public static Transaction newAccumulate(TradingDate date,
                                        Money amount,
                                        Symbol symbol,
                                        int shares,
                                        Money tradeCost,
                                        CashAccount cashAccount,
                                        ShareAccount shareAccount)
Create a new accumulate transaction. Shares have been bought.

Parameters:
date - date the transaction took place
amount - the cost of the shares (not including trade cost)
symbol - the symbol traded
shares - number of shares traded
tradeCost - for shares trades, the cost of the trade including any GST, Stamp Duty, Taxes etc
shareAccount - share account
cashAccount - cash account

newReduce

public static Transaction newReduce(TradingDate date,
                                    Money amount,
                                    Symbol symbol,
                                    int shares,
                                    Money tradeCost,
                                    CashAccount cashAccount,
                                    ShareAccount shareAccount)
Create a new reduce transaction. Shares have been sold.

Parameters:
date - date the transaction took place
amount - the value of the shares (not including trade cost)
symbol - the symbol traded
shares - number of shares traded
tradeCost - for shares trades, the cost of the trade including any GST, Stamp Duty, Taxes etc
shareAccount - share account
cashAccount - cash account

newDividend

public static Transaction newDividend(TradingDate date,
                                      Money amount,
                                      Symbol symbol,
                                      CashAccount cashAccount,
                                      ShareAccount shareAccount)
Create a new dividend transaction. A share has paid a dividend.

Parameters:
date - date the transaction took place
amount - the value of the dividend
symbol - the stock paying the dividend
shareAccount - share account
cashAccount - cash account

newDividendDRP

public static Transaction newDividendDRP(TradingDate date,
                                         Symbol symbol,
                                         int shares,
                                         ShareAccount shareAccount)
Create a new dividend transaction. A share has paid a dividend and the dividend has been re-invested back into the holding, increasing the holding by several shares.

Parameters:
date - date the transaction took place
symbol - the stock paying the dividend
shares - the number of shares gained
shareAccount - share account

newTransfer

public static Transaction newTransfer(TradingDate date,
                                      Money amount,
                                      CashAccount cashAccount,
                                      CashAccount cashAccount2)
Create a new transfer transaction. A transfer transaction is when cash has been transferred between two cash accounts.

Parameters:
date - date the transaction took place
amount - the value of the transfer
cashAccount - source cash account
cashAccount2 - destination cash account

typeToString

public static java.lang.String typeToString(int type)
Convert between a given transaction type and a text string.

Parameters:
type - the transaction type
Returns:
string representation of transaction

stringToType

public static int stringToType(java.lang.String type)
Convert between a transaction type string and its transaction type.

Parameters:
type - string representation of the transaction
Returns:
the transaction type

compareTo

public int compareTo(java.lang.Object object)
Compare this transaction to another one. Transactions are compared by date only.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - other transaction object
Returns:
-1 if this transaction is before; 0 if they fall on the same date; 1 if this transaction is after

equals

public boolean equals(java.lang.Object object)
Compares this transaction to another.

Overrides:
equals in class java.lang.Object
Parameters:
object - another transaction
Returns:
true if the transactions are equal; false otherwise

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Convert this transaction to a tab-separated value string.

Overrides:
toString in class java.lang.Object
Returns:
text version

getType

public int getType()
Return the type of this transaction.

Returns:
type

getDate

public TradingDate getDate()
Return the date this transaction occured on.

Returns:
date

getAmount

public Money getAmount()
Return the amount of this transaction if applicable.

Returns:
amount

getSymbol

public Symbol getSymbol()
Return the symbol traded if this transaction was a share transaction.

Returns:
symbol or null if this transaction was not a share transaction

getShares

public int getShares()
Return the shares traded if this transaction was a share transaction.

Returns:
number of shares or 0 if this transaction was not a share transaction

getTradeCost

public Money getTradeCost()
Return the cost of the trade if this transaction was a share transaction.

Returns:
cost of trade or 0 if this transaction was not a share transaction

getCashAccount

public CashAccount getCashAccount()
Return the associated cash account if any.

Returns:
cash account or null if no cash account associated with this transaction
See Also:
CashAccount

getCashAccount2

public CashAccount getCashAccount2()
Return the second associated cash account if any.

Returns:
second cash account or null if only zero or one cash accounts are associated with this transaction
See Also:
CashAccount

getShareAccount

public ShareAccount getShareAccount()
Return the associated share account if any.

Returns:
share account or null if no cash account associated with this transaction
See Also:
ShareAccount

setCashAccount

public void setCashAccount(CashAccount cashAccount)
Set the associated cash account.

Parameters:
cashAccount - the new cash account
See Also:
CashAccount

setCashAccount2

public void setCashAccount2(CashAccount cashAccount2)
Set the secondary associated cash account.

Parameters:
cashAccount2 - the new secondary cash account
See Also:
CashAccount

setShareAccount

public void setShareAccount(ShareAccount shareAccount)
Set the associated share account.

Parameters:
shareAccount - the new share account
See Also:
ShareAccount

Venice 0.7beta