Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
futureoptionhelper.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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
19#include <ql/exercise.hpp>
20#include <ql/pricingengines/blackformula.hpp>
21#include <ql/time/calendars/nullcalendar.hpp>
23
24#include <boost/make_shared.hpp>
25
26namespace QuantExt {
27
29 const Period& maturity, const Calendar& calendar, const Real strike,
30 const Handle<QuantExt::PriceTermStructure> priceCurve, const Handle<Quote> volatility,
31 BlackCalibrationHelper::CalibrationErrorType errorType)
32 : BlackCalibrationHelper(volatility, errorType), priceCurve_(priceCurve), hasMaturity_(true),
33 maturity_(maturity), calendar_(calendar), strike_(strike) {
34 registerWith(priceCurve_);
35}
36
38 const Date& exerciseDate, const Real strike,
39 const Handle<QuantExt::PriceTermStructure> priceCurve, const Handle<Quote> volatility,
40 BlackCalibrationHelper::CalibrationErrorType errorType)
41 : BlackCalibrationHelper(volatility, errorType), priceCurve_(priceCurve), hasMaturity_(false),
42 exerciseDate_(exerciseDate), strike_(strike) {
43 registerWith(priceCurve_);
44}
45
47 if (hasMaturity_)
48 exerciseDate_ = calendar_.advance(priceCurve_->referenceDate(), maturity_);
49 tau_ = priceCurve_->timeFromReference(exerciseDate_);
50 atm_ = priceCurve_->price(tau_);
52 if (effStrike_ == Null<Real>())
54 type_ = effStrike_ >= atm_ ? Option::Call : Option::Put;
55 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(new PlainVanillaPayoff(type_, effStrike_));
56 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(exerciseDate_);
57 option_ = QuantLib::ext::shared_ptr<VanillaOption>(new VanillaOption(payoff, exercise));
58 BlackCalibrationHelper::performCalculations();
59}
60
62 calculate();
63 option_->setPricingEngine(engine_);
64 return option_->NPV();
65}
66
67Real FutureOptionHelper::blackPrice(Real volatility) const {
68 calculate();
69 const Real stdDev = volatility * std::sqrt(tau_);
70 return blackFormula(type_, effStrike_, atm_, stdDev, 1.0);
71}
72
73} // namespace QuantExt
QuantLib::ext::shared_ptr< PricingEngine > engine_
Definition: cdsoption.cpp:78
void performCalculations() const override
Handle< QuantExt::PriceTermStructure > priceCurve_
Real blackPrice(Real volatility) const override
Real modelValue() const override
QuantLib::ext::shared_ptr< VanillaOption > option_
FutureOptionHelper(const Period &maturity, const Calendar &calendar, const Real strike, const Handle< QuantExt::PriceTermStructure > priceCurve, const Handle< Quote > volatility, BlackCalibrationHelper::CalibrationErrorType errorType=BlackCalibrationHelper::RelativePriceError)
calibration helper for Black-Scholes options