61 {
62
63 SwaptionVolatilityCube::performCalculations();
64
66
67
68
71
72 std::vector<Real> allOptionTimes, allSwapLengths;
73 for (auto const& p : allOptionTenors)
74 allOptionTimes.push_back(timeFromReference(optionDateFromTenor(p)));
75 for (auto const& p : allSwapTenors)
76 allSwapLengths.push_back(swapLength(p));
77
78 std::vector<Matrix> interpolatedVolSpreads(strikeSpreads_.size(),
79 Matrix(allSwapLengths.size(), allOptionTimes.size(), Null<Real>()));
80
81 for (Size k = 0; k < strikeSpreads_.size(); ++k) {
82 for (Size i = 0; i < allOptionTenors.size(); ++i) {
83 for (Size j = 0; j < allSwapTenors.size(); ++j) {
84 Size i0 = std::distance(optionTenors_.begin(),
85 std::find(optionTenors_.begin(), optionTenors_.end(), allOptionTenors[i]));
86 Size j0 = std::distance(swapTenors_.begin(),
87 std::find(swapTenors_.begin(), swapTenors_.end(), allSwapTenors[j]));
88 if (i0 < optionTenors_.size() && j0 < swapTenors_.size()) {
89 interpolatedVolSpreads[k](j, i) = volSpreads_[i0 * swapTenors_.size() + j0][k]->value();
90 }
91 }
92 }
93 }
94
95 for (auto& v : interpolatedVolSpreads) {
96 laplaceInterpolationWithErrorHandling(v, allOptionTimes, allSwapLengths);
97 }
98
99
100
101 std::vector<ParametricVolatility::MarketSmile> marketSmiles;
102 std::map<std::pair<QuantLib::Real, QuantLib::Real>, std::vector<std::pair<Real, bool>>> modelParameters;
103 for (Size i = 0; i < allOptionTenors.size(); ++i) {
104 for (Size j = 0; j < allSwapTenors.size(); ++j) {
105 Real forward = atmStrike(allOptionTenors[i], allSwapTenors[j]);
106 Real sigma = atmVol()->volatility(allOptionTenors[i], allSwapTenors[j], forward);
108 std::vector<Real> vols;
109 for (Size k = 0; k < strikeSpreads_.size(); ++k) {
110 strikes.push_back(forward + strikeSpreads_[k]);
111 vols.push_back(sigma + interpolatedVolSpreads[k](j, i));
112 }
113 marketSmiles.push_back(ParametricVolatility::MarketSmile{allOptionTimes[i],
114 allSwapLengths[j],
115 forward,
116 shift(allOptionTenors[i], allSwapTenors[j]),
117 {},
119 vols});
122 modelParameters[std::make_pair(allOptionTimes[i], allSwapLengths[j])] = m->second;
123 }
124 }
125 }
126
133}
@ ShiftedLognormalVolatility
std::map< std::pair< Real, Real >, QuantLib::ext::shared_ptr< ParametricVolatilitySmileSection > > cache_
QuantLib::ext::shared_ptr< ParametricVolatility > parametricVolatility_