Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxforward.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
20
22
23namespace ore {
24namespace data {
25
26using namespace QuantLib;
27using namespace QuantExt;
28
29QuantLib::ext::shared_ptr<PricingEngine> CamAmcFxForwardEngineBuilder::engineImpl(const Currency& forCcy,
30 const Currency& domCcy) {
31
32 QL_REQUIRE(domCcy != forCcy, "CamAmcFxForwardEngineBuilder: domCcy = forCcy = " << domCcy.code());
33
34 std::vector<Size> externalModelIndices;
35 std::vector<Handle<YieldTermStructure>> discountCurves;
36 std::vector<Size> cIdx;
37 std::vector<QuantLib::ext::shared_ptr<IrModel>> lgm;
38 std::vector<QuantLib::ext::shared_ptr<FxBsParametrization>> fx;
39
40 // add the IR and FX components in the order they appear in the CAM; this way
41 // we can sort the external model indices and be sure that they match up with
42 // the indices 0,1,2,3,... of the projected model we build here
43 // keep the base ccy in every case
44 for (Size i = 0; i < cam_->components(CrossAssetModel::AssetType::IR); ++i) {
45 if (i == 0 || cam_->irlgm1f(i)->currency() == domCcy || cam_->irlgm1f(i)->currency() == forCcy) {
46 lgm.push_back(cam_->lgm(i));
47 externalModelIndices.push_back(cam_->pIdx(CrossAssetModel::AssetType::IR, i));
48 cIdx.push_back(cam_->cIdx(CrossAssetModel::AssetType::IR, i));
49 if (i > 0) {
50 fx.push_back(cam_->fxbs(i - 1));
51 externalModelIndices.push_back(cam_->pIdx(CrossAssetModel::AssetType::FX, i - 1));
52 cIdx.push_back(cam_->cIdx(CrossAssetModel::AssetType::FX, i - 1));
53 }
54 }
55 }
56
57 std::sort(externalModelIndices.begin(), externalModelIndices.end());
58 std::sort(cIdx.begin(), cIdx.end());
59
60 // build correlation matrix
61 Matrix corr(cIdx.size(), cIdx.size(), 1.0);
62 for (Size i = 0; i < cIdx.size(); ++i) {
63 for (Size j = 0; j < i; ++j) {
64 corr(i, j) = corr(j, i) = cam_->correlation()(cIdx[i], cIdx[j]);
65 }
66 }
67 Handle<CrossAssetModel> model(QuantLib::ext::make_shared<CrossAssetModel>(lgm, fx, corr));
68 // we assume that the model has the pricing discount curves attached already, so
69 // we leave the discountCurves vector empty here
70
71 // build the pricing engine
72
73 // NPV should be in domCcy, consistent with the npv currency of an ORE FX Forward Trade
74 auto engine = QuantLib::ext::make_shared<McCamFxForwardEngine>(
75 model, domCcy, forCcy, domCcy, parseSequenceType(engineParameter("Training.Sequence")),
76 parseSequenceType(engineParameter("Pricing.Sequence")), parseInteger(engineParameter("Training.Samples")),
77 parseInteger(engineParameter("Pricing.Samples")), parseInteger(engineParameter("Training.Seed")),
78 parseInteger(engineParameter("Pricing.Seed")), parseInteger(engineParameter("Training.BasisFunctionOrder")),
79 parsePolynomType(engineParameter("Training.BasisFunction")),
81 parseSobolRsgDirectionIntegers(engineParameter("SobolDirectionIntegers")), discountCurves, simulationDates_,
82 externalModelIndices, parseBool(engineParameter("MinObsDate")),
83 parseRegressorModel(engineParameter("RegressorModel", {}, false, "Simple")),
84 parseRealOrNull(engineParameter("RegressionVarianceCutoff", {}, false, std::string())));
85
86 return engine;
87}
88
89} // namespace data
90} // namespace ore
Engine builder for FX Forwards.
const std::vector< Date > simulationDates_
Definition: fxforward.hpp:84
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const Currency &forCcy, const Currency &domCcy) override
Definition: fxforward.cpp:29
const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > cam_
Definition: fxforward.hpp:83
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
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
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
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23