Venice 0.751beta

nz.org.venice.quote
Class DatabaseQuoteSource

java.lang.Object
  extended bynz.org.venice.quote.DatabaseQuoteSource
All Implemented Interfaces:
QuoteSource

public class DatabaseQuoteSource
extends java.lang.Object
implements QuoteSource

Provides functionality to obtain stock quotes from a database. This class implements the QuoteSource interface to allow users to obtain stock quotes in the fastest possible manner. Example:

      EODQuoteRange quoteRange = new EODQuoteRange("CBA");
      EODQuoteBundle quoteBundle = new EODQuoteBundle(quoteRange);
      try {
	    float = quoteBundle.getQuote("CBA", Quote.DAY_OPEN, 0);
      }
      catch(QuoteNotLoadedException e) {
          //...
      }
 

Author:
Andrew Leppard
See Also:
Quote, EODQuote, EODQuoteRange, EODQuoteBundle

Constructor Summary
DatabaseQuoteSource(DatabaseManager manager)
          Creates a new quote source to connect to an external database.
 
Method Summary
 void cacheExpiry()
          Force the database to reset the first and last dates so that new data can be displayed.
 boolean containsDate(TradingDate date)
          Returns whether the source contains any quotes for the given date.
 int getAdvanceDecline(TradingDate date)
          Return the advance/decline for the given date.
 java.util.HashMap getAdvanceDecline(TradingDate firstDate, TradingDate lastDate)
          Return the advance/decline for the given date.
 java.util.List getDates()
          Return all the dates which we have quotes for.
 java.util.List getExchangeRates(Currency sourceCurrency, Currency destinationCurrency)
          Return all the stored exchange rates between the two currencies.
 TradingDate getFirstDate()
          Return the first date in the database that has any quotes.
 TradingDate getLastDate()
          Return the last date in the database that has any quotes.
 Symbol getSymbol(java.lang.String partialCompanyName)
          Returns the symbol associated with the given company.
 java.lang.String getSymbolName(Symbol symbol)
          Returns the company name associated with the given symbol.
 void importExchangeRates(java.util.List exchangeRates)
          Import currency exchange rates into the database.
 int importQuotes(java.util.List quotes)
          Import quotes into the database.
 boolean isMarketIndex(Symbol symbol)
          Is the given symbol a market index?
 boolean loadQuoteRange(EODQuoteRange quoteRange)
          Load the given quote range into the quote cache.
 void shutdown()
          Shutdown the quote source.
 boolean symbolExists(Symbol symbol)
          Returns whether we have any quotes for the given symbol.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseQuoteSource

public DatabaseQuoteSource(DatabaseManager manager)
Creates a new quote source to connect to an external database.

Parameters:
manager - The DatabaseManager object which manages software, username/host/port etc.
Method Detail

getSymbolName

public java.lang.String getSymbolName(Symbol symbol)
Returns the company name associated with the given symbol.

Specified by:
getSymbolName in interface QuoteSource
Parameters:
symbol - the stock symbol.
Returns:
the company name.

getSymbol

public Symbol getSymbol(java.lang.String partialCompanyName)
Returns the symbol associated with the given company.

Specified by:
getSymbol in interface QuoteSource
Parameters:
partialCompanyName - a partial company name.
Returns:
the company symbol.

symbolExists

public boolean symbolExists(Symbol symbol)
Returns whether we have any quotes for the given symbol.

Specified by:
symbolExists in interface QuoteSource
Parameters:
symbol - the symbol we are searching for
Returns:
whether the symbol was found or not

getFirstDate

public TradingDate getFirstDate()
Return the first date in the database that has any quotes.

Specified by:
getFirstDate in interface QuoteSource
Returns:
oldest date with quotes

cacheExpiry

public void cacheExpiry()
Force the database to reset the first and last dates so that new data can be displayed.

Specified by:
cacheExpiry in interface QuoteSource

getLastDate

public TradingDate getLastDate()
Return the last date in the database that has any quotes.

Specified by:
getLastDate in interface QuoteSource
Returns:
newest date with quotes

isMarketIndex

public boolean isMarketIndex(Symbol symbol)
Is the given symbol a market index?

Specified by:
isMarketIndex in interface QuoteSource
Parameters:
symbol - to test
Returns:
yes or no

loadQuoteRange

public boolean loadQuoteRange(EODQuoteRange quoteRange)
Load the given quote range into the quote cache.

Specified by:
loadQuoteRange in interface QuoteSource
Parameters:
quoteRange - the range of quotes to load
Returns:
TRUE if the operation suceeded
See Also:
EODQuote, EODQuoteCache

importQuotes

public int importQuotes(java.util.List quotes)
Import quotes into the database.

Parameters:
quotes - list of quotes to import
Returns:
the number of quotes imported

containsDate

public boolean containsDate(TradingDate date)
Returns whether the source contains any quotes for the given date.

Specified by:
containsDate in interface QuoteSource
Parameters:
date - the date
Returns:
wehther the source contains the given date

getDates

public java.util.List getDates()
Return all the dates which we have quotes for. REALLY SLOW.

Specified by:
getDates in interface QuoteSource
Returns:
a list of dates

getAdvanceDecline

public int getAdvanceDecline(TradingDate date)
                      throws MissingQuoteException
Return the advance/decline for the given date. This returns the number of all ordinary stocks that rose (day close > day open) - the number of all ordinary stocks that fell.

Specified by:
getAdvanceDecline in interface QuoteSource
Parameters:
date - the date
Returns:
the difference between the number of advances and declines for date
Throws:
throws - MissingQuoteException if the date wasn't in the source
MissingQuoteException

getAdvanceDecline

public java.util.HashMap getAdvanceDecline(TradingDate firstDate,
                                           TradingDate lastDate)
                                    throws MissingQuoteException
Return the advance/decline for the given date. This returns the number of all ordinary stocks that rose (day close > day open) - the number of all ordinary stocks that fell.

Specified by:
getAdvanceDecline in interface QuoteSource
Parameters:
firstDate - the first date in the range
lastDate - the last date in the range
Returns:
A map of dates and advance/decline differences for each date in the range
Throws:
throw - MissingQuoteException if none of the dates are in the source
MissingQuoteException

importExchangeRates

public void importExchangeRates(java.util.List exchangeRates)
Import currency exchange rates into the database.

Parameters:
exchangeRates - a list of exchange rates to import.

getExchangeRates

public java.util.List getExchangeRates(Currency sourceCurrency,
                                       Currency destinationCurrency)
Description copied from interface: QuoteSource
Return all the stored exchange rates between the two currencies.

Specified by:
getExchangeRates in interface QuoteSource
Parameters:
sourceCurrency - the currency to convert from
destinationCurrency - the currency to convert to
Returns:
the exchange rate being the number of destinationCurrency that you can buy per sourceCurrency

shutdown

public void shutdown()
Description copied from interface: QuoteSource
Shutdown the quote source.

Specified by:
shutdown in interface QuoteSource

Venice 0.751beta