Venice 0.751beta

nz.org.venice.quote
Class MixedQuoteBundle

java.lang.Object
  extended bynz.org.venice.quote.MixedQuoteBundle
All Implemented Interfaces:
QuoteBundle

public class MixedQuoteBundle
extends java.lang.Object
implements QuoteBundle

When a task requires a mix of end-of-day and intra-day stock quotes, it should create an instance of this class which represents all the task's required quotes. This quote bundle is useful for displaying the latest value of stock quotes. If intra-day quotes are not available, then user of this package will transparently see just the end-of-day quotes. Even when intra-day quotes are available, the end-of-day quotes can be used for calculating quote change.

Example:

      MixedQuoteBundle quoteBundle = new MixedQuoteBundle(symbols, firstDate, lastDate);
      try {
	    double = quoteBundle.getQuote("CBA", Quote.DAY_OPEN, 0);
      }
      catch(QuoteNotLoadedException e) {
          //...
      }
 

Author:
Andrew Leppard
See Also:
EODQuote, IDQuote, Quote, Symbol

Constructor Summary
MixedQuoteBundle(java.util.List symbols, TradingDate firstDate, TradingDate lastDate)
          Create a new mixed quote bundle that contains the end of day quotes from between the two dates given and the current day's intra-day quotes.
 
Method Summary
 int getFirstOffset()
          Return the fast access offset for the earliest quote in the bundle.
 int getLastOffset()
          Return the fast access 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 offset)
          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 dateOffset)
          Get a stock quote.
 TradingDate offsetToDate(int dateOffset)
          Convert between a fast access offset to an actual date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MixedQuoteBundle

public MixedQuoteBundle(java.util.List symbols,
                        TradingDate firstDate,
                        TradingDate lastDate)
Create a new mixed quote bundle that contains the end of day quotes from between the two dates given and the current day's intra-day quotes. The quote bundle should be given at least two days of end of day quotes to properly calculate quote change, in case the intra-day quotes are not available.

Parameters:
symbols - the symbols to load
firstDate - the first end of day quotes to load
lastDate - the last end of day quotes to load
Method Detail

getQuote

public double getQuote(Symbol symbol,
                       int quoteType,
                       int today,
                       int dateOffset)
                throws EvaluationException,
                       MissingQuoteException
Description copied from interface: QuoteBundle
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 can prevent the GP accessing 'future' dates.

Specified by:
getQuote in interface QuoteBundle
Parameters:
symbol - the stock symbol
quoteType - the quote type, e.g. Quote.DAY_OPEN, Quote.DAY_CLOSE, Quote.DAY_LOW, Quote.DAY_HIGH, Quote.DAY_VOLUME
today - 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).
dateOffset - modifier offset to fast access offset
Returns:
the quote
Throws:
MissingQuoteException - if the quote was not found
EvaluationException - if the script isn't allow access to the quote.

getQuote

public double getQuote(Symbol symbol,
                       int quoteType,
                       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
quoteType - the quote type, one of Quote.DAY_OPEN, Quote.DAY_CLOSE, Quote.DAY_LOW, Quote.DAY_HIGH, Quote.DAY_VOLUME
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 Quote getQuote(Symbol symbol,
                      int offset)
               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
offset - 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

offsetToDate

public TradingDate offsetToDate(int dateOffset)
Description copied from interface: QuoteBundle
Convert between a fast access offset to an actual date. Intra-day quotes will return the same date for each offset because the offset refers to the time within that date. End-of-day quotes will return a different date for each fast access offset.

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

getNearestQuote

public double getNearestQuote(Symbol symbol,
                              int quoteType,
                              int dateOffset)
                       throws MissingQuoteException
Description copied from interface: QuoteBundle
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 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

getFirstOffset

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

Specified by:
getFirstOffset in interface QuoteBundle
Returns:
fast access offset

getLastOffset

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

Specified by:
getLastOffset in interface QuoteBundle
Returns:
fast access offset

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.

Venice 0.751beta