38 "integrations bounds (" << t1 <<
39 "," << t2 <<
") are in reverse order");
40 Time cutOff = std::min(
S,
T);
44 cutOff = std::min(t2, cutOff);
45 return (cutOff - t1)*v1*v2;
50 const vector<Volatility>& vols,
51 const ext::shared_ptr<PiecewiseConstantCorrelation>& corr,
54 const vector<Rate>& initialRates,
55 const vector<Spread>& displacements)
56 : numberOfFactors_(numberOfFactors),
57 numberOfRates_(initialRates.size()),
58 numberOfSteps_(evolution.evolutionTimes().size()),
59 initialRates_(initialRates),
60 displacements_(displacements),
61 evolution_(evolution),
62 pseudoRoots_(numberOfSteps_,
Matrix(numberOfRates_, numberOfFactors_))
73 ") and vols (" << vols.size() <<
")");
80 ") cannot be greater than numberOfRates (" <<
84 ") must be greater than zero");
86 Time effStopTime = 0.0;
87 const vector<Time>& corrTimes = corr->times();
96 for (; corrTimes[kk]<evolTimes[k]; ++kk) {
97 Time effStartTime = effStopTime;
98 effStopTime = corrTimes[kk];
99 const Matrix& corrMatrix = corr->correlation(kk);
103 rateTimes[i], rateTimes[j],
110 Time effStartTime = effStopTime;
111 effStopTime = evolTimes[k];
112 const Matrix& corrMatrix = corr->correlation(kk);
116 rateTimes[i], rateTimes[j],
122 while (kk<corrTimes.size() && corrTimes[kk]<=evolTimes[k])
138 <<
" flat vol wrong number of rows: "
143 <<
" flat vol wrong number of columns: "
153 vector<Volatility> vols,
156 : longTermCorrelation_(longTermCorrelation), beta_(
beta), times_(
std::move(times)),
157 vols_(
std::move(vols)), yieldCurve_(
std::move(yieldCurve)), displacement_(displacement) {
164 ext::shared_ptr<MarketModel>
166 Size numberOfFactors)
const {
167 const vector<Time>& rateTimes = evolution.
rateTimes();
168 Size numberOfRates = rateTimes.size()-1;
170 vector<Rate> initialRates(numberOfRates);
171 for (
Size i=0; i<numberOfRates; ++i)
172 initialRates[i] =
yieldCurve_->forwardRate(rateTimes[i],
176 vector<Volatility> displacedVolatilities(numberOfRates);
177 for (
Size i=0; i<numberOfRates; ++i) {
180 displacedVolatilities[i] =
189 ext::shared_ptr<PiecewiseConstantCorrelation> corr(
new
192 return ext::shared_ptr<MarketModel>(
new
Market-model evolution description.
const std::vector< Time > & rateTimes() const
const std::vector< Time > & evolutionTimes() const
Real longTermCorrelation_
Interpolation volatility_
std::vector< Time > times_
FlatVolFactory(Real longTermCorrelation, Real beta, std::vector< Time > times, std::vector< Volatility > vols, Handle< YieldTermStructure > yieldCurve, Spread displacement)
std::vector< Volatility > vols_
Handle< YieldTermStructure > yieldCurve_
ext::shared_ptr< MarketModel > create(const EvolutionDescription &, Size numberOfFactors) const override
const std::vector< Spread > & displacements() const override
std::vector< Matrix > pseudoRoots_
FlatVol(const std::vector< Volatility > &volatilities, const ext::shared_ptr< PiecewiseConstantCorrelation > &corr, const EvolutionDescription &evolution, Size numberOfFactors, const std::vector< Rate > &initialRates, const std::vector< Spread > &displacements)
const EvolutionDescription & evolution() const override
Size numberOfFactors() const override
Shared handle to an observable.
Linear interpolation between discrete points
virtual const Matrix & covariance(Size i) const
Matrix used in linear algebra.
const_iterator begin() const
const_iterator end() const
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
exponential correlation matrix
Real Time
continuous quantity with 1-year units
Real Volatility
volatility
Real Spread
spreads on interest rates
std::size_t Size
size of a container
linear interpolation between discrete points
Real flatVolCovariance(Time t1, Time t2, Time T, Time S, Volatility v1, Volatility v2)
Matrix exponentialCorrelations(const std::vector< Time > &rateTimes, Real longTermCorr, Real beta, Real gamma, Time time)
Matrix rankReducedSqrt(const Matrix &matrix, Size maxRank, Real componentRetainedPercentage, SalvagingAlgorithm::Type sa)
pseudo square root of a real symmetric matrix