As discussed in Creating SDE Objects, object parameters may be evaluated as if they are MATLAB® functions accessible by a common interface. This accessibility provides the impression of dynamic behavior regardless of whether the underlying parameters are truly time-varying. Furthermore, because parameters are accessible by a common interface, seemingly simple linear constructs may in fact represent complex, nonlinear designs.

For example, consider a univariate geometric Brownian motion (GBM) model of the form:

In this model, the return, *μ(t)*, and volatility,*σ(t)*, are dynamic parameters of time alone. However, when creating a `gbm`

object to represent the underlying model, such dynamic behavior must be accessible by the common $\left(\mathit{t},{\mathit{X}}_{\mathit{t}}^{}\right)$interface. This reflects the fact that `GBM`

models are restricted parameterizations that derive from the general `SDE`

class.

As a convenience, you can specify parameters of restricted models, such as GBM models, as traditional MATLAB® arrays of appropriate dimension. In this case, such arrays represent a static special case of the more general dynamic situation accessible by the $\left(\mathit{t},{\mathit{X}}_{\mathit{t}}^{}\right)$ interface.

Moreover, when you enter parameters as functions, object constructors can verify that they return arrays of correct size by evaluating them at the initial time and state. Otherwise, object constructors have no knowledge of any particular functional form.

The following example illustrates a technique that includes dynamic behavior by mapping a traditional MATLAB® time series array to a callable function with a $\left(\mathit{t},{\mathit{X}}_{\mathit{t}}^{}\right)$ interface. It also compares the function with an otherwise identical model with constant parameters.

Because time series arrays represent dynamic behavior that must be captured by functions accessible by the $\left(\mathit{t},{\mathit{X}}_{\mathit{t}}^{}\right)$ interface, you need utilities to convert traditional time series arrays into callable functions of time and state. The following example shows how to do this using the conversion function `ts2func`

(time series to function).

Load a daily historical data set containing three-month Euribor rates and closing index levels of France's CAC 40 spanning the time interval February 7, 2001 to April 24, 2006.

Simulate risk-neutral sample paths of the CAC 40 index using a geometric Brownian motion (GBM) model:

where *r(t)* represents evolution of the risk-free rate of return.

Furthermore, assume that you need to annualize the relevant information derived from the daily data (annualizing the data is optional, but is useful for comparison to other examples), and that each calendar year comprises 250 trading days.

Compare the resulting sample paths obtained from two risk-neutral historical simulation approaches, where the daily Euribor yields serve as a proxy for the risk-free rate of return.

The first approach specifies the risk-neutral return as the sample average of Euribor yields, and therefore assumes a constant (non-dynamic) risk-free return.

obj =
Class GBM: Generalized Geometric Brownian Motion
------------------------------------------------
Dimensions: State = 1, Brownian = 1
------------------------------------------------
StartTime: 0
StartState: 100
Correlation: 1
Drift: drift rate function F(t,X(t))
Diffusion: diffusion rate function G(t,X(t))
Simulation: simulation method/function simByEuler
Return: 0.0278117
Sigma: 0.231906

In contrast, the second approach specifies the risk-neutral return as the historical time series of Euribor yields. It therefore assumes a dynamic, yet deterministic, rate of return; this example does not illustrate stochastic interest rates. To illustrate this dynamic effect, use the `ts2func`

utility.

`ts2func`

packages a specified time series array inside a callable function of time and state, and synchronizes it with an optional time vector. For instance:

evaluates the function at (*t *= `0`

, ${\mathit{X}}_{\mathit{t}}^{}$ = `100`

) and returns the first observed Euribor yield.

However, you can also evaluate the resulting function at any intermediate time *t* and state ${\mathit{X}}_{\mathit{t}}^{}$:

Furthermore, the following command produces the same result when called with time alone:

The equivalence of these last two commands highlights some important features.

When you specify parameters as functions, they must evaluate properly when passed a scalar, real-valued sample time (*t*), and an `NVars`

-by-`1`

state vector (${\mathit{X}}_{\mathit{t}}^{}$). They must also generate an array of appropriate dimensions, which in the first case is a scalar constant, and in the second case is a scalar, piecewise constant function of time alone. You are not required to use either time (*t*) or state (${\mathit{X}}_{\mathit{t}}^{}$). In the current example, the function evaluates properly when passed time followed by state, thereby satisfying the minimal requirements. The fact that it also evaluates correctly when passed only time simply indicates that the function does not require the state vector ${\mathit{X}}_{\mathit{t}}^{}$. The important point to make is that it works when you pass it $\left(\mathit{t},{\mathit{X}}_{\mathit{t}}^{}\right)$.

Furthermore, the `ts2func`

function performs a zero-order-hold (ZOH) piecewise constant interpolation. The notion of piecewise constant parameters is pervasive throughout the SDE architecture, and is discussed in more detail in Optimizing Accuracy: About Solution Precision and Error.

Complete the comparison by performing the second simulation using the same initial random number state. Simulate paths using a dynamic, deterministic rate of return.

obj =
Class GBM: Generalized Geometric Brownian Motion
------------------------------------------------
Dimensions: State = 1, Brownian = 1
------------------------------------------------
StartTime: 0
StartState: 100
Correlation: 1
Drift: drift rate function F(t,X(t))
Diffusion: diffusion rate function G(t,X(t))
Simulation: simulation method/function simByEuler
Return: function ts2func/vector2Function
Sigma: 0.231906

Plot the series of risk-free reference rates to compare the two simulation trials.

The paths are close but not exact. The blue line in the last plot uses all the historical Euribor data, and illustrates a single trial of a historical simulation.