WebCab Bonds
v2.01
(J2SE Edition)

webcab.lib.finance.pricing.contexts
Class ContextGraph

java.lang.Object
  |
  +--webcab.lib.finance.pricing.contexts.ContextGraph

public class ContextGraph
extends Object

This class implements a graph of contexts. Each model produces a context graph which is processed also by the pricing algorithm and finally is sent to the contract as a parameter in its GeneralContract#getAccumulatedCashflow or FixedExchangeMomentsContract#getPayoff.

The contract implementor can use the graph to access information about the state variables and compute the payoff using it. The elementary models usually produce only one node - a Context (exception: the HJM model). When constructing a compound model (see @link CompoundModel} the nodes produced by the submodels are used to make a single large context graph.

The reason this is a graph and not a simple vector is that there are certain relationships between the contexts. For example we can have two volatility contexts, an interest rate context and a price context. One of the volatilities is a price volatility, the other is an interest rate volatility. The relationship is expressed by placing a link between the nodes in the context graph. Moreover, the graph is directed - so a link can express also a dependency between the two values. For example the AverageModel computes its variable (the average) using another state variable. The average is dependent upon the other variable. The two variables are provided by different models - so this is an inter-model dependecy. All inter-model relationships (dependencies, correlations) are controlled via the compound model (implements the CompoundModel interface). You can specify what variable is used to compute the average with a call to CompoundModel.addDependency(java.lang.String, java.lang.String). An arrow from node1 (the dependee context) to name2 (the dependent context) will be automatically added in the context graph produced by the compound model.

Each node of the graph (an individual context) keeps some of the model state variables. Each node offers access to different categories of information deduced using the variables. The information offered can be the value of a variable or the result of some determinist algorithm using the variables as inputs (e.g. ForwardRateContext uses an interpolation algorithm to compute a forward rate of specified maturity).

The information offered is classified in standard categories (its signification is standardized) - e.g. price, volatility, spot rate, forward rate curve, numeraire, average, extremum, trigger, etc. A single context (a node in the graph) can offer more than one category of information deduced from its variables. Each category has an interface associated with it, providing a means to access the information. Usually these interfaces have one or more get() methods. They usually have no parameters and have a double result, although this is not a restriction.


Constructor Summary
ContextGraph(Context context1, Context context2)
          Constructs a new ContextGraph resulting from the union of the two nodes received as parmeters.
ContextGraph(ContextGraph[] graphs, int nInitialized, Vector dependencies)
           
 
Method Summary
 void addDependency(String node1, String node2)
          This method should not be used directly.
 void addHardDependency(String node1, String node2)
          This method should not be used directly.
 ContextGraph applyContextGraphToVariables(double[] variables, double[] memoryVariables)
           
 void applyDeltaContextGraph(ContextGraph deltaContextGraph)
           
 Object clone()
           
 ContextGraph copySchema()
           
 Context[] findAllByType(int type)
          Searches for all contexts providing a specified category.
 Context findByIndex(int index)
          Returns the node with the specified index in the context graph.
 Context findByName(String name)
          Searches for a node in the context graph, using its name.
 Context findByType(int type, int index)
          Serches for the contexts providing a specified category; the index-th context found is returned.
 Context findFirstByType(int type)
          Returns the first context found supporting a specified category.
 int findIndexByName(String name)
          Returns the index of a node with a given name in the context graph.
 double getMemoryVariable(int index)
          Returns the value of the index-th internal variable.
 int getNMemoryVariables()
          Returns the total number of internal variables administered by all contexts.
 int getNNodes()
          Returns the total number of contexts in the graph.
 Context getNode(int index)
          Identical with findByIndex(int)
 int getNVariables()
          Returns the total number of variables kept by all the contexts in the graph.
 double[] getUpdatedMemoryVariables(double t, double dt)
           
 double getVariable(int index)
          Returns the value of the index-th variable.
 void setMemoryVariable(int index, double value)
           
 void setMemoryVariables(double[] values)
           
 void setVariable(int index, double value)
           
 String toString()
           
 ContextGraph union(ContextGraph graph)
           
static ContextGraph union(ContextGraph[] g, int nInitialized)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ContextGraph

public ContextGraph(ContextGraph[] graphs,
                    int nInitialized,
                    Vector dependencies)

ContextGraph

public ContextGraph(Context context1,
                    Context context2)
Constructs a new ContextGraph resulting from the union of the two nodes received as parmeters. A dependency is added, so that the second node applies to the first one.

Parameters:
context1 - The first context (node)
context2 - The second context (node)
Method Detail

applyContextGraphToVariables

public ContextGraph applyContextGraphToVariables(double[] variables,
                                                 double[] memoryVariables)

applyDeltaContextGraph

public void applyDeltaContextGraph(ContextGraph deltaContextGraph)
                            throws BondsException
BondsException

addDependency

public void addDependency(String node1,
                          String node2)
                   throws ContextNotFoundException
This method should not be used directly. Use CompoundModel.addDependency(java.lang.String, java.lang.String) instead.

ContextNotFoundException

addHardDependency

public void addHardDependency(String node1,
                              String node2)
                       throws ContextNotFoundException
This method should not be used directly. Use CompoundModel.addHardDependency(java.lang.String, java.lang.String) instead.

ContextNotFoundException

clone

public Object clone()
Overrides:
clone in class Object

copySchema

public ContextGraph copySchema()
                        throws InvalidParametersException
InvalidParametersException

findByName

public Context findByName(String name)
                   throws ContextNotFoundException
Searches for a node in the context graph, using its name.

Parameters:
name - the node's name
Returns:
Context
Throws:
ContextNotFoundException - thrown if the node was not found

findIndexByName

public int findIndexByName(String name)
                    throws ContextNotFoundException
Returns the index of a node with a given name in the context graph. The indexes begini with 0.

Parameters:
name - String
Returns:
int
Throws:
ContextNotFoundException - thrown if the node was not found

findByIndex

public Context findByIndex(int index)
                    throws ContextNotFoundException
Returns the node with the specified index in the context graph.

Parameters:
index - the index (begining with 0)
Returns:
Context
Throws:
ContextNotFoundException

findByType

public Context findByType(int type,
                          int index)
                   throws ContextNotFoundException
Serches for the contexts providing a specified category; the index-th context found is returned.

Parameters:
type - the category id
index - the index (begining with 0)
Returns:
Context
Throws:
ContextNotFoundException

findAllByType

public Context[] findAllByType(int type)
                        throws ContextNotFoundException
Searches for all contexts providing a specified category.

Parameters:
type - the category id
Returns:
Context[]
Throws:
ContextNotFoundException

findFirstByType

public Context findFirstByType(int type)
                        throws ContextNotFoundException
Returns the first context found supporting a specified category.

Parameters:
type - the category id
Returns:
Context
Throws:
ContextNotFoundException

getNode

public Context getNode(int index)
                throws ContextNotFoundException
Identical with findByIndex(int)

Parameters:
index - the index (begining with 0)
Returns:
Context
Throws:
ContextNotFoundException

getNNodes

public int getNNodes()
Returns the total number of contexts in the graph.

Returns:
int

getNVariables

public int getNVariables()
Returns the total number of variables kept by all the contexts in the graph.

Returns:
int

getNMemoryVariables

public int getNMemoryVariables()
Returns the total number of internal variables administered by all contexts.

Returns:
int

getVariable

public double getVariable(int index)
Returns the value of the index-th variable.

Parameters:
index - the index (begining with 0)
Returns:
double

getMemoryVariable

public double getMemoryVariable(int index)
Returns the value of the index-th internal variable.

Parameters:
index - the index (begining with 0)
Returns:
double

setVariable

public void setVariable(int index,
                        double value)

setMemoryVariable

public void setMemoryVariable(int index,
                              double value)

setMemoryVariables

public void setMemoryVariables(double[] values)
                        throws InvalidParametersException
InvalidParametersException

getUpdatedMemoryVariables

public double[] getUpdatedMemoryVariables(double t,
                                          double dt)
                                   throws BondsException
BondsException

toString

public String toString()
Overrides:
toString in class Object

union

public ContextGraph union(ContextGraph graph)
                   throws BondsException
BondsException

union

public static ContextGraph union(ContextGraph[] g,
                                 int nInitialized)
                          throws BondsException
BondsException

WebCab Bonds
v2.01
(J2SE Edition)