Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
analyticxassetlgmeqoptionengine.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/pricingengines/blackcalculator.hpp>
23
24namespace QuantExt {
25
26using namespace CrossAssetAnalytics;
27
29 const QuantLib::ext::shared_ptr<CrossAssetModel>& model, const Size eqName, const Size EqCcy)
30 : model_(model), eqIdx_(eqName), ccyIdx_(EqCcy) {}
31
32Real AnalyticXAssetLgmEquityOptionEngine::value(const Time t0, const Time t,
33 const QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff, const Real discount,
34 const Real eqForward) const {
35
36 const Size& k = eqIdx_;
37 const Size& i = ccyIdx_;
38
39 Real Hi_t = Hz(i).eval(*model_, t);
40
41 // calculate the full variance. This is the equity analogy to eqn: 12.18 in Lichters,Stamm,Gallagher
42 Real variance = 0;
43 variance += (vs(k).eval(*model_, t) - vs(k).eval(*model_, t0));
44
45 variance += Hi_t * Hi_t * (zetaz(i).eval(*model_, t) - zetaz(i).eval(*model_, t0));
46 variance -= 2.0 * Hi_t * integral(*model_, P(Hz(i), az(i), az(i)), t0, t);
47 variance += integral(*model_, P(Hz(i), Hz(i), az(i), az(i)), t0, t);
48
49 variance += 2.0 * Hi_t * integral(*model_, P(rzs(i, k), ss(k), az(i)), t0, t);
50 variance -= 2.0 * integral(*model_, P(Hz(i), rzs(i, k), ss(k), az(i)), t0, t);
51
52 Real stdev = sqrt(variance);
53 BlackCalculator black(payoff, eqForward, stdev, discount);
54
55 return black.value();
56}
57
59
60 QL_REQUIRE(arguments_.exercise->type() == Exercise::European, "only European options are allowed");
61
62 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff = QuantLib::ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
63 QL_REQUIRE(payoff != NULL, "only striked payoff is allowed");
64
65 Date expiry = arguments_.exercise->lastDate();
66 Time t = model_->irlgm1f(0)->termStructure()->timeFromReference(expiry);
67
68 if (t <= 0.0) {
69 // option is expired, we do not value any possibly non settled
70 // flows, i.e. set the npv to zero in this case
71 results_.value = 0.0;
72 return;
73 }
74
75 Real divDiscount = model_->eqbs(eqIdx_)->equityDivYieldCurveToday()->discount(expiry);
76 Real eqIrDiscount = model_->eqbs(eqIdx_)->equityIrCurveToday()->discount(expiry);
77 Real cashflowsDiscount = model_->irlgm1f(ccyIdx_)->termStructure()->discount(expiry);
78
79 Real eqForward = model_->eqbs(eqIdx_)->eqSpotToday()->value() * divDiscount / eqIrDiscount;
80
81 results_.value = value(0.0, t, payoff, cashflowsDiscount, eqForward);
82
83} // calculate()
84
85} // namespace QuantExt
analytic cross-asset lgm eq option engine
const Instrument::results * results_
Definition: cdsoption.cpp:81
Real value(const Time t0, const Time t, const QuantLib::ext::shared_ptr< StrikedTypePayoff > payoff, const Real domesticDiscount, const Real eqForward) const
AnalyticXAssetLgmEquityOptionEngine(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, const Size equityIdx, const Size ccyIdx)
const QuantLib::ext::shared_ptr< CrossAssetModel > model_
analytics for the cross asset model
Real integral(const CrossAssetModel &model, const E &e, const Real a, const Real b)
const P2_< E1, E2 > P(const E1 &e1, const E2 &e2)
RandomVariable sqrt(RandomVariable x)
RandomVariable variance(const RandomVariable &r)
RandomVariable black(const RandomVariable &omega, const RandomVariable &t, const RandomVariable &strike, const RandomVariable &forward, const RandomVariable &impliedVol)
Real eval(const CrossAssetModel &x, const Real t) const
Real eval(const CrossAssetModel &x, const Real t) const
Real eval(const CrossAssetModel &x, const Real t) const
Swap::arguments * arguments_