25#ifndef quantlib_replicating_varianceswap_engine_hpp
26#define quantlib_replicating_varianceswap_engine_hpp
46 typedef std::vector<std::pair<
51 const std::vector<Real>& callStrikes = std::vector<Real>(),
52 const std::vector<Real>& putStrikes = std::vector<Real>());
68 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
77 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
79 const std::vector<Real>& callStrikes,
80 const std::vector<Real>& putStrikes)
81 : process_(
std::move(process)), dk_(dk), callStrikes_(callStrikes), putStrikes_(putStrikes) {
84 QL_REQUIRE(!callStrikes.empty() && !putStrikes.empty(),
85 "no strike(s) given");
86 QL_REQUIRE(*std::min_element(putStrikes.begin(),putStrikes.end())>0.0,
87 "min put strike must be positive");
88 QL_REQUIRE(*std::min_element(callStrikes.begin(), callStrikes.end())==
89 *std::max_element(putStrikes.begin(), putStrikes.end()),
90 "min call and max put strikes differ");
95 const std::vector<Real>& availStrikes,
98 if (availStrikes.empty())
101 std::vector<Real> strikes = availStrikes;
106 std::sort(strikes.begin(), strikes.end());
107 strikes.push_back(strikes.back() +
dk_);
110 std::sort(strikes.begin(), strikes.end(), std::greater<>());
111 strikes.push_back(std::max(strikes.back() -
dk_, 0.0));
114 QL_FAIL(
"invalid option type");
118 auto last = std::unique(strikes.begin(), strikes.end());
119 strikes.erase(last, strikes.end());
122 Real f = strikes.front();
123 Real slope, prevSlope = 0.0;
128 for (std::vector<Real>::const_iterator k=strikes.begin();
135 ext::shared_ptr<StrikedTypePayoff>
payoff(
137 if ( k == strikes.begin() )
138 optionWeights.emplace_back(
payoff,slope);
140 optionWeights.emplace_back(
payoff, slope - prevSlope);
148 const Real callPutStrikeBoundary)
const {
149 Real f = callPutStrikeBoundary;
158 ext::shared_ptr<Exercise> exercise(
160 ext::shared_ptr<PricingEngine> optionEngine(
162 Real optionsValue = 0.0;
164 for (
auto i = optionWeights.begin(); i < optionWeights.end(); ++i) {
165 ext::shared_ptr<StrikedTypePayoff>
payoff = i->first;
168 Real weight = i->second;
169 optionsValue += option.
NPV() * weight;
172 Real f = optionWeights.front().first->strike();
Analytic European engine.
Pricing engine for European vanilla options using analytical formulae.
European option on a single asset.
VarianceSwap::results results_
VarianceSwap::arguments arguments_
std::map< std::string, ext::any > additionalResults
Real NPV() const
returns the net present value of the instrument.
void setPricingEngine(const ext::shared_ptr< PricingEngine > &)
set the pricing engine to be used.
Variance-swap pricing engine using replicating cost,.
Time residualTime() const
Real computeLogPayoff(Real, Real) const
std::vector< std::pair< ext::shared_ptr< StrikedTypePayoff >, Real > > weights_type
void calculate() const override
void computeOptionWeights(const std::vector< Real > &, Option::Type, weights_type &optionWeights) const
std::vector< Real > putStrikes_
Rate riskFreeRate() const
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
ReplicatingVarianceSwapEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process, Real dk=5.0, const std::vector< Real > &callStrikes=std::vector< Real >(), const std::vector< Real > &putStrikes=std::vector< Real >())
std::vector< Real > callStrikes_
Real computeReplicatingPortfolio(const weights_type &optionWeights) const
DiscountFactor riskFreeDiscount() const
base class for variance-swap engines
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
European option on a single asset.
Option exercise classes and payoff function.
@ NoFrequency
null frequency
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
ext::shared_ptr< QuantLib::Payoff > payoff