C# Class HullAndWhiteOneFactor.HW1

Inheritance: IExtensibleProcessIR, IZeroRateReference, IMarkovSimulator, IParsable, IEstimationResultPopulable, IGreeksDerivativesInfo, IOpenCLCode, IPostSimulationTransformation, IExportableContainer
Show file Open project: fairmat/InterestRatesModels Class Usage Examples

Protected Properties

Property Type Description
alpha1 IModelParameter
sigma1 IModelParameter

Private Properties

Property Type Description
A double
AlphaInt double
B double
ExpectedAverageRate double
OnDeserialized void
ZR double

Public Methods

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

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

ExpectedShortRate ( double t ) : double
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.

HW1 ( ) : System

Initializes a new instance of the HW1 class with alpha 0.1, sigma 0.001 and an empty zeroRateReference.

HW1 ( double alpha, double sigma, double lambda, string zeroRateReference ) : System

Initializes a new instance of the HW1 class given alpha, sigma, lambda and a zero rate reference.

HW1 ( double alpha, double sigma, string zeroRateReference ) : System

Initializes a new instance of the HW1 class given alpha, sigma and a zero rate reference.

Parse ( IProject p_Context ) : bool

Ensure the parameters are correct.

Populate ( IStochasticProcess stocProcess, EstimationResult estimate ) : void

Populate editable fields from name and value vectors specific to the Heston extended process.

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.

Simulate ( double Dates, IReadOnlyMatrixSlice Noise, IMatrixSlice OutDynamic ) : void
Transform ( double dates, IMatrixSlice outDynamic ) : void

Handles the conversion, after the simulation, from y to the short rate r.

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

This function defines the drift in the HW Markov process. The formula to calculate the A component is A = theta(t) - alpha * previous State.

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

This function defines drift and the volatility in the HW Markov process. The formula to calculate the B component is A = theta(t) - alpha * previous State. B = sigma.

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

This function defines the volatility in the HW Markov process. The formula to calculate the B component is B = sigma.

isLog ( bool &isLog ) : void

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

Protected Methods

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

Numerically calculates the instantaneous forward rate.

Ft ( double t, double dt ) : double

First derivative w.r.t time of forward rate

alphaTFunc ( double t, double dt ) : double

Calculates the value of alpha function at time t

theta ( double t, double dt ) : double

Private Methods

Method Description
A ( double t, double T, double alpha, double sigma, System.Function zeroRateCurve ) : double

Calculates the function A() to be used in the Bond() method.

AlphaInt ( double t, double T, double alpha, double sigma, System.Function zeroRateCurve ) : double

Calculates the integral of alpha function to be used in the A() method.

B ( double T, double alpha ) : double

Calculates the function B() to be used in the Bond() method.

ExpectedAverageRate ( double t ) : double
OnDeserialized ( StreamingContext context ) : void
ZR ( double t ) : double

Helper function to make functions easier to read. Just returns the value of the zero rate at position t.

Method Details

Bond() public method

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

ExpectedShortRate() public method

public ExpectedShortRate ( double t ) : double
t double
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

Ft() protected method

First derivative w.r.t time of forward rate
protected Ft ( double t, double dt ) : double
t double
dt double
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

HW1() public method

Initializes a new instance of the HW1 class with alpha 0.1, sigma 0.001 and an empty zeroRateReference.
public HW1 ( ) : System
return System

HW1() public method

Initializes a new instance of the HW1 class given alpha, sigma, lambda and a zero rate reference.
public HW1 ( double alpha, double sigma, double lambda, string zeroRateReference ) : System
alpha double The rate of the mean reversion to be used to initialize HW.
sigma double The standard deviation to be used to initialize HW.
lambda double The market price of risk to be used to initialize HW.
zeroRateReference string /// Reference to the zero rate to be used to initialize HW. ///
return System

HW1() public method

Initializes a new instance of the HW1 class given alpha, sigma and a zero rate reference.
public HW1 ( double alpha, double sigma, string zeroRateReference ) : System
alpha double The rate of the mean reversion to be used to initialize HW.
sigma double The standard deviation to be used to initialize HW.
zeroRateReference string /// Reference to the zero rate to be used to initialize HW. ///
return System

Parse() public method

Ensure 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 the Heston extended process.
public Populate ( IStochasticProcess stocProcess, EstimationResult estimate ) : void
stocProcess IStochasticProcess /// The stochastic process which is being referenced to. ///
estimate EstimationResult /// The estimation result which contains values and names of parameters. /// It will be searched for S0, kappa, theta, sigma, V0 and rho. ///
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

Simulate() public method

public Simulate ( double Dates, IReadOnlyMatrixSlice Noise, IMatrixSlice OutDynamic ) : void
Dates double
Noise IReadOnlyMatrixSlice
OutDynamic IMatrixSlice
return void

Transform() public method

Handles the conversion, after the simulation, from y to the short rate r.
public Transform ( double dates, IMatrixSlice outDynamic ) : void
dates double Simulation dates.
outDynamic IMatrixSlice The input and output components of the transformation.
return void

a() public method

This function defines the drift in the HW Markov process. The formula to calculate the A component is A = theta(t) - alpha * previous State.
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 output of the function.
return void

ab() public method

This function defines drift and the volatility in the HW Markov process. The formula to calculate the B component is A = theta(t) - alpha * previous State. B = sigma.
public ab ( int i, double x, double a, double b ) : void
i int The time step of the simulation.
x double The state vector at the previous state.
a double The output state dependent drift.
b double The output volatility.
return void

alphaTFunc() protected method

Calculates the value of alpha function at time t
protected alphaTFunc ( double t, double dt ) : double
t double Time at which calculate alpha
dt double
return double

b() public method

This function defines the volatility in the HW Markov process. The formula to calculate the B component is B = sigma.
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 Boolean stating if the process 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

theta() protected method

protected theta ( double t, double dt ) : double
t double
dt double
return double

Property Details

alpha1 protected property

Rate of mean reversion.
protected IModelParameter alpha1
return IModelParameter

sigma1 protected property

Standard deviation.
protected IModelParameter sigma1
return IModelParameter