Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
analyticcclgmfxoptionengine.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
28AnalyticCcLgmFxOptionEngine::AnalyticCcLgmFxOptionEngine(const QuantLib::ext::shared_ptr<CrossAssetModel>& model,
29 const Size foreignCurrency)
30 : model_(model), foreignCurrency_(foreignCurrency), cacheEnabled_(false), cacheDirty_(true) {}
31
32Real AnalyticCcLgmFxOptionEngine::value(const Time t0, const Time t, const QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff,
33 const Real domesticDiscount, const Real fxForward) const {
34 Real H0 = Hz(0).eval(*model_, t);
35 Real Hi = Hz(foreignCurrency_ + 1).eval(*model_, t);
36
37 // just a shortcut
38 const Size& i = foreignCurrency_;
39
42 // first term
43 H0 * H0 * (zetaz(0).eval(*model_, t) - zetaz(0).eval(*model_, t0)) -
44 2.0 * H0 * integral(*model_, P(Hz(0), az(0), az(0)), t0, t) +
45 integral(*model_, P(Hz(0), Hz(0), az(0), az(0)), t0, t) +
46 // second term
47 Hi * Hi * (zetaz(i + 1).eval(*model_, t) - zetaz(i + 1).eval(*model_, t0)) -
48 2.0 * Hi * integral(*model_, P(Hz(i + 1), az(i + 1), az(i + 1)), t0, t) +
49 integral(*model_, P(Hz(i + 1), Hz(i + 1), az(i + 1), az(i + 1)), t0, t) -
50 // third term
51 2.0 * (H0 * Hi * integral(*model_, P(az(0), az(i + 1), rzz(0, i + 1)), t0, t) -
52 H0 * integral(*model_, P(Hz(i + 1), az(i + 1), az(0), rzz(i + 1, 0)), t0, t) -
53 Hi * integral(*model_, P(Hz(0), az(0), az(i + 1), rzz(0, i + 1)), t0, t) +
54 integral(*model_, P(Hz(0), Hz(i + 1), az(0), az(i + 1), rzz(0, i + 1)), t0, t));
55 cacheDirty_ = false;
56 cachedT0_ = t0;
57 cachedT_ = t;
58 }
59
61 // term two three/fourth
62 (vx(i).eval(*model_, t) - vx(i).eval(*model_, t0)) +
63 // forth term
64 2.0 * (H0 * integral(*model_, P(az(0), sx(i), rzx(0, i)), t0, t) -
65 integral(*model_, P(Hz(0), az(0), sx(i), rzx(0, i)), t0, t)) -
66 // fifth term
67 2.0 * (Hi * integral(*model_, P(az(i + 1), sx(i), rzx(i + 1, i)), t0, t) -
68 integral(*model_, P(Hz(i + 1), az(i + 1), sx(i), rzx(i + 1, i)), t0, t));
69
70 BlackCalculator black(payoff, fxForward, std::sqrt(variance), domesticDiscount);
71
72 return black.value();
73}
74
76
77 QL_REQUIRE(arguments_.exercise->type() == Exercise::European, "only European options are allowed");
78
79 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff = QuantLib::ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
80 QL_REQUIRE(payoff != NULL, "only striked payoff is allowed");
81
82 Date expiry = arguments_.exercise->lastDate();
83 Time t = model_->irlgm1f(0)->termStructure()->timeFromReference(expiry);
84
85 if (t <= 0.0) {
86 // option is expired, we do not value any possibly non settled
87 // flows, i.e. set the npv to zero in this case
88 results_.value = 0.0;
89 return;
90 }
91
92 Real foreignDiscount = model_->irlgm1f(foreignCurrency_ + 1)->termStructure()->discount(expiry);
93 Real domesticDiscount = model_->irlgm1f(0)->termStructure()->discount(expiry);
94
95 Real fxForward = model_->fxbs(foreignCurrency_)->fxSpotToday()->value() * foreignDiscount / domesticDiscount;
96
97 results_.value = value(0.0, t, payoff, domesticDiscount, fxForward);
98
99} // calculate()
100
101} // namespace QuantExt
analytic cc lgm fx option engine
const Instrument::results * results_
Definition: cdsoption.cpp:81
AnalyticCcLgmFxOptionEngine(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, const Size foreignCurrency)
Real value(const Time t0, const Time t, const QuantLib::ext::shared_ptr< StrikedTypePayoff > payoff, const Real domesticDiscount, const Real fxForward) const
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)
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
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_