39 for (
Size i=startIndex; i<endIndex; ++i)
50 if (forwardIndex < startIndex)
52 if (forwardIndex >= endIndex)
56 Real swapAnnuity =
annuity(cs, startIndex, endIndex,endIndex);
61 Real part1 = ratio*(numerator+1)/swapAnnuity;
62 Real part2 = numerator/(swapAnnuity*swapAnnuity);
65 part2 *= ratio*
annuity(cs, startIndex, forwardIndex, endIndex);
76 const std::vector<Time>& tau = cs.
rateTaus();
79 std::vector<Real> a(
n);
80 for (
Size k=0; k<
n; ++k)
85 for (
Size i=0; i<
n; ++i) {
86 for (
Size j=i; j<
n; ++j) {
93 tau[j]/(1.0+
f[j]*tau[j]) *
95 (-a[j]*bi+a[i]*bj)/(bi*bi);
103 const Spread displacement) {
108 for (
Size i=0; i<
n; ++i)
109 for (
Size j=i; j<
n; ++j)
110 zMatrix[i][j] *= (
f[j]+displacement)/(sr[i]+displacement);
120 for (
Size i=0; i<
n; ++i)
121 for (
Size j=0; j<
n; ++j)
128 const Size spanningForwards)
133 for (
Size i=0; i<
n; ++i)
134 for (
Size j=0; j<
n; ++j)
135 jacobian[i][j] =
swapDerivative(cs, i, std::min(
n,i+spanningForwards), j);
141 const Spread displacement)
146 std::vector<Rate> sr(
n);
148 for (
Size i=0; i<
n; ++i)
151 for (
Size i=0; i<
n; ++i)
152 for (
Size j=i; j<
n; ++j)
153 zMatrix[i][j] *= (
f[j]+displacement)/(sr[i]+displacement);
158 const Size spanningForwards,
159 const Spread displacement)
164 std::vector<Rate> sr(
n);
166 for (
Size i=0; i<
n; ++i)
169 for (
Size i=0; i<
n; ++i)
170 for (
Size j=i; j<
n; ++j)
171 zMatrix[i][j] *= (
f[j]+displacement)/(sr[i]+displacement);
179 QL_REQUIRE(startIndex < endIndex,
"start index must be before end index in swaptionImpliedVolatility");
197 Real thisVariance =0.0;
199 for (
Size f=0;
f < factors; ++
f)
203 for (
Size j=startIndex; j < endIndex;++j)
205 sum += cmsZed[startIndex][j]*thisPseudo[j][
f];
208 thisVariance += sum*sum;
Curve state for market-model simulations
Size numberOfRates() const
virtual Rate coterminalSwapAnnuity(Size numeraire, Size i) const =0
virtual Rate cmSwapRate(Size i, Size spanningForwards) const =0
virtual Rate forwardRate(Size i) const =0
virtual const std::vector< Rate > & coterminalSwapRates() const =0
virtual const std::vector< Rate > & forwardRates() const =0
const std::vector< Time > & rateTaus() const
virtual Real discountRatio(Size i, Size j) const =0
Market-model evolution description.
const std::vector< Time > & rateTimes() const
Size numberOfSteps() const
const std::vector< Size > & firstAliveRate() const
Curve state for Libor market models
void setOnForwardRates(const std::vector< Rate > &fwdRates, Size firstValidIndex=0)
base class for market models
virtual Size numberOfFactors() const =0
virtual const std::vector< Rate > & initialRates() const =0
virtual const Matrix & pseudoRoot(Size i) const =0
virtual const EvolutionDescription & evolution() const =0
virtual const std::vector< Spread > & displacements() const =0
Matrix used in linear algebra.
static Matrix coinitialSwapZedMatrix(const CurveState &cs, Spread displacement)
static Matrix coterminalSwapZedMatrix(const CurveState &cs, Spread displacement)
static Matrix cmSwapZedMatrix(const CurveState &cs, Size spanningForwards, Spread displacement)
static Real swaptionImpliedVolatility(const MarketModel &volStructure, Size startIndex, Size endIndex)
static Real swapDerivative(const CurveState &cs, Size startIndex, Size endIndex, Size forwardIndex)
compute derivative of swap-rate to underlying forward rate
static Matrix coinitialSwapForwardJacobian(const CurveState &cs)
static Real annuity(const CurveState &cs, Size startIndex, Size endIndex, Size numeraireIndex)
compute annuity of arbitrary swap-rate
static Matrix cmSwapForwardJacobian(const CurveState &cs, Size spanningForwards)
static Matrix coterminalSwapForwardJacobian(const CurveState &cs)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
LinearInterpolation variance
Real Spread
spreads on interest rates
std::size_t Size
size of a container
Utility functions for mapping between swap rate and forward rate.