C# Class HullAndWhiteTwoFactors.HW2

Inheritance: HW2Context, IExtensibleProcessIR, IZeroRateReference, IMarkovSimulator, IParsable, IPopulable, IGreeksDerivativesInfo, IExportableContainer
Show file Open project: fairmat/InterestRatesModels

Public Properties

Property Type Description
_a1 IModelParameter
_a2 IModelParameter
_rho IModelParameter
_s1 IModelParameter
_s2 IModelParameter

Public Methods

Method Description
Bond ( IReadOnlyMatrixSlice dynamic, double dates, int i, double t, double s ) : double

Calculates the value of a Bond under the Hull and White Two factors model.

ExportObjects ( bool recursive ) : List

Creates a list of all the sub-objects that can be edited.

GetDeltaFactors ( ) : IModelParameter[]

Gets the factors for Delta Greek derivative.

GetVegaFactors ( ) : IModelParameter[]

Gets the factors for Vega Greek derivative.

GetZeroRateReference ( ) : string

Gets the zero rate reference.

HW2 ( ) : System

Initializes a new instance of the HullAndWhiteTwoFactors.HW2 class. This is the default constructor and sets the default values of several components of the model: * alpha 1 = 0.1 * sigma 1 = 0.001 * alpha 2 = 0.01 * sigma 2 = 0.001 * rho = 0.001 * No zero rate. * drift correction = 0.

Parse ( IProject p_Context ) : bool

Parses the data and ensures the parameters are correct.

Populate ( string names, double values ) : void

Populate editable fields from name and value vectors specific to HW2.

SetZeroRateReference ( string zr ) : void

Associate the process to a zero rate defined in the Fairmat model (e.g. @zr1).

Setup ( double dates ) : void

Called by Simulator after parse. Initializes here time-dependant but not state dependent variables.

a ( int i, double x, double a ) : void

This function calculates the drift in the HW2 Markov process.

ab ( int i, double x, double a, double b ) : void
b ( int i, double x, double b ) : void

This function updates the volatility parameters (vector b) of the HW2 process.

isLog ( bool &isLog ) : void

Sets the passed array with a Booleans stating if the process components must be simulated as a log-normal process.

va ( int i, System.Matrix x, System.Matrix a ) : void

Vectorial version of method a.

Protected Methods

Method Description
DF ( double t, double dt ) : double

Numerically calculates the derivative of function F().

F ( double t, double dt ) : double

Numerically calculates the instantaneous forward rate.

Theta ( double t, double dt ) : double

Calculates the theta element of the Hull And White formula which will be stored in the theta in order to be used during simulation.

Private Methods

Method Description
BondHW2 ( Project context, SPCache cache, HW2Context hw2, double R, double u, double PT, double P_t, double Pdt, double TT, double t, double dt ) : double

Price of a zcb at t > 0 with maturity TT > t as a function of the rate R, of the factor u at t and of the current zr curve (ZR) using the Hull & White two-factor model

dr = (theta(t) + u - a * r) * dt + sigma1 * dz1 du = -b * du * dt + sigma2 * dz2 with dz1 * dz2 = rho * dt

(see Hull-White (1994) Journal of Derivatives).

CalculateInnerModelParameters ( ) : void

Calculates and caches the model parameters for use during the simulation.

DPhi ( double t, double dt ) : double

Calculates either the right numerical derivative or the central numerical derivative of Phi.

OnDeserialized ( StreamingContext context ) : void
Phi ( double t ) : double

Calculates the standard normal cumulative distribution function.

Preprocessing ( ) : void

Does a preliminary processing of all the parameters and required data which will be used during the simulation.

ZCB ( double t ) : double

Calculates the value of a Zero Coupon Bond.

Zr ( double t ) : double

Evaluates the referenced zr.

Method Details

Bond() public method

Calculates the value of a Bond under the Hull and White Two factors model.
public Bond ( IReadOnlyMatrixSlice dynamic, double dates, int i, double t, double s ) : double
dynamic IReadOnlyMatrixSlice /// The simulated process. ///
dates double /// The vector of reference dates. ///
i int /// The index at which the state variables must be sampled. ///
t double /// The date in years/fractions at at which the state variables must be sampled. ///
s double /// The maturity of the bond. ///
return double

DF() protected method

Numerically calculates the derivative of function F().
protected DF ( double t, double dt ) : double
t double /// Time at which calculate the derivative. ///
dt double /// Semi-interval to be used in the numerical derivative. ///
return double

ExportObjects() public method

Creates a list of all the sub-objects that can be edited.
public ExportObjects ( bool recursive ) : List
recursive bool /// The parameter is not used. ///
return List

F() protected method

Numerically calculates the instantaneous forward rate.
protected F ( double t, double dt ) : double
t double /// Time at which calculate the forward rate. ///
dt double /// Interval to be used in the numerical derivative. ///
return double

GetDeltaFactors() public method

Gets the factors for Delta Greek derivative.
public GetDeltaFactors ( ) : IModelParameter[]
return IModelParameter[]

GetVegaFactors() public method

Gets the factors for Vega Greek derivative.
public GetVegaFactors ( ) : IModelParameter[]
return IModelParameter[]

GetZeroRateReference() public method

Gets the zero rate reference.
public GetZeroRateReference ( ) : string
return string

HW2() public method

Initializes a new instance of the HullAndWhiteTwoFactors.HW2 class. This is the default constructor and sets the default values of several components of the model: * alpha 1 = 0.1 * sigma 1 = 0.001 * alpha 2 = 0.01 * sigma 2 = 0.001 * rho = 0.001 * No zero rate. * drift correction = 0.
public HW2 ( ) : System
return System

Parse() public method

Parses the data and ensures the parameters are correct.
public Parse ( IProject p_Context ) : bool
p_Context IProject /// The underlying project. ///
return bool

Populate() public method

Populate editable fields from name and value vectors specific to HW2.
public Populate ( string names, double values ) : void
names string /// An array with the names of the variable, /// will search for alpha1 (or a1), sigma1 (or sigma), alpha2 (or a2), sigma2 and rho. ///
values double The values associated to the parameters in names.
return void

SetZeroRateReference() public method

Associate the process to a zero rate defined in the Fairmat model (e.g. @zr1).
public SetZeroRateReference ( string zr ) : void
zr string /// The zero rate reference. ///
return void

Setup() public method

Called by Simulator after parse. Initializes here time-dependant but not state dependent variables.
public Setup ( double dates ) : void
dates double /// The dates at which the process realizations will be requested. ///
return void

Theta() protected method

Calculates the theta element of the Hull And White formula which will be stored in the theta in order to be used during simulation.
protected Theta ( double t, double dt ) : double
t double The position in which this value will be calculated.
dt double The delta between this t position and the previous one.
return double

a() public method

This function calculates the drift in the HW2 Markov process.
public a ( int i, double x, double a ) : void
i int The time step of the simulation.
x double The state vector at the previous state.
a double The drift,output of the function.
return void

ab() public method

public ab ( int i, double x, double a, double b ) : void
i int
x double
a double
b double
return void

b() public method

This function updates the volatility parameters (vector b) of the HW2 process.
public b ( int i, double x, double b ) : void
i int The parameter is not used.
x double The parameter is not used.
b double The output of the function.
return void

isLog() public method

Sets the passed array with a Booleans stating if the process components must be simulated as a log-normal process.
public isLog ( bool &isLog ) : void
isLog bool /// A reference to the array to be set with the required information. ///
return void

va() public method

Vectorial version of method a.
public va ( int i, System.Matrix x, System.Matrix a ) : void
i int The discrete time-step.
x System.Matrix The actual state matrix.
a System.Matrix The output drift matrix.
return void

Property Details

_a1 public property

Mean-reversion rate for r (short rate).
public IModelParameter _a1
return IModelParameter

_a2 public property

Volatility of r (short rate).
public IModelParameter _a2
return IModelParameter

_rho public property

Mean-reversion rate for u (latent component).
public IModelParameter _rho
return IModelParameter

_s1 public property

Mean-reversion rate for u (latent component).
public IModelParameter _s1
return IModelParameter

_s2 public property

Mean-reversion rate for r (short rate).
public IModelParameter _s2
return IModelParameter