Creating User-Specified Functions

Evaluating Object Parameters, Noise, and End-of-Period Processing Functions

Several examples in this documentation emphasize the evaluation of object parameters as functions accessible by a common interface. In fact, you can evaluate object parameters by passing to them time and state, regardless of whether the underlying user-specified parameter is a function. However, it is helpful to compare the behavior of object parameters that are specified as functions to that of user-specified noise and end-of-period processing functions.

Object parameters that are specified as functions are evaluated in the same way as user-specified random number (noise) generation functions. (For more information, see Random Number Generation Functions vs. End-of-Period Processing Functions.) Object parameters that are specified as functions are inputs to model object constructors. User-specified noise and processing functions are optional inputs to model object constructors.

Because class constructors offer unique interfaces, and simulation methods of any given model have different implementation details, models often call parameter functions for validation purposes a different number of times, or in a different order, during object creation, simulation, and interpolation.

Therefore, although parameter functions, user-specified noise generation functions, and end-of-period processing functions all share the same interface and are validated at the same initial time and state (obj.StartTime and obj.StartState), parameter functions are not guaranteed to be invoked only once before simulation as noise generation and end-of-period processing functions are. In fact, parameter functions might not even be invoked the same number of times during a given Monte Carlo simulation process.

In most applications in which you specify parameters as functions, they are simple, deterministic functions of time and/or state. There is no need to count periods, count trials, or otherwise accumulate information or synchronize time.

However, if parameter functions require more sophisticated bookkeeping, the correct way to determine when a simulation has begun (or equivalently, to determine when model validation is complete) is to determine when the input time and/or state differs from the initial time and state (obj.StartTime and obj.StartState, respectively). Because the input time is a known scalar, detecting a change from the initial time is likely the best choice in most situations. This is a general mechanism that you can apply to any type of user-defined function.

Random Number Generation Functions vs. End-of-Period Processing Functions

It is useful to compare the evaluation rules of user-specified noise generation functions to those of end-of-period processing functions. These functions have the following in common:

However, there is an important distinction regarding the timing, between these two types of functions. It is most clearly drawn directly from the generic SDE model:

This equation is expressed in continuous time, but the simulation methods approximate the model in discrete time as:

where Δt > 0

is a small (and not necessarily equal) period or time increment into the future. This equation is often referred to as an Euler approximation. All functions on the right-hand side are evaluated at the current time and state (t, Xt).

In other words, over the next small time increment, the simulation evolves the state vector based only on information available at the current time and state. In this sense, you can think of the noise function as a beginning-of-period function, or as a function evaluated from the left. This is also true for any user-supplied drift or diffusion function. For more details, see Evaluating Object Parameters, Noise, and End-of-Period Processing Functions.

In contrast, user-specified end-of-period processing functions are applied only at the end of each simulation period or time increment. For more information about processing functions, see Black-Scholes Option Pricing.

Therefore, all simulation methods evaluate noise generation functions as:

for t = t0 + Δt, t0 + 2Δt, ..., T

Yet simulation methods evaluate end-of-period processing functions as:

for t = t0 + Δt, t0 + 2Δt, ..., T

where t0 and T are the initial time (taken from the object) and the terminal time (derived from inputs to the simulation method), respectively. These evaluations occur on all sample paths. Therefore, during simulation, noise functions are never evaluated at the final (terminal) time, and end-of-period processing functions are never evaluated at the initial (starting) time.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS