Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crossassetmodelimpliedfxvoltermstructure.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
21
22#include <ql/payoff.hpp>
23#include <ql/pricingengines/blackformula.hpp>
24
25namespace QuantExt {
26
28 const QuantLib::ext::shared_ptr<CrossAssetModel>& model, const Size foreignCurrencyIndex, BusinessDayConvention bdc,
29 const DayCounter& dc, const bool purelyTimeBased)
30 : BlackVolTermStructure(bdc, dc == DayCounter() ? model->irlgm1f(0)->termStructure()->dayCounter() : dc),
31 model_(model), fxIndex_(foreignCurrencyIndex), purelyTimeBased_(purelyTimeBased),
32 engine_(QuantLib::ext::make_shared<AnalyticCcLgmFxOptionEngine>(model_, foreignCurrencyIndex)),
33 referenceDate_(purelyTimeBased ? Null<Date>() : model_->irlgm1f(0)->termStructure()->referenceDate()) {
34
35 registerWith(model_);
36 engine_->cache(false);
37 Real fxSpot = model_->fxbs(fxIndex_)->fxSpotToday()->value();
38 QL_REQUIRE(fxSpot > 0, "FX Spot for index " << fxIndex_ << " must be positive");
39 state(0.0, 0.0, std::log(fxSpot));
40 update();
41}
42
44
45 Real tmpStrike = strike;
46
47 Real fxSpot = std::exp(fx_);
48 Real domDisc = model_->discountBond(0, relativeTime_, relativeTime_ + t, irDom_);
49 Real forDisc = model_->discountBond(fxIndex_ + 1, relativeTime_, relativeTime_ + t, irFor_);
50 Real atm = fxSpot * forDisc / domDisc;
51
52 if (tmpStrike == Null<Real>()) {
53 tmpStrike = atm;
54 }
55
56 Option::Type type = tmpStrike >= atm ? Option::Call : Option::Put;
57
58 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff = QuantLib::ext::make_shared<PlainVanillaPayoff>(type, tmpStrike);
59
60 Real premium = engine_->value(relativeTime_, relativeTime_ + t, payoff, domDisc, atm);
61
62 Real impliedStdDev = 0.0;
63 try {
64 impliedStdDev = blackFormulaImpliedStdDev(type, tmpStrike, atm, premium, domDisc);
65 } catch (...) {
66 }
67
68 return impliedStdDev * impliedStdDev;
69}
70
71Volatility CrossAssetModelImpliedFxVolTermStructure::blackVolImpl(Time t, Real strike) const {
72 Real tmp = std::max(1.0E-6, t);
73 return std::sqrt(blackVarianceImpl(tmp, strike) / tmp);
74}
75
77 QL_REQUIRE(!purelyTimeBased_, "reference date not available for purely "
78 "time based term structure");
79 return referenceDate_;
80}
81
83 QL_REQUIRE(!purelyTimeBased_, "reference date not available for purely "
84 "time based term structure");
86 update();
87}
88
90 QL_REQUIRE(purelyTimeBased_, "reference time can only be set for purely "
91 "time based term structure");
92 relativeTime_ = t;
93}
94
95void CrossAssetModelImpliedFxVolTermStructure::state(const Real domesticIr, const Real foreignIr, const Real logFx) {
96 irDom_ = domesticIr;
97 irFor_ = foreignIr;
98 fx_ = logFx;
99}
100
101void CrossAssetModelImpliedFxVolTermStructure::move(const Date& d, const Real domesticIr, const Real foreignIr,
102 const Real logFx) {
103 state(domesticIr, foreignIr, logFx);
104 referenceDate(d);
105}
106
107void CrossAssetModelImpliedFxVolTermStructure::move(const Time t, const Real domesticIr, const Real foreignIr,
108 const Real logFx) {
109 state(domesticIr, foreignIr, logFx);
110 referenceTime(t);
111}
112
114 if (!purelyTimeBased_) {
115 relativeTime_ = dayCounter().yearFraction(model_->irlgm1f(0)->termStructure()->referenceDate(), referenceDate_);
116 }
117 notifyObservers();
118}
119
120Date CrossAssetModelImpliedFxVolTermStructure::maxDate() const { return Date::maxDate(); }
121
122Time CrossAssetModelImpliedFxVolTermStructure::maxTime() const { return QL_MAX_REAL; }
123
125
126Real CrossAssetModelImpliedFxVolTermStructure::maxStrike() const { return QL_MAX_REAL; }
127
128} // namespace QuantExt
analytic cc lgm fx option engine
QuantLib::ext::shared_ptr< PricingEngine > engine_
Definition: cdsoption.cpp:78
CrossAssetModelImpliedFxVolTermStructure(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, const Size foreignCurrencyIndex, BusinessDayConvention bdc=Following, const DayCounter &dc=DayCounter(), const bool purelyTimeBased=false)
void state(const Real domesticIr, const Real foreignIr, const Real logFx)
const QuantLib::ext::shared_ptr< AnalyticCcLgmFxOptionEngine > engine_
void move(const Date &d, const Real domesticIr, const Real foreignIr, const Real logFx)
dynamic black volatility term structure