Class ClApsMprExposureSimulation
Classical model for the margin period of risk (MPR) including Classical+ and Classical- variants. The Classical+ variant of the model assumes that trade and asset flows continue during MPR, while margin flows stop. The Classical- variant assumes that no flows by either party take place during MPR.
Constructor(builder)
Create from the specified builder (freezes both the object and source data).
public ClApsMprExposureSimulation(ClApsMprExposureSimulationBuilder builder) : base(builder)
{
exposureID_ = builder.ExposureID;
underlyingExposure_ = builder.UnderlyingExposure;
cptyMarginDelta_ = builder.CptyMarginDelta;
ourMarginDelta_ = builder.OurMarginDelta;
cptyTradeDelta_ = builder.CptyTradeDelta;
ourTradeDelta_ = builder.OurTradeDelta;
measureMarginAtEndPointsOnly_ = builder.MeasureMarginAtEndPointsOnly;
if (ClDouble.Less(cptyMarginDelta_, ourMarginDelta_))
throw new ClEx("Counterparty margin delta must be the same or greater than our delta.");
if (ClDouble.Less(ourMarginDelta_, cptyTradeDelta_))
throw new ClEx("Our margin delta must be the same or greater than counterparty trade flows delta.");
if (ClDouble.Less(cptyTradeDelta_, ourTradeDelta_))
throw new ClEx("Counterparty trade flows delta must be the same or greater than our trade flows delta.");
if (ClDouble.Less(ourTradeDelta_, 0.0))
throw new ClEx("Our trade flows delta must be non-negative.");
}
Property ExposureID
(IClExposure) Unique exposure identifier.
public ClString ExposureID { get { return exposureID_; } }
Property Model
(IClExposure) Model for which exposure is calculated.
public IClModel Model { get { return underlyingExposure_.Model; } }
Method ExposureSlice(exposureTime, exposureSide)
(IClExposure) Slice of exposure at \(exposureTime\), defined to exclude any trade or margin flows occurring exactly at that time.\ On a grid with daily discretization, this corresponds to exposure being calculated at the end of day when all prescribed flows already occurred and are no longer subject to counterparty credit risk.
public ClDoubleArray ExposureSlice(double exposureTime, ClExposureSide exposureSide)
{
Dates when the counterparty and us stop paying margin flows.\
We assume that all flows were paid as prescribed in the past.
Accordingly, if either of these times is in the past, we use \(t=0\) instead.
double cptyMprStartTime = Math.Max(exposureTime - cptyMarginDelta_, 0.0);
double ourMprStartTime = Math.Max(exposureTime - ourMarginDelta_, 0.0);
double cptyTradeFlowsTo = Math.Max(exposureTime - cptyTradeDelta_, 0.0);
double ourTradeFlowsTo = Math.Max(exposureTime - ourTradeDelta_, 0.0);
Use ClRelativeExposure wrapper if the exposure object
does not implement an optimized version of IClRelativeExposure
IClRelativeExposure relativeExposureInterface = underlyingExposure_.AsRelativeExposure;
if (relativeExposureInterface == null)
{
ClRelativeExposureBuilder relativeExposureBuilder = new ClRelativeExposureBuilder();
relativeExposureBuilder.UnderlyingExposure = underlyingExposure_;
relativeExposureBuilder.MeasureMarginAtEndPointsOnly = measureMarginAtEndPointsOnly_;
relativeExposureInterface = relativeExposureBuilder.Build<IClRelativeExposure>();
}
Use IClRelativeExposure to compute relative value as this method may have a custom
implementation making it more accurate than subtracting two absolute exposures
ClDoubleArray valueDiff = relativeExposureInterface.MaxRelativeValue(cptyMprStartTime, ourMprStartTime, cptyTradeFlowsTo, ourTradeFlowsTo, exposureTime);
If value is null, exposure is zero irrespectively of side; null can be returned
if (valueDiff == null) return null;
Calculate exposure as positive or negative part of value
switch (exposureSide)
{
case ClExposureSide.Positive: return valueDiff.MaxWith(0.0);
case ClExposureSide.Negative: return valueDiff.MinWith(0.0);
case ClExposureSide.Value: return valueDiff;
case ClExposureSide.Empty: throw new ClEx("Empty value of exposureSide.");
default: throw new ClEx("Unknown value of exposureSide.");
}
}