Venice 0.751beta

nz.org.venice.portfolio
Class Portfolio

java.lang.Object
  extended bynz.org.venice.portfolio.Portfolio
All Implemented Interfaces:
java.lang.Cloneable

public class Portfolio
extends java.lang.Object
implements java.lang.Cloneable

Representation of a portfolio. A portfolio object contains several accounts, accounts can be either CashAccount or ShareAccount.

Author:
Andrew Leppard

Constructor Summary
Portfolio(java.lang.String name, boolean isTransient)
          Create a new empty portfolio using the default currency.
Portfolio(java.lang.String name, Currency currency)
          Create a new empty portfolio using the given currency.
Portfolio(java.lang.String name, Currency currency, boolean isTransient)
          Create a new empty portfolio using the given currency.
 
Method Summary
 void addAccount(Account account)
          Add an account to the portfolio.
 void addTransaction(Transaction transaction)
          Record a single transaction on the portfolio.
 void addTransactions(java.util.List transactions)
          Record multiple transactions on the portfolio.
 java.lang.Object clone()
          Create a clone of this portfolio.
 int countAccounts(int type)
          Return the number of accounts of the given type the portfolio has
 int countTransactions()
          Count the number of transactions.
 int countTransactions(int type)
          Count the number of transactions of the given type.
 boolean equals(java.lang.Object object)
          Compares this portfolio to another.
 Account findAccountByName(java.lang.String name)
          Find and return the account with the given name in the portfolio.
 java.util.List getAccounts()
          Return all the accounts in the portfolio
 Money getCashValue(TradingDate date)
          Get the cash value of the Portfolio on the current day.
 Currency getCurrency()
          Return the portfolio's default currency.
 TradingDate getLastDate()
          Return the date of the last transaction in this portfolio.
 java.lang.String getName()
          Return the portfolio name.
 Portfolio getPortfolio(TradingDate date)
          Returns the state of the Portfolio on the given date.
 Money getReturnValue(EODQuoteBundle quoteBundle, TradingDate date)
          Get the return of the Portfolio on the current day.
 Money getShareValue(EODQuoteBundle quoteBundle, TradingDate date)
          Get the share value of the Portfolio on the current day.
 TradingDate getStartDate()
          Return the start date of this portfolio.
 java.util.List getStocksHeld()
          Return a list of all the stocks currently held in the portfolio.
 java.util.List getSymbolsTraded()
          Returns all the symbols traded in this portfolio.
 java.util.List getTransactions()
          Return the transaction history.
 Money getValue(EODQuoteBundle quoteBundle, int dateOffset)
          Get the value of the portfolio on the given day.
 Money getValue(EODQuoteBundle quoteBundle, TradingDate date)
          Get the value of the portfolio on the given day.
 boolean isTransient()
          Return whether the portfolio is transient or permanent.
 java.util.Iterator iterator()
          Return an iterator that iterates over every day from the date of the first transaction to whenever the user chooses to stop iterating.
 void removeAllTransactions()
          Remove all transactions from portfolio.
 void setName(java.lang.String name)
          Set the portfolio name.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Portfolio

public Portfolio(java.lang.String name,
                 Currency currency)
Create a new empty portfolio using the given currency.

Parameters:
name - The name of the portfolio
currency - The base currency of the portfolio

Portfolio

public Portfolio(java.lang.String name,
                 boolean isTransient)
Create a new empty portfolio using the default currency. The portfolio can be permanent or transient.

Parameters:
name - The name of the portfolio
isTransient - Set to true if the portfolio displays working information and shouldn't be saved.

Portfolio

public Portfolio(java.lang.String name,
                 Currency currency,
                 boolean isTransient)
Create a new empty portfolio using the given currency. The portfolio can be permanent or transient.

Parameters:
name - The name of the portfolio
currency - The base currency of the portfolio
isTransient - Set to true if the portfolio displays working information and shouldn't be saved.
Method Detail

getName

public java.lang.String getName()
Return the portfolio name.

Returns:
the name of the portfolio

setName

public void setName(java.lang.String name)
Set the portfolio name.

Parameters:
name - the new portfolio name.

getCurrency

public Currency getCurrency()
Return the portfolio's default currency.

Returns:
the default currency

isTransient

public boolean isTransient()
Return whether the portfolio is transient or permanent.

Returns:
true if the portfolio is transient and shouldn't be saved

addAccount

public void addAccount(Account account)
Add an account to the portfolio.

Parameters:
account - the new account to add

addTransactions

public void addTransactions(java.util.List transactions)
Record multiple transactions on the portfolio.

Parameters:
transactions - a list of transactions
See Also:
Transaction

addTransaction

public void addTransaction(Transaction transaction)
Record a single transaction on the portfolio.

Parameters:
transaction - a new transaction

clone

public java.lang.Object clone()
Create a clone of this portfolio.

Returns:
clone

getAccounts

public java.util.List getAccounts()
Return all the accounts in the portfolio

Returns:
accounts

countAccounts

public int countAccounts(int type)
Return the number of accounts of the given type the portfolio has

Parameters:
type - account type, e.g. Account.CASH_ACCOUNT
Returns:
number of accounts of the given type

findAccountByName

public Account findAccountByName(java.lang.String name)
Find and return the account with the given name in the portfolio.

Parameters:
name - the name of the account to search for
Returns:
the account with the same name as given or null if it could not be found

getStartDate

public TradingDate getStartDate()
Return the start date of this portfolio. The start date is defined as the date of the first transaction.

Returns:
date of the first transaction

getLastDate

public TradingDate getLastDate()
Return the date of the last transaction in this portfolio.

Returns:
date of the last transaction

getSymbolsTraded

public java.util.List getSymbolsTraded()
Returns all the symbols traded in this portfolio.

Returns:
symbols traded

countTransactions

public int countTransactions()
Count the number of transactions.

Returns:
the number of transactions

countTransactions

public int countTransactions(int type)
Count the number of transactions of the given type.

Returns:
the number of transactions

getTransactions

public java.util.List getTransactions()
Return the transaction history.

Returns:
transaction history
See Also:
Transaction

removeAllTransactions

public void removeAllTransactions()
Remove all transactions from portfolio.


getValue

public Money getValue(EODQuoteBundle quoteBundle,
                      TradingDate date)
               throws MissingQuoteException
Get the value of the portfolio on the given day. Currently this function should only be called for dates after the last transaction. When it calculates the value it will assume all transactions have taken place.

Parameters:
quoteBundle - the quote bundle
date - the date to calculate the value
Returns:
the value
Throws:
MissingQuoteException

getValue

public Money getValue(EODQuoteBundle quoteBundle,
                      int dateOffset)
               throws MissingQuoteException
Get the value of the portfolio on the given day. Currently this function should only be called for dates after the last transaction. When it calculates the value it will assume all transactions have taken place.

Parameters:
quoteBundle - the quote bundle
dateOffset - fast date offset
Returns:
the value
Throws:
MissingQuoteException

getStocksHeld

public java.util.List getStocksHeld()
Return a list of all the stocks currently held in the portfolio.

Returns:
the stock list

getCashValue

public Money getCashValue(TradingDate date)
Get the cash value of the Portfolio on the current day.

Parameters:
date - the date.
Returns:
the value

getShareValue

public Money getShareValue(EODQuoteBundle quoteBundle,
                           TradingDate date)
                    throws MissingQuoteException
Get the share value of the Portfolio on the current day.

Parameters:
quoteBundle - the quote bundle
date - the date
Returns:
the value
Throws:
MissingQuoteException

getReturnValue

public Money getReturnValue(EODQuoteBundle quoteBundle,
                            TradingDate date)
                     throws MissingQuoteException
Get the return of the Portfolio on the current day.

Parameters:
quoteBundle - the quote bundle
date - the date
Returns:
the value
Throws:
MissingQuoteException

iterator

public java.util.Iterator iterator()
Return an iterator that iterates over every day from the date of the first transaction to whenever the user chooses to stop iterating. Each iteration will return the state of the Portfolio on that date. This allows the user to efficiently query a range of historical states of the Portfolio.

Returns:
the portfolio iterator
See Also:
getPortfolio(TradingDate)

getPortfolio

public Portfolio getPortfolio(TradingDate date)
Returns the state of the Portfolio on the given date. If the date is before the last transaction in the Portfolio, then this function will-reconstruct the Portfolio to how it would have been on that date. This can be slow, so if you want to query a range of dates, the iterator() method is more efficient.

Parameters:
date - the date to query
Returns:
the Portfolio on the given date

equals

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

Parameters:
object - another portfolio
Returns:
true if the portfolios are equal; false otherwise

Venice 0.751beta