43 {
44
45
46
47 Real value = 0.0, vega = 0.0;
48 Size optionlets =
arguments_.startDates.size();
49 std::vector<Real> values(optionlets, 0.0);
50 std::vector<Real> stdDevs(optionlets, 0.0);
51 std::vector<Real> forwards(optionlets, 0.0);
52 YoYInflationCapFloor::Type type =
arguments_.type;
53
54 Handle<YoYInflationTermStructure> yoyTS =
index()->yoyInflationTermStructure();
56 QL_REQUIRE(!discountTS.empty(), "YoYInflationCapFloorEngine: No discount curve given.");
57 Date settlement = discountTS->referenceDate();
58
59 for (Size i = 0; i < optionlets; ++i) {
61 if (paymentDate > settlement) {
62 DiscountFactor d =
arguments_.nominals[i] *
arguments_.gearings[i] * discountTS->discount(paymentDate) *
64
65
66
67
68
69
70
71
72 forwards[i] = yoyTS->yoyRate(
arguments_.fixingDates[i], Period(0, Days));
73 Rate forward = forwards[i];
74
76 Time sqrtTime = 0.0;
78 sqrtTime = std::sqrt(
volatility_->timeFromBase(fixingDate));
79 }
80
81 if (type == YoYInflationCapFloor::Cap || type == YoYInflationCapFloor::Collar) {
83 if (sqrtTime > 0.0) {
84 stdDevs[i] = std::sqrt(
volatility_->totalVariance(fixingDate, strike, Period(0, Days)));
85 }
86
87
88 values[i] =
optionletImpl(Option::Call, strike, forward, stdDevs[i], d);
89 vega +=
optionletVegaImpl(Option::Call, strike, forward, stdDevs[i], sqrtTime, d);
90 }
91 if (type == YoYInflationCapFloor::Floor || type == YoYInflationCapFloor::Collar) {
93 if (sqrtTime > 0.0) {
94 stdDevs[i] = std::sqrt(
volatility_->totalVariance(fixingDate, strike, Period(0, Days)));
95 }
96 Real floorlet =
optionletImpl(Option::Put, strike, forward, stdDevs[i], d);
97 Real floorletVega =
optionletVegaImpl(Option::Call, strike, forward, stdDevs[i], sqrtTime, d);
98 if (type == YoYInflationCapFloor::Floor) {
99 values[i] = floorlet;
100 vega -= floorletVega;
101 } else {
102
103 values[i] -= floorlet;
104 vega -=
optionletVegaImpl(Option::Call, strike, forward, stdDevs[i], sqrtTime, d);
105 }
106 }
107 value += values[i];
108 }
109 }
111
112 results_.additionalResults[
"vega"] = vega;
113 results_.additionalResults[
"optionletsPrice"] = values;
114 results_.additionalResults[
"optionletsAtmForward"] = forwards;
115 if (type != YoYInflationCapFloor::Collar)
116 results_.additionalResults[
"optionletsStdDev"] = stdDevs;
117}
const Instrument::results * results_
virtual Real optionletVegaImpl(Option::Type type, Rate strike, Rate forward, Real stdDev, Real sqrtTime, Real d) const =0
virtual Real optionletImpl(Option::Type type, Rate strike, Rate forward, Real stdDev, Real d) const =0
descendents only need to implement this
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
Swap::arguments * arguments_