Venice 0.7beta

org.mov.chart
Class GraphableQuoteFunctionSource

java.lang.Object
  extended by org.mov.chart.GraphableQuoteFunctionSource
All Implemented Interfaces:
QuoteFunctionSource

public class GraphableQuoteFunctionSource
extends java.lang.Object
implements QuoteFunctionSource

Allow the QuoteFunctions package to use quotes directly from a Graphable. The following code, from MovingAverageGraph shows an example of how to call a quote function from a graph:

      Graphable movingAverage = new Graphable();
      TradingDate date = (TradingDate)source.getStartX();
      GraphableQuoteFunctionSource quoteFunctionSource 
          = new GraphableQuoteFunctionSource(source, date, period);

      for(Iterator iterator = source.iterator(); iterator.hasNext();) {
          date = (TradingDate)iterator.next();
          quoteFunctionSource.setStartDate(date);

          try {
              double average = QuoteFunctions.avg(quoteFunctionSource, period);
              movingAverage.putY(date, new Double(average));
          }
          catch(EvaluationException e) {
          }
      }
 

Author:
Andrew Leppard
See Also:
QuoteFunctions

Constructor Summary
GraphableQuoteFunctionSource(Graphable graphable, TradingDate date, int period)
          Create a new quote function source that uses quotes directly from a Graphable.
 
Method Summary
 double getValue(int index)
          Return the quote value on the given date.
 void setDate(TradingDate date)
          Set the current date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphableQuoteFunctionSource

public GraphableQuoteFunctionSource(Graphable graphable,
                                    TradingDate date,
                                    int period)
Create a new quote function source that uses quotes directly from a Graphable.

Parameters:
graphable - the graphable containing the quotes
date - the current date, the previous quotes for period number of days will be accessed
period - the number of quote dates available from this source
Method Detail

setDate

public void setDate(TradingDate date)
Set the current date. Since quote functions use previous day's quote values, this function source will provide the previous quotes for period number of days. The date given here will be the most recent quote date available from the source.

Parameters:
date - the current date

getValue

public double getValue(int index)
                throws EvaluationException
Description copied from interface: QuoteFunctionSource
Return the quote value on the given date. The quote function source contains a set of quotes which can be accessed from offset 0, which is the earliest date, to the number of quotes in the source minus one. Typically a quote source is set up to contain a fixed number of quotes, each of which is used by a quote function.

Specified by:
getValue in interface QuoteFunctionSource
Parameters:
index - the offset of the date in the quote source.
Returns:
the quote value or NaN if the quote is missing / not available
Throws:
EvaluationException - if QuoteBundleFunctionSource is not allowed access to a quote. See GPQuoteBundle.

Venice 0.7beta