Class BetaRiskSimulation
- Namespace
- NanoQL.Experimental
- Assembly
- NanoQL.dll
The simulation of a BetaRisk: each path's events arrive as a Poisson process over the period, each event's loss the maximum loss times a beta draw, X / (X + Y) of two gamma draws.
[Experimental("NQL0001")]
[WorkingType]
public sealed class BetaRiskSimulation : CatSimulation
- Inheritance
-
BetaRiskSimulation
- Inherited Members
Remarks
The draws are those of QuantLib built with MSVC 14.44, its oracle's standard library: a 32-bit Mersenne
Twister seeded with QuantLib's constant 5489, no parameter, as std::mt19937's default; each uniform from two
of its integers as MSVC's generate_canonical forms it, the first's top 21 bits and the second's 32, (g₀
>> 11) + (g₁ << 21) times 2⁻⁵³, truncating where the standard's form rounds; the exponential as −log(1 −
u)/λ; and the gamma by Knuth's published algorithms (TAOCP vol. 2, §3.4.1) in the order MSVC draws them:
Ahrens-Dieter's GS below α = 1, the exponential at α = 1, a product of uniforms for an integer α below 20, and
Ahrens' tangent method otherwise. They are written from those algorithms and this description of MSVC's behaviour;
the standard leaves a distribution's algorithm to the implementation.
The event times are the inter-arrival times cumulated, so the count is Poisson's and a path's dates ascend:
QuantLib's draws each event's time afresh, so its count is geometric, a mean of e^(λT) − 1 for λT (3.48 for 1.5 at a
two-year return period over three years), and its dates come unordered, which the notional path reads as ascending.
A path of one event or none is QuantLib's bit for bit up to the first path where QuantLib's next fresh draw falls
inside the period and the cumulated time doesn't; the streams part there (Divergences/BetaRiskTests.cs).
A working type: each simulation owns its generator, stepping it in place.
Constructors
BetaRiskSimulation(Date, Date, double, double, double, double)
Initializes a new instance of the BetaRiskSimulation class.
public BetaRiskSimulation(Date start, Date end, double maxLoss, double lambda, double alpha, double beta)
Parameters
startDateThe period's start.
endDateThe period's end.
maxLossdoubleThe maximum loss.
lambdadoubleThe events' rate, per year.
alphadoubleThe beta distribution's first parameter.
betadoubleThe beta distribution's second parameter.
Methods
GenerateBeta()
The next event's loss: the maximum loss times X / (X + Y), X and Y gamma draws of the beta distribution's parameters.
public double GenerateBeta()
Returns
- double
The loss.
NextPath(List<KeyValuePair<Date, double>>)
Writes the next path's events into a list, cleared first.
public override bool NextPath(List<KeyValuePair<Date, double>> path)
Parameters
pathList<KeyValuePair<Date, double>>The list the events are written into.