Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crlgmbuilder.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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
23
24#include <ql/currencies/america.hpp>
25#include <ql/termstructures/credit/flathazardrate.hpp>
26
27using namespace QuantLib;
28using namespace QuantExt;
29using namespace std;
30
31namespace ore {
32namespace data {
33
34CrLgmBuilder::CrLgmBuilder(const QuantLib::ext::shared_ptr<ore::data::Market>& market, const QuantLib::ext::shared_ptr<CrLgmData>& data,
35 const std::string& configuration)
36 : market_(market), configuration_(configuration), data_(data) {
37
38 string name = data->name();
39 LOG("LgmCalibration for name " << name << ", configuration is " << configuration);
40
41 modelDefaultCurve_ = RelinkableHandle<DefaultProbabilityTermStructure>(*market_->defaultCurve(name, configuration)->curve());
42
43 QL_REQUIRE(!data_->calibrateA() && !data_->calibrateH(), "CrLgmBuilder does not support calibration currently");
44
45 QL_REQUIRE(data_->aParamType() == ParamType::Constant, "CrLgmBuilder only supports constant volatility currently");
46 QL_REQUIRE(data_->hParamType() == ParamType::Constant, "CrLgmBuilder only supports constant reversion currently");
47
48 Array aTimes(data_->aTimes().begin(), data_->aTimes().end());
49 Array hTimes(data_->hTimes().begin(), data_->hTimes().end());
50 Array alpha(data_->aValues().begin(), data_->aValues().end());
51 Array h(data_->hValues().begin(), data_->hValues().end());
52
53 // the currency does not matter here
55 QuantLib::ext::make_shared<QuantExt::CrLgm1fConstantParametrization>(USDCurrency(), modelDefaultCurve_, alpha[0], h[0], name);
56
57 LOG("Apply shift horizon and scale");
58
59 QL_REQUIRE(data_->shiftHorizon() >= 0.0, "shift horizon must be non negative");
60 QL_REQUIRE(data_->scaling() > 0.0, "scaling must be positive");
61
62 if (data_->shiftHorizon() > 0.0) {
63 LOG("Apply shift horizon " << data_->shiftHorizon() << " to the " << data_->qualifier() << " CR-LGM model");
64 parametrization_->shift() = data_->shiftHorizon();
65 }
66
67 if (data_->scaling() != 1.0) {
68 LOG("Apply scaling " << data_->scaling() << " to the " << data_->qualifier() << " CR-LGM model");
69 parametrization_->scaling() = data_->scaling();
70 }
71}
72} // namespace data
73} // namespace ore
RelinkableHandle< DefaultProbabilityTermStructure > modelDefaultCurve_
CrLgmBuilder(const QuantLib::ext::shared_ptr< ore::data::Market > &market, const QuantLib::ext::shared_ptr< CrLgmData > &data, const std::string &configuration=Market::defaultConfiguration)
QuantLib::ext::shared_ptr< ore::data::Market > market_
QuantLib::ext::shared_ptr< CrLgmData > data_
QuantLib::ext::shared_ptr< QuantExt::CrLgm1fParametrization > parametrization_
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552
Serializable Credit Default Swap.
Definition: namespaces.docs:23
string name