Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
AnalyticCcLgmFxOptionEngine Class Reference

Analytic cc lgm fx option engine. More...

#include <qle/pricingengines/analyticcclgmfxoptionengine.hpp>

+ Inheritance diagram for AnalyticCcLgmFxOptionEngine:
+ Collaboration diagram for AnalyticCcLgmFxOptionEngine:

Public Member Functions

 AnalyticCcLgmFxOptionEngine (const QuantLib::ext::shared_ptr< CrossAssetModel > &model, const Size foreignCurrency)
 
void calculate () const override
 
void cache (bool enable=true)
 
Real value (const Time t0, const Time t, const QuantLib::ext::shared_ptr< StrikedTypePayoff > payoff, const Real domesticDiscount, const Real fxForward) const
 

Private Attributes

const QuantLib::ext::shared_ptr< CrossAssetModelmodel_
 
const Size foreignCurrency_
 
bool cacheEnabled_
 
bool cacheDirty_
 
Real cachedIntegrals_
 
Real cachedT0_
 
Real cachedT_
 

Detailed Description

Analytic cc lgm fx option engine.

Definition at line 36 of file analyticcclgmfxoptionengine.hpp.

Constructor & Destructor Documentation

◆ AnalyticCcLgmFxOptionEngine()

AnalyticCcLgmFxOptionEngine ( const QuantLib::ext::shared_ptr< CrossAssetModel > &  model,
const Size  foreignCurrency 
)

Member Function Documentation

◆ calculate()

void calculate ( ) const
override

Definition at line 75 of file analyticcclgmfxoptionengine.cpp.

75 {
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()
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 fxForward) const
Swap::arguments * arguments_
+ Here is the call graph for this function:

◆ cache()

void cache ( bool  enable = true)

if cache is enabled, the integrals independent of fx volatility are cached, which can speed up calibration; remember to flush the cache when the ir parameters change, this can be done by another call to cache

Definition at line 63 of file analyticcclgmfxoptionengine.hpp.

63 {
64 cacheEnabled_ = enable;
65 cacheDirty_ = true;
66}

◆ value()

Real value ( const Time  t0,
const Time  t,
const QuantLib::ext::shared_ptr< StrikedTypePayoff >  payoff,
const Real  domesticDiscount,
const Real  fxForward 
) const

the actual option price calculation, exposed to public, since it is useful to directly use the core computation sometimes

Definition at line 32 of file analyticcclgmfxoptionengine.cpp.

33 {
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}
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)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ model_

const QuantLib::ext::shared_ptr<CrossAssetModel> model_
private

Definition at line 54 of file analyticcclgmfxoptionengine.hpp.

◆ foreignCurrency_

const Size foreignCurrency_
private

Definition at line 55 of file analyticcclgmfxoptionengine.hpp.

◆ cacheEnabled_

bool cacheEnabled_
private

Definition at line 56 of file analyticcclgmfxoptionengine.hpp.

◆ cacheDirty_

bool cacheDirty_
mutableprivate

Definition at line 57 of file analyticcclgmfxoptionengine.hpp.

◆ cachedIntegrals_

Real cachedIntegrals_
mutableprivate

Definition at line 58 of file analyticcclgmfxoptionengine.hpp.

◆ cachedT0_

Real cachedT0_
private

Definition at line 58 of file analyticcclgmfxoptionengine.hpp.

◆ cachedT_

Real cachedT_
private

Definition at line 58 of file analyticcclgmfxoptionengine.hpp.