Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
cptycalculator.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
19/*! \file engine/cptycalculator.hpp
20 \brief The counterparty cube calculator interface
21 \ingroup simulation
22*/
23
27
28namespace ore {
29namespace analytics {
30
31void SurvivalProbabilityCalculator::calculate(const std::string& name, Size nameIndex,
32 const QuantLib::ext::shared_ptr<SimMarket>& simMarket, QuantLib::ext::shared_ptr<NPVCube>& outputCube,
33 const Date& date, Size dateIndex, Size sample, bool isCloseOut) {
34 if (!isCloseOut)
35 outputCube->set(survProb(name, simMarket, date), nameIndex, dateIndex, sample, index_);
36}
37
38void SurvivalProbabilityCalculator::calculateT0(const std::string& name, Size nameIndex,
39 const QuantLib::ext::shared_ptr<SimMarket>& simMarket,
40 QuantLib::ext::shared_ptr<NPVCube>& outputCube) {
41 outputCube->setT0(survProb(name, simMarket), nameIndex, index_);
42}
43
44Real SurvivalProbabilityCalculator::survProb(const std::string& name,
45 const QuantLib::ext::shared_ptr<SimMarket>& simMarket,
46 const Date& date) {
47 Real survivalProb = 1.0;
48
49 try {
50 Handle<DefaultProbabilityTermStructure> dts = simMarket->defaultCurve(name, configuration_)->curve();
51 QL_REQUIRE(!dts.empty(), "Default curve missing for counterparty " << name);
52 survivalProb = dts->survivalProbability(date == Date() ? dts->referenceDate() : date);
53 } catch (std::exception& e) {
54 ALOG("Failed to calculate surv prob of counterparty " << name << " : " << e.what());
55 survivalProb = 1.0;
56 } catch (...) {
57 ALOG("Failed to calculate surv prob of counterparty " << name << " : Unhandled Exception");
58 survivalProb = 1.0;
59 }
60 return survivalProb;
61}
62} // namespace analytics
63} // namespace ore
Real survProb(const std::string &name, const QuantLib::ext::shared_ptr< SimMarket > &simMarket, const Date &date=Date())
virtual void calculate(const std::string &name, Size nameIndex, const QuantLib::ext::shared_ptr< SimMarket > &simMarket, QuantLib::ext::shared_ptr< NPVCube > &outputCube, const Date &date, Size dateIndex, Size sample, bool isCloseOut=false) override
virtual void calculateT0(const std::string &name, Size nameIndex, const QuantLib::ext::shared_ptr< SimMarket > &simMarket, QuantLib::ext::shared_ptr< NPVCube > &outputCube) override
The counterparty cube calculator interface.
#define ALOG(text)
string name