Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxeqoptionhelper.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
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
28FxEqOptionHelper::FxEqOptionHelper(const Period& maturity, const Calendar& calendar, const Real strike,
29 const Handle<Quote> spot, const Handle<Quote> volatility,
30 const Handle<YieldTermStructure>& domesticYield,
31 const Handle<YieldTermStructure>& foreignYield,
32 BlackCalibrationHelper::CalibrationErrorType errorType)
33 : BlackCalibrationHelper(volatility, errorType), termStructure_(domesticYield), hasMaturity_(true),
34 maturity_(maturity), calendar_(calendar), strike_(strike), spot_(spot), foreignYield_(foreignYield) {
35 registerWith(spot_);
36 registerWith(foreignYield_);
37}
38
39FxEqOptionHelper::FxEqOptionHelper(const Date& exerciseDate, const Real strike, const Handle<Quote> spot,
40 const Handle<Quote> volatility, const Handle<YieldTermStructure>& domesticYield,
41 const Handle<YieldTermStructure>& foreignYield,
42 BlackCalibrationHelper::CalibrationErrorType errorType)
43 : BlackCalibrationHelper(volatility, errorType), termStructure_(domesticYield), hasMaturity_(false),
44 exerciseDate_(exerciseDate), strike_(strike), spot_(spot), foreignYield_(foreignYield) {
45 registerWith(spot_);
46 registerWith(foreignYield_);
47}
48
50 if (hasMaturity_)
51 exerciseDate_ = calendar_.advance(termStructure_->referenceDate(), maturity_);
52 tau_ = termStructure_->timeFromReference(exerciseDate_);
53 atm_ = spot_->value() * foreignYield_->discount(tau_) / termStructure_->discount(tau_);
55 if (effStrike_ == Null<Real>())
57 type_ = effStrike_ >= atm_ ? Option::Call : Option::Put;
58 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(new PlainVanillaPayoff(type_, effStrike_));
59 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(exerciseDate_);
60 option_ = QuantLib::ext::shared_ptr<VanillaOption>(new VanillaOption(payoff, exercise));
61 BlackCalibrationHelper::performCalculations();
62}
63
65 calculate();
66 option_->setPricingEngine(engine_);
67 return option_->NPV();
68}
69
70Real FxEqOptionHelper::blackPrice(Real volatility) const {
71 calculate();
72 const Real stdDev = volatility * std::sqrt(tau_);
73 return blackFormula(type_, effStrike_, atm_, stdDev, termStructure_->discount(tau_));
74}
75
76} // namespace QuantExt
QuantLib::ext::shared_ptr< PricingEngine > engine_
Definition: cdsoption.cpp:78
const Handle< Quote > spot_
void performCalculations() const override
Real blackPrice(Real volatility) const override
Real modelValue() const override
QuantLib::ext::shared_ptr< VanillaOption > option_
FxEqOptionHelper(const Period &maturity, const Calendar &calendar, const Real strike, const Handle< Quote > spot, const Handle< Quote > volatility, const Handle< YieldTermStructure > &domesticYield, const Handle< YieldTermStructure > &foreignYield, BlackCalibrationHelper::CalibrationErrorType errorType=BlackCalibrationHelper::RelativePriceError)
const Handle< YieldTermStructure > foreignYield_
Handle< YieldTermStructure > termStructure_
calibration helper for Black-Scholes options