Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
datedstrippedoptionlet.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20
21#include <ql/utilities/dataformatters.hpp>
22
23#include <boost/algorithm/cxx11/is_sorted.hpp>
24
25using boost::algorithm::is_strictly_increasing;
26
27namespace QuantExt {
28
30 const QuantLib::ext::shared_ptr<StrippedOptionletBase>& s)
31 : referenceDate_(referenceDate), calendar_(s->calendar()), businessDayConvention_(s->businessDayConvention()),
32 optionletDates_(s->optionletFixingDates()), nOptionletDates_(s->optionletMaturities()),
33 optionletTimes_(s->optionletFixingTimes()), optionletStrikes_(nOptionletDates_, vector<Rate>()),
34 optionletVolatilities_(nOptionletDates_, vector<Volatility>()), optionletAtmRates_(s->atmOptionletRates()),
35 dayCounter_(s->dayCounter()), type_(s->volatilityType()), displacement_(s->displacement()) {
36
37 // Populate the optionlet strikes and volatilities
38 for (Size i = 0; i < nOptionletDates_; ++i) {
39 optionletStrikes_[i] = s->optionletStrikes(i);
40 optionletVolatilities_[i] = s->optionletVolatilities(i);
41 }
42}
43
44DatedStrippedOptionlet::DatedStrippedOptionlet(const Date& referenceDate, const Calendar& calendar,
45 BusinessDayConvention bdc, const vector<Date>& optionletDates,
46 const vector<vector<Rate> >& strikes,
47 const vector<vector<Volatility> >& volatilities,
48 const vector<Rate>& optionletAtmRates, const DayCounter& dayCounter,
49 VolatilityType type, Real displacement)
50 : referenceDate_(referenceDate), calendar_(calendar), businessDayConvention_(bdc), optionletDates_(optionletDates),
51 nOptionletDates_(optionletDates.size()), optionletTimes_(nOptionletDates_), optionletStrikes_(strikes),
52 optionletVolatilities_(volatilities), optionletAtmRates_(optionletAtmRates), dayCounter_(dayCounter), type_(type),
53 displacement_(displacement) {
54
56 // Populate the optionlet times
57 for (Size i = 0; i < nOptionletDates_; ++i)
59}
60
62
63 QL_REQUIRE(!optionletDates_.empty(), "Need at least one optionlet to create optionlet surface");
64 QL_REQUIRE(nOptionletDates_ == optionletVolatilities_.size(),
65 "Mismatch between number of option tenors (" << nOptionletDates_ << ") and number of volatility rows ("
66 << optionletVolatilities_.size() << ")");
67 QL_REQUIRE(nOptionletDates_ == optionletStrikes_.size(), "Mismatch between number of option tenors ("
68 << nOptionletDates_ << ") and number of strike rows ("
69 << optionletStrikes_.size() << ")");
70 QL_REQUIRE(nOptionletDates_ == optionletAtmRates_.size(), "Mismatch between number of option tenors ("
71 << nOptionletDates_ << ") and number of ATM rates ("
72 << optionletAtmRates_.size() << ")");
73 QL_REQUIRE(optionletDates_[0] > referenceDate_,
74 "First option date (" << optionletDates_[0] << ") must be greater than the reference date");
75 QL_REQUIRE(is_strictly_increasing(optionletDates_.begin(), optionletDates_.end()),
76 "Optionlet dates must be sorted in ascending order");
77
78 for (Size i = 0; i < nOptionletDates_; ++i) {
79 QL_REQUIRE(!optionletStrikes_[i].empty(), "The " << io::ordinal(i) << " row of strikes is empty");
80 QL_REQUIRE(optionletStrikes_[i].size() == optionletVolatilities_[i].size(),
81 "Size of " << io::ordinal(i) << " row of strikes and volatilities are not equal");
82 QL_REQUIRE(is_strictly_increasing(optionletStrikes_[i].begin(), optionletStrikes_[i].end()),
83 "The " << io::ordinal(i) << " row of strikes is not sorted in ascending order");
84 }
85}
86
87const vector<Rate>& DatedStrippedOptionlet::optionletStrikes(Size i) const {
88 QL_REQUIRE(i < optionletStrikes_.size(),
89 "index (" << i << ") must be less than optionletStrikes size (" << optionletStrikes_.size() << ")");
90 return optionletStrikes_[i];
91}
92
93const vector<Volatility>& DatedStrippedOptionlet::optionletVolatilities(Size i) const {
94 QL_REQUIRE(i < optionletVolatilities_.size(), "index (" << i << ") must be less than optionletVolatilities size ("
95 << optionletVolatilities_.size() << ")");
96 return optionletVolatilities_[i];
97}
98
100
102
104
106
107const DayCounter& DatedStrippedOptionlet::dayCounter() const { return dayCounter_; }
108
109const Calendar& DatedStrippedOptionlet::calendar() const { return calendar_; }
110
112
114
115VolatilityType DatedStrippedOptionlet::volatilityType() const { return type_; }
116
118} // namespace QuantExt
DatedStrippedOptionlet(const Date &referenceDate, const QuantLib::ext::shared_ptr< StrippedOptionletBase > &s)
Construct from a StrippedOptionletBase object.
const vector< Date > & optionletFixingDates() const override
const vector< Rate > & optionletStrikes(Size i) const override
const Date & referenceDate() const override
const vector< Time > & optionletFixingTimes() const override
const vector< Volatility > & optionletVolatilities(Size i) const override
VolatilityType volatilityType() const override
vector< vector< Volatility > > optionletVolatilities_
const Calendar & calendar() const override
const DayCounter & dayCounter() const override
const vector< Rate > & atmOptionletRates() const override
BusinessDayConvention businessDayConvention() const override
vector< vector< Rate > > optionletStrikes_
Stripped optionlet surface with fixed reference date.
vector< Real > strikes