27 const std::vector<Real> &moneynessGrid,
29 const bool deleteArbitragePoints) {
31 if (!moneynessGrid.empty()) {
34 "moneyness grid should only contain non negative values ("
35 << moneynessGrid[0] <<
")");
36 for (
Size i = 0; i < moneynessGrid.size() - 1; i++) {
37 QL_REQUIRE(moneynessGrid[i] < moneynessGrid[i + 1],
38 "moneyness grid should contain strictly increasing "
40 << moneynessGrid[i] <<
","
41 << moneynessGrid[i + 1] <<
" at indices " << i
42 <<
", " << i + 1 <<
")");
49 "atm level must be provided by source section or given "
50 "in the constructor");
55 std::vector<Real> tmp;
57 static const Real defaultMoney[] = { 0.0, 0.01, 0.05, 0.10, 0.25, 0.40,
58 0.50, 0.60, 0.70, 0.80, 0.90, 1.0,
59 1.25, 1.5, 1.75, 2.0, 5.0, 7.5,
61 static const Real defaultMoneyNormal[] = {
62 -0.20, -0.15, -0.10, -0.075, -0.05, -0.04, -0.03,
63 -0.02, -0.015, -0.01, -0.0075, -0.0050, -0.0025, 0.0,
64 0.0025, 0.0050, 0.0075, 0.01, 0.015, 0.02, 0.03,
65 0.04, 0.05, 0.075, 0.10, 0.15, 0.20
68 if (moneynessGrid.empty()) {
70 ? std::vector<Real>(defaultMoneyNormal,
71 defaultMoneyNormal + 27)
72 : std::vector<Real>(defaultMoney, defaultMoney + 21);
75 tmp = std::vector<Real>(moneynessGrid);
84 bool minStrikeAdded =
false, maxStrikeAdded =
false;
94 maxStrikeAdded =
true;
98 if (k < section.
minStrike() && !minStrikeAdded) {
103 minStrikeAdded =
true;
105 if (k > section.
maxStrike() && !maxStrikeAdded) {
110 maxStrikeAdded =
true;
118 c_.push_back(
f_ + shift);
121 i <
k_.size(); i++) {
126 std::upper_bound(
m_.begin(),
m_.end(),
130 QL_REQUIRE(centralIndex <
k_.size() - 1 && centralIndex > 1,
131 "Atm point in moneyness grid ("
132 << centralIndex <<
") too close to boundary.");
137 while (!
af(centralIndex, centralIndex, centralIndex + 1) &&
138 centralIndex <
k_.size() - 1)
142 "central index is at right boundary");
173 if (deleteArbitragePoints &&
leftIndex_ > 1) {
191 "arbitrage free region must at least contain two "
192 "points (only index is "
206 const Size i1)
const {
209 Size im = i - 1 >= i0 ? i - 1 : 0;
211 if (q1 < -1.0 || q1 > 0.0)
216 return q1 <= q2 && q2 <= 0.0;
template class providing a null value for a given type.
interest rate volatility smile section
virtual Real minStrike() const =0
virtual VolatilityType volatilityType() const
virtual Real atmLevel() const =0
virtual Rate shift() const
virtual Real optionPrice(Rate strike, Option::Type type=Option::Call, Real discount=1.0) const
virtual Real maxStrike() const =0
std::pair< Size, Size > arbitragefreeIndices() const
std::pair< Real, Real > arbitragefreeRegion() const
SmileSectionUtils(const SmileSection §ion, const std::vector< Real > &moneynessGrid=std::vector< Real >(), Real atm=Null< Real >(), bool deleteArbitragePoints=false)
bool af(Size i0, Size i, Size i1) const
floating-point comparisons
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
std::size_t Size
size of a container
bool close(const Quantity &m1, const Quantity &m2, Size n)
Additional utilities for smile sections.