27 : numberOfRates_(rateTimes.empty() ? 0 : rateTimes.size()-1),
28 rateTimes_(rateTimes), rateTaus_(numberOfRates_) {
35 QL_REQUIRE(end > begin,
"empty range specified");
39 for (
Size i=begin; i<end; ++i)
46 const std::vector<DiscountFactor>& ds,
47 const std::vector<Time>& taus,
48 std::vector<Rate>& fwds) {
50 "taus.size()!=fwds.size()");
52 "ds.size()!=fwds.size()+1");
54 for (
Size i=firstValidIndex; i<fwds.size(); ++i)
55 fwds[i] = (ds[i]-ds[i+1])/(ds[i+1]*taus[i]);
59 const Size firstValidIndex,
60 const std::vector<DiscountFactor>& discountFactors,
61 const std::vector<Time>& taus,
62 std::vector<Rate>& cotSwapRates,
63 std::vector<Real>& cotSwapAnnuities)
65 Size nCotSwapRates = cotSwapRates.size();
67 "taus.size()!=cotSwapRates.size()");
68 QL_REQUIRE(cotSwapAnnuities.size()==nCotSwapRates,
69 "cotSwapAnnuities.size()!=cotSwapRates.size()");
70 QL_REQUIRE(discountFactors.size()==nCotSwapRates+1,
71 "discountFactors.size()!=cotSwapRates.size()+1");
73 cotSwapAnnuities[nCotSwapRates-1] =
74 taus[nCotSwapRates-1]*discountFactors[nCotSwapRates];
75 cotSwapRates[nCotSwapRates-1] =
76 (discountFactors[nCotSwapRates-1]-discountFactors[nCotSwapRates])
77 /cotSwapAnnuities[nCotSwapRates-1];
79 for (
Size i=nCotSwapRates-1; i>firstValidIndex; --i) {
80 cotSwapAnnuities[i-1] = cotSwapAnnuities[i] + taus[i-1] * discountFactors[i];
82 (discountFactors[i-1]-discountFactors[nCotSwapRates])
83 /cotSwapAnnuities[i-1];
89 const Size spanningForwards,
90 const Size firstValidIndex,
91 const std::vector<DiscountFactor>& ds,
92 const std::vector<Time>& taus,
93 std::vector<Rate>& constMatSwapRates,
94 std::vector<Real>& constMatSwapAnnuities) {
95 Size nConstMatSwapRates = constMatSwapRates.size();
97 "taus.size()!=nConstMatSwapRates");
98 QL_REQUIRE(constMatSwapAnnuities.size()==nConstMatSwapRates,
99 "constMatSwapAnnuities.size()!=nConstMatSwapRates");
101 "ds.size()!=nConstMatSwapRates+1");
103 constMatSwapAnnuities[firstValidIndex]=0.;
104 Size lastIndex = std::min(firstValidIndex+spanningForwards,nConstMatSwapRates);
105 for (
Size i=firstValidIndex; i<lastIndex; ++i) {
106 constMatSwapAnnuities[firstValidIndex]+= taus[i] * ds[i+1];
108 constMatSwapRates[firstValidIndex] =
109 (ds[firstValidIndex]-ds[lastIndex])/
110 constMatSwapAnnuities[firstValidIndex];
111 Size oldLastIndex = lastIndex;
114 for (
Size i=firstValidIndex+1; i<nConstMatSwapRates; ++i) {
115 Size lastIndex = std::min(i+spanningForwards,nConstMatSwapRates);
116 constMatSwapAnnuities[i] = constMatSwapAnnuities[i-1]
118 if (lastIndex!=oldLastIndex)
119 constMatSwapAnnuities[i] += taus[lastIndex-1] * ds[lastIndex];
120 constMatSwapRates[i] = (ds[i]-ds[lastIndex])
121 /constMatSwapAnnuities[i];
122 oldLastIndex = lastIndex;
Rate swapRate(Size begin, Size end) const
std::vector< Time > rateTimes_
CurveState(const std::vector< Time > &rateTimes)
std::vector< Time > rateTaus_
virtual Real discountRatio(Size i, Size j) const =0
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
std::size_t Size
size of a container
void forwardsFromDiscountRatios(const Size firstValidIndex, const std::vector< DiscountFactor > &ds, const std::vector< Time > &taus, std::vector< Rate > &fwds)
void coterminalFromDiscountRatios(const Size firstValidIndex, const std::vector< DiscountFactor > &discountFactors, const std::vector< Time > &taus, std::vector< Rate > &cotSwapRates, std::vector< Real > &cotSwapAnnuities)
void checkIncreasingTimesAndCalculateTaus(const std::vector< Time > ×, std::vector< Time > &taus)
void constantMaturityFromDiscountRatios(const Size spanningForwards, const Size firstValidIndex, const std::vector< DiscountFactor > &ds, const std::vector< Time > &taus, std::vector< Rate > &constMatSwapRates, std::vector< Real > &constMatSwapAnnuities)