Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
security.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
19/*! \file ored/marketdata/bondspread.cpp
20 \brief
21 \ingroup
22*/
23
27
28namespace ore {
29namespace data {
30
31Security::Security(const Date& asof, SecuritySpec spec, const Loader& loader, const CurveConfigurations& curveConfigs) {
32
33 try {
34 const QuantLib::ext::shared_ptr<SecurityConfig>& config = curveConfigs.securityConfig(spec.securityID());
35
36 string spreadQuote = config->spreadQuote();
37 if (spreadQuote != "" && loader.has(spreadQuote, asof)) {
38 QuantLib::ext::shared_ptr<SecuritySpreadQuote> q =
39 QuantLib::ext::dynamic_pointer_cast<SecuritySpreadQuote>(loader.get(spreadQuote, asof));
40 QL_REQUIRE(q, "Failed to cast " << spreadQuote << " to SecuritySpreadQuote");
41 spread_ = q->quote();
42 }
43
44 // get recovery quote
45 string recoveryQuote = config->recoveryRatesQuote();
46 if (recoveryQuote != "" && loader.has(recoveryQuote, asof)) {
47 QuantLib::ext::shared_ptr<RecoveryRateQuote> q =
48 QuantLib::ext::dynamic_pointer_cast<RecoveryRateQuote>(loader.get(recoveryQuote, asof));
49 QL_REQUIRE(q, "Failed to cast " << recoveryQuote << " to RecoveryRateQuote");
50 recoveryRate_ = q->quote();
51 }
52
53 // get cpr quote
54 string cprQuote = config->cprQuote();
55 if (cprQuote != "" && loader.has(cprQuote,asof)) {
56 QuantLib::ext::shared_ptr<CPRQuote> q = QuantLib::ext::dynamic_pointer_cast<CPRQuote>(loader.get(cprQuote, asof));
57 QL_REQUIRE(q, "Failed to cast " << cprQuote << " to CPRQuote");
58 cpr_ = q->quote();
59 }
60
61 // get price quote
62 string priceQuote = config->priceQuote();
63 if (priceQuote != "" && loader.has(priceQuote,asof)) {
64 QuantLib::ext::shared_ptr<BondPriceQuote> q =
65 QuantLib::ext::dynamic_pointer_cast<BondPriceQuote>(loader.get(priceQuote, asof));
66 QL_REQUIRE(q, "Failed to cast " << priceQuote << " to BondPriceQuote");
67 price_ = q->quote();
68 }
69
70 } catch (std::exception& e) {
71 QL_FAIL("Security building failed for curve " << spec.curveConfigID() << " on date " << io::iso_date(asof)
72 << ": " << e.what());
73 } catch (...) {
74 QL_FAIL("Security building failed: unknown error");
75 }
76
77 return;
78}
79} // namespace data
80} // namespace ore
Container class for all Curve Configurations.
const std::string & curveConfigID() const
Definition: curvespec.hpp:83
Market data loader base class.
Definition: loader.hpp:47
virtual QuantLib::ext::shared_ptr< MarketDatum > get(const std::string &name, const QuantLib::Date &d) const
get quote by its unique name, throws if not existent, override in derived classes for performance
Definition: loader.cpp:24
virtual bool has(const std::string &name, const QuantLib::Date &d) const
Default implementation, returns false if get throws or returns a null pointer.
Definition: loader.cpp:53
Handle< Quote > spread_
Definition: security.hpp:51
Handle< Quote > price_
Definition: security.hpp:52
Handle< Quote > cpr_
Definition: security.hpp:54
Security(const Date &asof, SecuritySpec spec, const Loader &loader, const CurveConfigurations &curveConfigs)
Constructor.
Definition: security.cpp:31
Handle< Quote > recoveryRate_
Definition: security.hpp:53
Security description.
Definition: curvespec.hpp:396
const string & securityID() const
Definition: curvespec.hpp:403
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
Market data representation.
Serializable Credit Default Swap.
Definition: namespaces.docs:23
A wrapper class for holding Bond Spread quotes.
vector< string > curveConfigs