Venice 0.751beta

nz.org.venice.quote
Class EODQuoteBundle

java.lang.Object
  extended bynz.org.venice.quote.EODQuoteBundle
All Implemented Interfaces:
QuoteBundle
Direct Known Subclasses:
GPQuoteBundle

public class EODQuoteBundle
extends java.lang.Object
implements QuoteBundle

When a task requires end-of-day stock quotes, it should create an instance of this class which represents all the task's required quotes. The task can then access quotes from this class, which in turn reads its stock quotes from the global end-of-day quote cache - EODQuoteCache.

The purpose of this class is therefore to group together a set of quotes that are needed by a single task. This grouping allows the quotes to be loaded in at one time, which is much faster than loading them in quote by quote.

Also by placing a set of quotes in a bundle it simplifies caching. Caching is performed by EODQuoteBundleCache. Example:

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

Author:
Andrew Leppard
See Also:
GPQuoteBundle, EODQuote, EODQuoteRange, EODQuoteBundleCache, EODQuoteCache, IDQuoteBundle, Symbol

Field Summary
protected  EODQuoteBundleCache quoteBundleCache
          For speed reasons, keep reference to the global quote bundle cache
protected  EODQuoteCache quoteCache
          For speed reasons, keep reference to the global quote cache
 
Constructor Summary
EODQuoteBundle(EODQuoteBundle quoteBundle)
          Create a new end-of-day quote bundle with the same quote range as the given quote bundle.
EODQuoteBundle(EODQuoteRange quoteRange)
          Create a new end-of-day quote bundle that represents the quotes in the given quote range.
 
Method Summary
 boolean containsQuote(Symbol symbol, int dateOffset)
          Return whether the given quote should be in this quote bundle.
 boolean containsQuote(Symbol symbol, TradingDate date)
          Return whether the given quote should be in this quote bundle.
 int dateToOffset(TradingDate date)
          Convert between a date and a fast access date offset.
 java.util.List getAllSymbols()
          Returns all the symbols in the quote bundle.
 TradingDate getFirstDate()
          Return the first date in this quote bundle.
 int getFirstOffset()
          Return the fast access date offset for the earliest quote in the bundle.
 Symbol getFirstSymbol()
          Return the first symbol in the quote bundle.
 TradingDate getLastDate()
          Return the last date in this quote bundle.
 int getLastOffset()
          Return the fast access date offset for the latest quote in the bundle.
 double getNearestQuote(Symbol symbol, int quoteType, int dateOffset)
          Get a stock quote nearest to the given offset.
 int getOffset(Quote quote)
          Retrieve the fast access offset from the given quote.
 Quote getQuote(Symbol symbol, int dateOffset)
          Get a stock quote.
 double getQuote(Symbol symbol, int quoteType, int dateOffset)
          Get a stock quote.
 double getQuote(Symbol symbol, int quoteType, int today, int offset)
          Get a stock quote.
 double getQuote(Symbol symbol, int quoteType, TradingDate date)
          Get a stock quote.
 EODQuoteRange getQuoteRange()
          Return the quote range which specifies this quote bundle.
 java.util.List getSymbols(int dateOffset)
          Returns all the symbols listed in this quote bundle for the given date.
 java.util.List getSymbols(TradingDate date)
          Returns all the symbols listed in this quote bundle for the given date.
 java.util.Iterator iterator()
          Return an iterator over this quote bundle.
 TradingDate offsetToDate(int dateOffset)
          Convert between a fast access date offset to an actual date.
 void setQuoteRange(EODQuoteRange quoteRange)
          Set the qutoe range which specifies this quote bundle.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

quoteCache

protected EODQuoteCache quoteCache
For speed reasons, keep reference to the global quote cache


quoteBundleCache

protected EODQuoteBundleCache quoteBundleCache
For speed reasons, keep reference to the global quote bundle cache

Constructor Detail

EODQuoteBundle

public EODQuoteBundle(EODQuoteRange quoteRange)
Create a new end-of-day quote bundle that represents the quotes in the given quote range.

Parameters:
quoteRange - the quote range

EODQuoteBundle

public EODQuoteBundle(EODQuoteBundle quoteBundle)
Create a new end-of-day quote bundle with the same quote range as the given quote bundle.

Parameters:
quoteBundle - the quote bundle to copy
Method Detail

getQuote

public double getQuote(Symbol symbol,
                       int quoteType,
                       int dateOffset)
                throws MissingQuoteException
Get a stock quote. If the stock is earlier than the first date in the bundle, the bundle will be expand to include the new date given. If the stock symbol is not included in the original symbol list, the quote bundle will be expanded to include it.

Specified by:
getQuote in interface QuoteBundle
Parameters:
symbol - the stock symbol
quoteType - the quote type, one of Quote.DAY_OPEN, Quote.DAY_CLOSE, Quote.DAY_LOW, Quote.DAY_HIGH, Quote.DAY_VOLUME
dateOffset - fast access date offset, see EODQuoteCache
Returns:
the quote
Throws:
MissingQuoteException - if the quote was not found

getQuote

public Quote getQuote(Symbol symbol,
                      int dateOffset)
               throws MissingQuoteException
Description copied from interface: QuoteBundle
Get a stock quote. If the stock is earlier than the first date in the bundle, the bundle will be expand to include the new date given. If the stock symbol is not included in the original symbol list, the quote bundle will be expanded to include it.

Specified by:
getQuote in interface QuoteBundle
Parameters:
symbol - the stock symbol
dateOffset - fast access offset of current quote, for end-of-day quotes this is the fast access date offset (see EODQuoteCache). For intra-day quotes, it is the fast access time offset (see IDQuoteCache).
Returns:
the quote
Throws:
MissingQuoteException - if the quote was not found

getQuote

public double getQuote(Symbol symbol,
                       int quoteType,
                       int today,
                       int offset)
                throws EvaluationException,
                       MissingQuoteException
Get a stock quote. This function has been primarily created for Gondola scripts. It passes in the current date and the date offset so that specialised QuoteBundle implementations such as GPQuoteBundle can prevent the GP accessing 'future' dates.

Specified by:
getQuote in interface QuoteBundle
Parameters:
symbol - the stock symbol
quoteType - the quote type, one of Quote.DAY_OPEN, Quote.DAY_CLOSE, Quote.DAY_LOW, Quote.DAY_HIGH, Quote.DAY_VOLUME
today - fast access date offset of current date, see EODQuoteCache
offset - offset from current date
Returns:
the quote
Throws:
EvaluationException - if the script isn't allow access to the quote.
MissingQuoteException - if the quote was not found

getQuote

public double getQuote(Symbol symbol,
                       int quoteType,
                       TradingDate date)
                throws MissingQuoteException
Get a stock quote.

Parameters:
symbol - the stock symbol
quoteType - the quote type, one of Quote.DAY_OPEN, Quote.DAY_CLOSE, Quote.DAY_LOW, Quote.DAY_HIGH, Quote.DAY_VOLUME
date - the date
Returns:
the quote
Throws:
MissingQuoteException - if the quote was not found

getNearestQuote

public double getNearestQuote(Symbol symbol,
                              int quoteType,
                              int dateOffset)
                       throws MissingQuoteException
Get a stock quote nearest to the given offset.

Specified by:
getNearestQuote in interface QuoteBundle
Parameters:
symbol - the stock symbol
quoteType - the quote type, one of Quote.DAY_OPEN, Quote.DAY_CLOSE, Quote.DAY_LOW, Quote.DAY_HIGH, Quote.DAY_VOLUME
dateOffset - fast access date offset, see EODQuoteCache
Returns:
the quote nearest to the given dateOffset
Throws:
MissingQuoteException - if the quote was not found

containsQuote

public boolean containsQuote(Symbol symbol,
                             int dateOffset)
Return whether the given quote should be in this quote bundle.

Parameters:
symbol - the symbol
dateOffset - fast access date offset, see EODQuoteCache
Returns:
true if this symbol should be in the quote bundle, false otherwise

containsQuote

public boolean containsQuote(Symbol symbol,
                             TradingDate date)
Return whether the given quote should be in this quote bundle.

Parameters:
symbol - the symbol
date - the date
Returns:
true if this symbol should be in the quote bundle, false otherwise

iterator

public java.util.Iterator iterator()
Return an iterator over this quote bundle. The iterator will return, in order, all the quotes in this bundle.

Returns:
iterator over the quotes
See Also:
Quote

getQuoteRange

public EODQuoteRange getQuoteRange()
Return the quote range which specifies this quote bundle.

Returns:
the quote range

setQuoteRange

public void setQuoteRange(EODQuoteRange quoteRange)
Set the qutoe range which specifies this quote bundle.

Parameters:
quoteRange - the new quote range

getFirstSymbol

public Symbol getFirstSymbol()
Return the first symbol in the quote bundle.

Returns:
the first symbol

getAllSymbols

public java.util.List getAllSymbols()
Returns all the symbols in the quote bundle.

Returns:
all symbols

getSymbols

public java.util.List getSymbols(int dateOffset)
Returns all the symbols listed in this quote bundle for the given date.

Parameters:
dateOffset - fast access date offset, see EODQuoteCache
Returns:
all symbols

getSymbols

public java.util.List getSymbols(TradingDate date)
Returns all the symbols listed in this quote bundle for the given date.

Parameters:
date - the date
Returns:
all symbols

getFirstDate

public TradingDate getFirstDate()
Return the first date in this quote bundle.

Returns:
the earliest date

getLastDate

public TradingDate getLastDate()
Return the last date in this quote bundle.

Returns:
the latest date

getFirstOffset

public int getFirstOffset()
Return the fast access date offset for the earliest quote in the bundle.

Specified by:
getFirstOffset in interface QuoteBundle
Returns:
fast access date offset
See Also:
EODQuoteCache

getLastOffset

public int getLastOffset()
Return the fast access date offset for the latest quote in the bundle.

Specified by:
getLastOffset in interface QuoteBundle
Returns:
fast access date offset
See Also:
EODQuoteCache

offsetToDate

public TradingDate offsetToDate(int dateOffset)
Convert between a fast access date offset to an actual date.

Specified by:
offsetToDate in interface QuoteBundle
Parameters:
dateOffset - fast access date offset, see EODQuoteCache
Returns:
the date

dateToOffset

public int dateToOffset(TradingDate date)
                 throws WeekendDateException
Convert between a date and a fast access date offset.

Parameters:
date - the date
Returns:
fast access date offset, see EODQuoteCache
Throws:
WeekendDateException

getOffset

public int getOffset(Quote quote)
              throws WeekendDateException
Retrieve the fast access offset from the given quote.

Specified by:
getOffset in interface QuoteBundle
Parameters:
quote - quote
Returns:
fast access offset
Throws:
WeekendDateException - if the date falls on a weekend.

toString

public java.lang.String toString()

Venice 0.751beta