Class MCVanillaEngine<TMc, TPath, TStats>
- Namespace
- NanoQL.PricingEngines
- Assembly
- NanoQL.dll
The base of the Monte Carlo engines for vanilla options: a time grid to the last exercise, paths of the process on it, and a control variate's value from a control engine.
public abstract class MCVanillaEngine<TMc, TPath, TStats> : McSimulation<TPath, TStats> where TMc : IMcTraits<TPath> where TStats : IStatistics, new()
Type Parameters
TMcThe Monte Carlo traits, QuantLib's
MC<RNG>: the path type and its generator.TPathThe path type.
TStatsThe statistics accumulator.
- Inheritance
-
McSimulation<TPath, TStats>MCVanillaEngine<TMc, TPath, TStats>
- Inherited Members
Remarks
An extension point and an immutable object (over McSimulation<TPath, TStats>): a concrete engine's
static Calculate builds one per call from the option, the context, the process and QuantLib's settings, with
QuantLib's constructor checks, implements the path pricer, and reads Run()'s model and results. The
vanilla option is its only instrument, as in every QuantLib instantiation. The control variate's value comes from
ControlPricingEngine(), an engine delegate of the engines' form, on the option.
The process is the engine's: the Black-Scholes engines pass the process on their clock, whose times run from the earliest structure's reference date, so TimeGrid()'s times are that clock's.
Constructors
MCVanillaEngine(VanillaOption, EvaluationContext, StochasticProcess, int?, int?, bool, bool, bool, int?, double?, int?, long)
Initializes a new instance of the MCVanillaEngine<TMc, TPath, TStats> class.
protected MCVanillaEngine(VanillaOption option, EvaluationContext context, StochasticProcess process, int? timeSteps, int? timeStepsPerYear, bool brownianBridge, bool antitheticVariate, bool controlVariate, int? requiredSamples, double? requiredTolerance, int? maxSamples, long seed)
Parameters
optionVanillaOptionThe option.
contextEvaluationContextThe evaluation context.
processStochasticProcessThe process the paths follow.
timeStepsint?The number of time steps, or null for steps per year.
timeStepsPerYearint?The number of time steps per year, or null for a number of steps.
brownianBridgeboolWhether the draws are ordered by a Brownian bridge.
antitheticVariateboolWhether antithetic variates are used.
controlVariateboolWhether a control variate is used.
requiredSamplesint?The number of samples, or null.
requiredTolerancedouble?The absolute tolerance, or null; it takes precedence.
maxSamplesint?The most samples for a tolerance, or null for no limit.
seedlongThe seed, in [1, 4294967295].
Exceptions
- ArgumentNullException
The option, the context or the process is null.
- ArgumentException
Neither or both of the time steps and the time steps per year are given, or the one given isn't positive.
- ArgumentOutOfRangeException
requiredSamplesormaxSamplesis negative, orseedis outside its range.
Properties
BrownianBridge
Gets a value indicating whether the draws are ordered by a Brownian bridge.
protected bool BrownianBridge { get; }
Property Value
Context
Gets the evaluation context.
protected EvaluationContext Context { get; }
Property Value
MaxSamples
Gets the most samples for a tolerance, or null for no limit.
protected int? MaxSamples { get; }
Property Value
- int?
Option
Gets the option, QuantLib's engine arguments.
protected VanillaOption Option { get; }
Property Value
Process
Gets the process the paths follow.
protected StochasticProcess Process { get; }
Property Value
RequiredSamples
Gets the number of samples, or null.
protected int? RequiredSamples { get; }
Property Value
- int?
RequiredTolerance
Gets the absolute tolerance, or null.
protected double? RequiredTolerance { get; }
Property Value
Seed
Gets the seed.
protected long Seed { get; }
Property Value
TimeSteps
Gets the number of time steps, or null.
protected int? TimeSteps { get; }
Property Value
- int?
TimeStepsPerYear
Gets the number of time steps per year, or null.
protected int? TimeStepsPerYear { get; }
Property Value
- int?
Methods
ControlPricingEngine()
The control variate's engine, QuantLib's controlPricingEngine(); by default none.
protected virtual Func<VanillaOption, EvaluationContext, OneAssetOptionResults>? ControlPricingEngine()
Returns
- Func<VanillaOption, EvaluationContext, OneAssetOptionResults>
The engine, or null.
ControlVariateValue()
The control variate's value: the control engine's NPV on the option.
protected override double? ControlVariateValue()
Returns
- double?
The value.
Exceptions
- NanoQLException
The engine gives no control engine, or its NPV.
PathGenerator()
The path generator: the traits' sequence generator, of the process's factors per step, and paths on the grid.
protected override IPathGenerator<TPath> PathGenerator()
Returns
- IPathGenerator<TPath>
A new path generator.
Run()
QuantLib's calculate: runs the simulation and returns its model and QuantLib's results, the mean as the
value and, where the traits allow one, the error estimate.
protected (MonteCarloModel<TPath, TStats> Model, OneAssetOptionResults Results) Run()
Returns
- (MonteCarloModel<TPath, TStats> Model, OneAssetOptionResults Results)
The call's model and results.
Exceptions
- NanoQLException
The simulation refuses, or the samples can't reach the tolerance.
TimeGrid()
The time grid: to the last exercise, in the steps given or the steps per year, at least one.
protected override TimeGrid TimeGrid()
Returns
- TimeGrid
The grid.
Exceptions
- NanoQLException
No steps are given.