19#ifndef quantlib_randomloss_latent_model_hpp
20#define quantlib_randomloss_latent_model_hpp
35 template<
class ,
class >
class RandomLossLM;
36 template<
class copulaPolicy,
class USNG>
39 : nameIdx(
n), dayFromRef(
d),
41 compactRR(
std::lround(
r/rrGranular)) {}
49 return dayFromRef < evt.dayFromRef;
56 return rrGranular * compactRR;
63 template <
class C,
class G>
const Real
70 template<
class copulaPolicy,
class USNG = SobolRsg>
76 const ext::shared_ptr<SpotRecoveryLatentModel<copulaPolicy> >
copula_;
84 Real accuracy = 1.e-6,
87 (copula->numFactors(), copula->size(), copula->copula(),
104 void
nextSample(const std::vector<Real>& values) const;
115 const ext::shared_ptr<Pool>& pool = this->
basket_->pool();
116 for(
Size iName=0; iName < this->
basket_->size(); ++iName)
117 horizonDefaultPs_.push_back(pool->get(pool->names()[iName]).
118 defaultProbability(this->
basket_->defaultKeys()[iName])
119 ->defaultProbability(maxHorizonDate,
true));
122 return evt.recovery();
127 return copula_->latentVarValue(factorsSample, iVar);
132 const Date&
d)
const;
142 "Incompatible basket and model sizes.");
156 template<
class C,
class URNG>
158 const std::vector<Real>& values)
const
160 const ext::shared_ptr<Pool>& pool = this->basket_->pool();
161 this->simsBuffer_.push_back(std::vector<defaultSimEvent> ());
164 for(
Size iName=0; iName<copula_->size()/2; iName++) {
173 Real latentVarSample =
174 copula_->latentVarValue(values, iName);
176 copula_->cumulativeY(latentVarSample, iName);
178 if (horizonDefaultPs_[iName] >= simDefaultProb) {
180 pool->get(pool->names()[iName]).
181 defaultProbability(this->basket_->defaultKeys()[iName]);
186 detail::Root(dfts, simDefaultProb), accuracy_, 0., 1.));
208 if(eventDate<dfts->referenceDate())
209 eventDate = dfts->referenceDate();
210 Real latentRRVarSample =
211 copula_->latentRRVarValue(values, iName);
213 copula_->conditionalRecovery(latentRRVarSample,
215 this->simsBuffer_.back().push_back(
basket of issuers and related notionals
RelinkableHandle< Basket > basket_
Shared handle to an observable.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
static const Size maxHorizon_
void nextSample(const std::vector< Real > &values) const
simEvent< RandomLossLM > defaultSimEvent
std::vector< Probability > horizonDefaultPs_
Real conditionalRecovery(Real latentVarSample, Size iName, const Date &d) const
void resetModel() override
Concrete models do now any updates/inits they need on basket reset.
Real latentVarValue(const std::vector< Real > &factorsSample, Size iVar) const
const ext::shared_ptr< SpotRecoveryLatentModel< copulaPolicy > > copula_
Real getEventRecovery(const defaultSimEvent &evt) const
DateProxy & evaluationDate()
the date at which pricing is to be performed.
static Settings & instance()
access to the unique instance
Real solve(const F &f, Real accuracy, Real guess, Real step) const
Random spot recovery rate latent variable portfolio model.
Utility for the numerical time solver.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
QL_INTEGER Integer
integer number
Real Probability
probability
std::size_t Size
size of a container
Generic multifactor latent variable model.
RandomLossLM< TCopulaPolicy > TRandomLossLM
RandomLossLM< GaussianCopulaPolicy > GaussianRandomLossLM
unsigned QL_BIG_INTEGER BigNatural
large positive integer
ext::shared_ptr< YieldTermStructure > r
bool operator<(const simEvent &evt) const
simEvent(unsigned int n, unsigned int d, Real r)
static const Real rrGranular