Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
cbo.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/europe.hpp>
25#include <ql/experimental/credit/onefactorgaussiancopula.hpp>
26#include <ql/experimental/credit/randomdefaultmodel.hpp>
27
28namespace ore {
29namespace data {
30
31static DefaultProbKey dummyDefaultProbKey() {
32 Currency currency = QuantLib::EURCurrency();
33 Seniority seniority = NoSeniority;
34 QuantLib::ext::shared_ptr<DefaultType> defaultType(new DefaultType());
35 vector<QuantLib::ext::shared_ptr<DefaultType>> defaultTypes(1, defaultType);
36 DefaultProbKey key(defaultTypes, currency, seniority);
37 return key;
38}
39
40QuantLib::ext::shared_ptr<PricingEngine> CboMCEngineBuilder::engine(const QuantLib::ext::shared_ptr<Pool>& pool) {
41
42 // get parameter
43 Size samples = parseInteger(engineParameter("Samples"));
44 Size bins = parseInteger(engineParameter("Bins"));
45 long seed = parseInteger(engineParameter("Seed"));
46 double corr = parseReal(engineParameter("Correlation"));
47
48 double errorTolerance = parseReal(engineParameter("ErrorTolerance", {}, false, "1.0e-6"));
49
50 string lossDistributionPeriods_str = engineParameter("LossDistributionPeriods");
51 std::vector<string> lossDistributionPeriods_vec = parseListOfValues(lossDistributionPeriods_str);
52 std::vector<QuantLib::Period> lossDistributionPeriods;
53 for (Size i = 0; i < lossDistributionPeriods_vec.size(); i++)
54 lossDistributionPeriods.push_back(parsePeriod(lossDistributionPeriods_vec[i]));
55
56 QuantLib::ext::shared_ptr<SimpleQuote> correlationQuote(new SimpleQuote(corr));
57 Handle<Quote> correlationHandle = Handle<Quote>(correlationQuote);
58 QuantLib::ext::shared_ptr<OneFactorCopula> gaussianCopula(new OneFactorGaussianCopula(correlationHandle));
59 RelinkableHandle<OneFactorCopula> copula(gaussianCopula);
60
61 vector<DefaultProbKey> keys(pool->size(), dummyDefaultProbKey());
62
63 QuantLib::ext::shared_ptr<RandomDefaultModel> rdm(new GaussianRandomDefaultModel(pool, keys, copula, 1.e-6, seed));
64
65 return QuantLib::ext::make_shared<QuantExt::MonteCarloCBOEngine>(rdm, samples, bins, errorTolerance,
66 lossDistributionPeriods);
67};
68
69} // namespace data
70} // namespace ore
const string & engine() const
Return the engine name.
std::string engineParameter(const std::string &p, const std::vector< std::string > &qualifiers={}, const bool mandatory=true, const std::string &defaultValue="") const
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
Definition: parsers.cpp:171
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
@ data
Definition: log.hpp:77
std::vector< string > parseListOfValues(string s, const char escape, const char delim, const char quote)
Definition: parsers.cpp:639
Serializable Credit Default Swap.
Definition: namespaces.docs:23