Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crossassetmodelimpliedeqvoltermstructure.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 equityIndex, BusinessDayConvention bdc,
29 const DayCounter& dc, const bool purelyTimeBased)
30 : BlackVolTermStructure(bdc, dc == DayCounter() ? model->irlgm1f(0)->termStructure()->dayCounter() : dc),
31 model_(model), eqIndex_(equityIndex), purelyTimeBased_(purelyTimeBased),
32 engine_(QuantLib::ext::make_shared<AnalyticXAssetLgmEquityOptionEngine>(model_, eqIndex_, eqCcyIndex())),
33 referenceDate_(purelyTimeBased ? Null<Date>() : model_->irlgm1f(0)->termStructure()->referenceDate()) {
34
35 registerWith(model_);
36 // engine_->cache(false);
37 Real eqSpot = model_->eqbs(eqIndex_)->eqSpotToday()->value();
38 QL_REQUIRE(eqSpot > 0, "EQ Spot for index " << eqIndex_ << " must be positive");
39 state(0.0, std::log(eqSpot));
40 update();
41}
42
44
45 Real tmpStrike = strike;
46
47 Real eqSpot = std::exp(eq_);
48 Real rateDisc = model_->discountBond(eqCcyIndex(), relativeTime_, relativeTime_ + t, eqIr_);
49 Real divDisc = model_->eqbs(eqIndex_)->equityDivYieldCurveToday()->discount(t);
50 // Real forDisc = model_->discountBond(fxIndex_ + 1, relativeTime_, relativeTime_ + t, irFor_);
51 Real atm = eqSpot * divDisc / rateDisc;
52
53 if (tmpStrike == Null<Real>()) {
54 tmpStrike = atm;
55 }
56
57 Option::Type type = tmpStrike >= atm ? Option::Call : Option::Put;
58
59 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff = QuantLib::ext::make_shared<PlainVanillaPayoff>(type, tmpStrike);
60
61 Real premium = engine_->value(relativeTime_, relativeTime_ + t, payoff, rateDisc, atm);
62
63 Real impliedStdDev = 0.0;
64 try {
65 impliedStdDev = blackFormulaImpliedStdDev(type, tmpStrike, atm, premium, rateDisc);
66 } catch (...) {
67 }
68
69 return impliedStdDev * impliedStdDev;
70}
71
72Volatility CrossAssetModelImpliedEqVolTermStructure::blackVolImpl(Time t, Real strike) const {
73 Real tmp = std::max(1.0E-6, t);
74 return std::sqrt(blackVarianceImpl(tmp, strike) / tmp);
75}
76
78 QL_REQUIRE(!purelyTimeBased_, "reference date not available for purely "
79 "time based term structure");
80 return referenceDate_;
81}
82
84 QL_REQUIRE(!purelyTimeBased_, "reference date not available for purely "
85 "time based term structure");
87 update();
88}
89
91 QL_REQUIRE(purelyTimeBased_, "reference time can only be set for purely "
92 "time based term structure");
93 relativeTime_ = t;
94}
95
96void CrossAssetModelImpliedEqVolTermStructure::state(const Real eqIr, const Real logEq) {
97 eqIr_ = eqIr;
98 eq_ = logEq;
99}
100
101void CrossAssetModelImpliedEqVolTermStructure::move(const Date& d, const Real eqIr, const Real logEq) {
102 state(eqIr, logEq);
103 referenceDate(d);
104}
105
106void CrossAssetModelImpliedEqVolTermStructure::move(const Time t, const Real eqIr, const Real logEq) {
107 state(eqIr, logEq);
108 referenceTime(t);
109}
110
112 if (!purelyTimeBased_) {
113 relativeTime_ = dayCounter().yearFraction(model_->irlgm1f(0)->termStructure()->referenceDate(), referenceDate_);
114 }
115 notifyObservers();
116}
117
118Date CrossAssetModelImpliedEqVolTermStructure::maxDate() const { return Date::maxDate(); }
119
120Time CrossAssetModelImpliedEqVolTermStructure::maxTime() const { return QL_MAX_REAL; }
121
123
124Real CrossAssetModelImpliedEqVolTermStructure::maxStrike() const { return QL_MAX_REAL; }
125
126} // namespace QuantExt
analytic cross-asset lgm eq option engine
QuantLib::ext::shared_ptr< PricingEngine > engine_
Definition: cdsoption.cpp:78
Analytic cross-asset lgm equity option engine.
void move(const Date &d, const Real eqIr, const Real logEq)
const QuantLib::ext::shared_ptr< AnalyticXAssetLgmEquityOptionEngine > engine_
CrossAssetModelImpliedEqVolTermStructure(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, const Size equityIndex, BusinessDayConvention bdc=Following, const DayCounter &dc=DayCounter(), const bool purelyTimeBased=false)
dynamic black volatility term structure