Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxoption.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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
26
28
29namespace ore {
30namespace data {
31
32using namespace QuantLib;
33using namespace QuantExt;
34
35QuantLib::ext::shared_ptr<PricingEngine> CamAmcFxOptionEngineBuilder::engineImpl(const string& assetName,
36 const Currency& domCcy,
37 const AssetClass& assetClassUnderlying,
38 const Date& expiryDate, const bool useFxSpot) {
39
40 QL_REQUIRE(assetClassUnderlying == AssetClass::FX, "FX Option required");
41 Currency forCcy = parseCurrency(assetName);
42
43 std::string ccysStr = forCcy.code() + "_" + domCcy.code();
44
45 DLOG("Building AMC FX option engine for ccys " << ccysStr << " (from externally given CAM)");
46
47 QL_REQUIRE(domCcy != forCcy, "CamAmcFxOptionEngineBuilder: domCcy = forCcy = " << domCcy.code());
48
49 std::vector<Size> externalModelIndices;
50 std::vector<Handle<YieldTermStructure>> discountCurves;
51 std::vector<Size> cIdx;
52 std::vector<QuantLib::ext::shared_ptr<IrModel>> lgm;
53 std::vector<QuantLib::ext::shared_ptr<FxBsParametrization>> fx;
54
55 // add the IR and FX components in the order they appear in the CAM; this way
56 // we can sort the external model indices and be sure that they match up with
57 // the indices 0,1,2,3,... of the projected model we build here
58 // keep the base ccy in every case
59 for (Size i = 0; i < cam_->components(CrossAssetModel::AssetType::IR); ++i) {
60 if (i == 0 || cam_->irlgm1f(i)->currency() == domCcy || cam_->irlgm1f(i)->currency() == forCcy) {
61 lgm.push_back(cam_->lgm(i));
62 externalModelIndices.push_back(cam_->pIdx(CrossAssetModel::AssetType::IR, i));
63 cIdx.push_back(cam_->cIdx(CrossAssetModel::AssetType::IR, i));
64 if (i > 0) {
65 fx.push_back(cam_->fxbs(i - 1));
66 externalModelIndices.push_back(cam_->pIdx(CrossAssetModel::AssetType::FX, i - 1));
67 cIdx.push_back(cam_->cIdx(CrossAssetModel::AssetType::FX, i - 1));
68 }
69 }
70 }
71
72 std::sort(externalModelIndices.begin(), externalModelIndices.end());
73 std::sort(cIdx.begin(), cIdx.end());
74
75 // build correlation matrix
76 Matrix corr(cIdx.size(), cIdx.size(), 1.0);
77 for (Size i = 0; i < cIdx.size(); ++i) {
78 for (Size j = 0; j < i; ++j) {
79 corr(i, j) = corr(j, i) = cam_->correlation()(cIdx[i], cIdx[j]);
80 }
81 }
82 Handle<CrossAssetModel> model(QuantLib::ext::make_shared<CrossAssetModel>(lgm, fx, corr));
83 // we assume that the model has the pricing discount curves attached already, so
84 // we leave the discountCurves vector empty here
85
86 // build the pricing engine
87
88 // NPV should be in domCcy, consistent with the npv currency of an ORE FX Option Trade
89 auto engine = QuantLib::ext::make_shared<McCamFxOptionEngine>(
90 model, domCcy, forCcy, domCcy, parseSequenceType(engineParameter("Training.Sequence")),
91 parseSequenceType(engineParameter("Pricing.Sequence")), parseInteger(engineParameter("Training.Samples")),
92 parseInteger(engineParameter("Pricing.Samples")), parseInteger(engineParameter("Training.Seed")),
93 parseInteger(engineParameter("Pricing.Seed")), parseInteger(engineParameter("Training.BasisFunctionOrder")),
94 parsePolynomType(engineParameter("Training.BasisFunction")),
96 parseSobolRsgDirectionIntegers(engineParameter("SobolDirectionIntegers")), discountCurves, simulationDates_,
97 externalModelIndices, parseBool(engineParameter("MinObsDate")),
98 parseRegressorModel(engineParameter("RegressorModel", {}, false, "Simple")),
99 parseRealOrNull(engineParameter("RegressionVarianceCutoff", {}, false, std::string())));
100
101 return engine;
102}
103
104} // namespace data
105} // namespace ore
Engine builder for FX Options.
const std::vector< Date > simulationDates_
Definition: fxoption.hpp:89
QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate, const bool useFxSpot) override
Definition: fxoption.cpp:35
const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > cam_
Definition: fxoption.hpp:88
const string & engine() const
Return the engine name.
const string & model() const
Return the model name.
std::string engineParameter(const std::string &p, const std::vector< std::string > &qualifiers={}, const bool mandatory=true, const std::string &defaultValue="") const
Build a cross asset model.
Cross asset model data.
FX component data for the cross asset model.
SequenceType parseSequenceType(const std::string &s)
Convert string to sequence type.
Definition: parsers.cpp:668
QuantLib::LsmBasisSystem::PolynomialType parsePolynomType(const std::string &s)
Convert text to QuantLib::LsmBasisSystem::PolynomialType.
Definition: parsers.cpp:527
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
SobolRsg::DirectionIntegers parseSobolRsgDirectionIntegers(const std::string &s)
Convert text to QuantLib::SobolRsg::DirectionIntegers.
Definition: parsers.cpp:579
Real parseRealOrNull(const string &s)
Convert text to Real, empty string to Null<Real>()
Definition: parsers.cpp:120
QuantExt::McMultiLegBaseEngine::RegressorModel parseRegressorModel(const std::string &s)
Convert text to QuantExt::McMultiLegBaseEngine::RegressorModel.
Definition: parsers.cpp:1418
SobolBrownianGenerator::Ordering parseSobolBrownianGeneratorOrdering(const std::string &s)
Convert text to QuantLib::SobolBrownianGenerator::Ordering.
Definition: parsers.cpp:567
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
Linear Gauss Markov model data.
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
Serializable Credit Default Swap.
Definition: namespaces.docs:23
string conversion utilities