43 const ext::shared_ptr<PiecewiseConstantCorrelation>& corr,
45 displacedSwapVariances,
46 const std::vector<Volatility>& capletVols,
47 const ext::shared_ptr<CurveState>& cs,
49 Real caplet0Swaption1Priority,
54 Size maxUnperiodicIterations,
55 Real toleranceUnperiodic,
56 Size maxPeriodIterations,
59 Real& totalSwaptionError,
60 std::vector<Matrix>& swapCovariancePseudoRoots,
61 std::vector<Real> & finalScales,
63 Real& errorImprovement,
64 Matrix& modelSwaptionVolsMatrix
71 QL_REQUIRE( numberSmallSteps == numberSmallRates,
72 "periodic calibration class requires evolution to the reset of each rate");
74 Size numberBigRates = numberSmallRates/period;
75 Size offset = numberSmallRates % period;
77 std::vector<Spread> newDisplacements(numberBigRates,displacement);
80 "mismatch between number of swap variances given and number of rates and period");
85 std::vector<Real> scalingFactors(numberBigRates);
86 for (
Size i=0; i < numberBigRates; ++i)
87 scalingFactors[i] =1.0;
92 std::vector<Real> marketSwaptionVols(numberBigRates);
93 for (
Size i=0; i < numberBigRates; ++i) {
94 marketSwaptionVols[i] =
98 std::vector<Real> modelSwaptionVols(numberBigRates);
100 Real periodSwaptionRmsError;
104 Real previousError = 1.0e+10;
107 modelSwaptionVolsMatrix =
Matrix(maxPeriodIterations,numberBigRates,0.0);
122 caplet0Swaption1Priority);
126 unperiodicCalibrator.
calibrate(numberOfFactors, maxUnperiodicIterations,
127 toleranceUnperiodic, max1dIterations, tolerance1d));
131 ext::shared_ptr<MarketModel> smm(
new
134 cs->coterminalSwapRates(),
135 std::vector<Spread>(evolution.
numberOfRates(), displacement)));
139 Matrix capletTotCovariance = flmm->totalCovariance(numberSmallRates-1);
148 Matrix swaptionTotCovariance(periodsmm->totalCovariance(periodsmm->numberOfSteps()-1));
152 totalSwaptionError=0.0;
154 for (
Size i=0; i < numberBigRates; ++i)
156 modelSwaptionVols[i] = std::sqrt(swaptionTotCovariance[i][i]/periodsmm->evolution().rateTimes()[i]);
157 Real scale = marketSwaptionVols[i]/modelSwaptionVols[i];
158 scalingFactors[i] *= scale;
160 totalSwaptionError += (marketSwaptionVols[i]-modelSwaptionVols[i])* (marketSwaptionVols[i]-modelSwaptionVols[i]);
164 for (
Size i=0; i < numberBigRates; ++i)
165 modelSwaptionVolsMatrix[iterationsDone][i] = modelSwaptionVols[i];
167 periodSwaptionRmsError = std::sqrt(totalSwaptionError/numberBigRates);
168 errorImprovement = previousError -periodSwaptionRmsError;
169 previousError = periodSwaptionRmsError;
171 while (errorImprovement> periodTolerance/10.0 && periodSwaptionRmsError >periodTolerance && ++iterationsDone < maxPeriodIterations);
173 finalScales = scalingFactors;
bool calibrate(Natural numberOfFactors, Natural maxIterations, Real tolerance, Natural innerMaxIterations=100, Real innerTolerance=1e-8)
const std::vector< Matrix > & swapPseudoRoots() const
Market-model evolution description.
Size numberOfRates() const
const std::vector< Time > & rateTimes() const
Size numberOfSteps() const
Matrix used in linear algebra.
virtual void setLastCapletVol(Real vol)=0
virtual Size getNoBigRates() const =0
virtual void setScalingFactors(const std::vector< Real > &scales)=0
virtual const std::vector< ext::shared_ptr< PiecewiseConstantVariance > > & originalVariances() const =0
virtual const std::vector< ext::shared_ptr< PiecewiseConstantVariance > > & interpolatedVariances() const =0
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
QL_INTEGER Integer
integer number
Real Spread
spreads on interest rates
std::size_t Size
size of a container
matrix used in linear algebra.
Integer capletSwaptionPeriodicCalibration(const EvolutionDescription &evolution, const ext::shared_ptr< PiecewiseConstantCorrelation > &corr, VolatilityInterpolationSpecifier &displacedSwapVariances, const std::vector< Volatility > &capletVols, const ext::shared_ptr< CurveState > &cs, const Spread displacement, Real caplet0Swaption1Priority, Size numberOfFactors, Size period, Size max1dIterations, Real tolerance1d, Size maxUnperiodicIterations, Real toleranceUnperiodic, Size maxPeriodIterations, Real periodTolerance, Real &, Real &totalSwaptionError, std::vector< Matrix > &swapCovariancePseudoRoots, std::vector< Real > &finalScales, Size &iterationsDone, Real &errorImprovement, Matrix &modelSwaptionVolsMatrix)
Maps shared_ptr to either the boost or std implementation.