Venice 0.7beta

org.mov.quote
Class DatabaseQuoteSource

java.lang.Object
  extended by org.mov.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

Field Summary
static int EXTERNAL
          External database.
static int HSQLDB
          Hypersonic SQL Database.
static java.lang.String HSQLDB_SOFTWARE
           
static int INTERNAL
          Internal database.
static int MYSQL
          MySQL Database.
static java.lang.String MYSQL_SOFTWARE
           
static int OTHER
          Any generic SQL Database.
static int POSTGRESQL
          PostgreSQL Database.
static java.lang.String POSTGRESQL_SOFTWARE
           
 
Constructor Summary
DatabaseQuoteSource(java.lang.String fileName)
          Create a new quote source to connect to an internal HSQL database stored in the given file.
DatabaseQuoteSource(java.lang.String software, java.lang.String driver, java.lang.String host, java.lang.String port, java.lang.String database, java.lang.String username, java.lang.String password)
          Creates a new quote source to connect to an external database.
 
Method Summary
 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.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 database.
 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
 

Field Detail

MYSQL

public static final int MYSQL
MySQL Database.

See Also:
Constant Field Values

POSTGRESQL

public static final int POSTGRESQL
PostgreSQL Database.

See Also:
Constant Field Values

HSQLDB

public static final int HSQLDB
Hypersonic SQL Database.

See Also:
Constant Field Values

OTHER

public static final int OTHER
Any generic SQL Database.

See Also:
Constant Field Values

INTERNAL

public static final int INTERNAL
Internal database.

See Also:
Constant Field Values

EXTERNAL

public static final int EXTERNAL
External database.

See Also:
Constant Field Values

MYSQL_SOFTWARE

public static final java.lang.String MYSQL_SOFTWARE
See Also:
Constant Field Values

POSTGRESQL_SOFTWARE

public static final java.lang.String POSTGRESQL_SOFTWARE
See Also:
Constant Field Values

HSQLDB_SOFTWARE

public static final java.lang.String HSQLDB_SOFTWARE
See Also:
Constant Field Values
Constructor Detail

DatabaseQuoteSource

public DatabaseQuoteSource(java.lang.String software,
                           java.lang.String driver,
                           java.lang.String host,
                           java.lang.String port,
                           java.lang.String database,
                           java.lang.String username,
                           java.lang.String password)
Creates a new quote source to connect to an external database.

Parameters:
software - the database software
driver - the class name for the driver to connect to the database
host - the host location of the database
port - the port of the database
database - the name of the database
username - the user login
password - the password for the login

DatabaseQuoteSource

public DatabaseQuoteSource(java.lang.String fileName)
Create a new quote source to connect to an internal HSQL database stored in the given file.

Parameters:
fileName - name of database file
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

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
Throws:
throws - MissingQuoteException if the date wasn't in the source
MissingQuoteException

shutdown

public void shutdown()
Shutdown the database. Only used for the internal database.

Specified by:
shutdown in interface QuoteSource

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

Venice 0.7beta