Class MCLongstaffSchwartzEngine<TOption, TMc, TMcCalibration, TPath, TState, TStats>
- Namespace
- NanoQL.PricingEngines
- Assembly
- NanoQL.dll
The Longstaff-Schwartz Monte Carlo engine for early-exercise options (Francis Longstaff, Eduardo Schwartz, 2001, "Valuing American Options by Simulation: A Simple Least-Squares Approach", The Review of Financial Studies, Volume 14, No. 1, 113-147): a calibration simulation whose paths the Longstaff-Schwartz pricer regresses, then the pricing simulation on the same pricer.
public abstract class MCLongstaffSchwartzEngine<TOption, TMc, TMcCalibration, TPath, TState, TStats> : McSimulation<TPath, TStats> where TOption : Option where TMc : IMcTraits<TPath> where TMcCalibration : IMcTraits<TPath> where TStats : IStatistics, new()
Type Parameters
TOptionThe option, QuantLib's
GenericEngine's instrument.TMcThe pricing simulation's Monte Carlo traits, QuantLib's
MC<RNG>.TMcCalibrationThe calibration's traits, QuantLib's
MC<RNG_Calibration>.TPathThe path type.
TStateThe early-exercise pricer's state type, which QuantLib's traits name for the path type.
TStatsThe statistics accumulator.
- Inheritance
-
McSimulation<TPath, TStats>MCLongstaffSchwartzEngine<TOption, TMc, TMcCalibration, TPath, TState, TStats>
- Inherited Members
Remarks
An extension point and an immutable object: a concrete engine's static Calculate builds one per call and
implements LsmPathPricer(). Run() builds the pricer, adds the calibration samples on the
calibration traits' generator, calibrates, prices on the same pricer and returns the model with the call's exercise
probability: QuantLib's mutable pricer and calibration model are the call's working state, and the pricer reaches
the pricing model as the call's argument, not as a member, so two calls can share one engine object.
The calibration samples default to 2,048, and the calibration's Brownian bridge and antithetic variates to the
pricing's. The calibration seed defaults to the pricing seed plus 1,768,237,423, modulo 2³² as MSVC's 32-bit
unsigned long computes it, as QuantLib's documentation says; QuantLib's code compares the narrowed
Null<Size>() with Null<Real>(), so its default is always the narrowed null: a
documented divergence (Divergences/LongstaffSchwartzCalibrationSeedTests.cs); QuantLib's engine with that
seed passed reproduces this one's default. Where that default is 0, at the pricing seed 2,526,729,873, it is
refused, since QuantLib reads 0 as a seed from the clock.
The pricer exercises only at the exercise times on the grid (ExerciseTimes(TimeGrid)): a Bermudan option's dates, and an American option's grid times from its earliest exercise.
Constructors
MCLongstaffSchwartzEngine(TOption, EvaluationContext, StochasticProcess, int?, int?, bool, bool, bool, int?, double?, int?, long, int?, bool?, bool?, long?)
Initializes a new instance of the MCLongstaffSchwartzEngine<TOption, TMc, TMcCalibration, TPath, TState, TStats> class.
protected MCLongstaffSchwartzEngine(TOption option, EvaluationContext context, StochasticProcess process, int? timeSteps, int? timeStepsPerYear, bool brownianBridge, bool antitheticVariate, bool controlVariate, int? requiredSamples, double? requiredTolerance, int? maxSamples, long seed, int? nCalibrationSamples = null, bool? brownianBridgeCalibration = null, bool? antitheticVariateCalibration = null, long? seedCalibration = null)
Parameters
optionTOptionThe 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 pricing draws are ordered by a Brownian bridge.
antitheticVariateboolWhether the pricing uses antithetic variates.
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 pricing seed, in [1, 4294967295].
nCalibrationSamplesint?The calibration samples, or null for 2,048.
brownianBridgeCalibrationbool?The calibration's Brownian bridge, or null for the pricing's.
antitheticVariateCalibrationbool?The calibration's antithetic variates, or null for the pricing's.
seedCalibrationlong?The calibration seed, in [1, 4294967295], or null for (
seed+ 1768237423) mod 2³².
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
A number of samples is negative, a seed is outside its range, or the default calibration seed is 0.
Properties
AntitheticVariateCalibration
Gets a value indicating whether the calibration uses antithetic variates.
protected bool AntitheticVariateCalibration { get; }
Property Value
BrownianBridge
Gets a value indicating whether the pricing draws are ordered by a Brownian bridge.
protected bool BrownianBridge { get; }
Property Value
BrownianBridgeCalibration
Gets a value indicating whether the calibration draws are ordered by a Brownian bridge.
protected bool BrownianBridgeCalibration { 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?
NCalibrationSamples
Gets the number of calibration samples.
protected int NCalibrationSamples { get; }
Property Value
Option
Gets the option, QuantLib's engine arguments.
protected TOption Option { get; }
Property Value
- TOption
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 pricing seed.
protected long Seed { get; }
Property Value
SeedCalibration
Gets the calibration seed.
protected long SeedCalibration { 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
ExerciseTimes(TimeGrid)
The grid's exercise times, beside its last, for the Longstaff-Schwartz pricer: a Bermudan option's exercise times after the start, and an American option's grid times from its earliest exercise.
protected IReadOnlyList<double> ExerciseTimes(TimeGrid grid)
Parameters
gridTimeGridThe grid.
Returns
- IReadOnlyList<double>
The times.
LsmPathPricer()
The Longstaff-Schwartz pricer of this call, new.
protected abstract LongstaffSchwartzPathPricer<TPath, TState> LsmPathPricer()
Returns
- LongstaffSchwartzPathPricer<TPath, TState>
The pricer.
PathGenerator()
The pricing simulation's path generator: the traits' generator of the process's factors per step.
protected override IPathGenerator<TPath> PathGenerator()
Returns
- IPathGenerator<TPath>
A new path generator.
PathPricer()
QuantLib's pathPricer(), which returns the pricer its calculate stored: Run() passes
the call's calibrated pricer to the pricing model, so outside it there is none.
protected override PathPricer<TPath> PathPricer()
Returns
- PathPricer<TPath>
Nothing: it throws.
Exceptions
- NanoQLException
Always ("path pricer unknown").
Run()
QuantLib's calculate: the calibration simulation, the regression and the pricing simulation on the same
Longstaff-Schwartz pricer.
protected (MonteCarloModel<TPath, TStats> Model, double ExerciseProbability) Run()
Returns
- (MonteCarloModel<TPath, TStats> Model, double ExerciseProbability)
The pricing model and the call's exercise probability.
Exceptions
- NanoQLException
The simulation refuses, or the samples can't reach the tolerance.
TimeGrid()
The time grid: to an American option's last exercise, or through a Bermudan's exercise times after the start, in the steps given or the steps per year of the last time, at least one.
protected override TimeGrid TimeGrid()
Returns
- TimeGrid
The grid.
Exceptions
- NanoQLException
No exercise time lies after the start, or no steps are given.