Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
bondposition.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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/portfolio/bondposition.hpp
20 \brief Bond Position trade data model and serialization
21 \ingroup tradedata
22 */
23
24#pragma once
25
27
29
30namespace ore {
31namespace data {
32
33using namespace ore::data;
34
36public:
38 BondPositionData(const Real quantity, const std::vector<BondUnderlying>& underlyings)
40
41 Real quantity() const { return quantity_; }
42 const std::string& identifier() const { return identifier_; }
43 const std::vector<BondUnderlying>& underlyings() const { return underlyings_; }
44
45 void fromXML(XMLNode* node) override;
46 XMLNode* toXML(XMLDocument& doc) const override;
47
48 void populateFromBondBasketReferenceData(const QuantLib::ext::shared_ptr<ReferenceDataManager>& ref);
49
50private:
51 Real quantity_ = QuantLib::Null<Real>();
52 std::string identifier_;
53 std::vector<BondUnderlying> underlyings_;
54};
55
56class BondPosition : public Trade {
57public:
58 BondPosition() : Trade("BondPosition") {}
60 : Trade("BondPosition", env), originalData_(data), data_(data) {}
61
62 // trade interface
63 void build(const QuantLib::ext::shared_ptr<ore::data::EngineFactory>&) override;
64 void fromXML(XMLNode* node) override;
65 XMLNode* toXML(XMLDocument& doc) const override;
66 std::map<AssetClass, std::set<std::string>>
67 underlyingIndices(const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceDataManager = nullptr) const override;
68
69 // additional inspectors
70 const BondPositionData& data() const { return data_; }
71 const std::vector<ore::data::BondBuilder::Result>& bonds() const { return bonds_; }
72 const std::vector<Real>& weights() const { return weights_; }
73 const std::vector<Real>& bidAskAdjustments() const { return bidAskAdjustments_; }
74 bool isSingleCurrency() const { return isSingleCurrency_; }
75
76 /*! we allow to set the npv currency to a different currency than the default npv currency = first asset's
77 currency; in this case a conversion rate from the default to the new currency has to be provided */
78 void setNpvCurrencyConversion(const std::string& ccy, const Handle<Quote>& conversion);
79
80private:
82 // populated during build()
83 std::vector<BondBuilder::Result> bonds_;
84 std::vector<Real> weights_;
85 std::vector<Real> bidAskAdjustments_;
86 std::vector<Handle<Quote>> fxConversion_;
88};
89
90//! Equity Position instrument wrapper
92public:
93 BondPositionInstrumentWrapper(const Real quantity, const std::vector<QuantLib::ext::shared_ptr<QuantLib::Bond>>& bonds,
94 const std::vector<Real>& weights, const std::vector<Real>& bidAskAdjstments,
95 const std::vector<Handle<Quote>>& fxConversion = {});
96 void initialise(const std::vector<QuantLib::Date>& dates) override {}
97 void reset() override {}
98 QuantLib::Real NPV() const override;
99 const std::map<std::string,boost::any>& additionalResults() const override;
100 void updateQlInstruments() override {}
101
102 void setNpvCurrencyConversion(const Handle<Quote>& npvCcyConversion);
103
104private:
106 std::vector<QuantLib::ext::shared_ptr<QuantLib::Bond>> bonds_;
107 std::vector<Real> weights_;
108 std::vector<Real> bidAskAdjustments_;
109 std::vector<Handle<Quote>> fxConversion_;
110 Handle<Quote> npvCcyConversion_;
111};
112
113} // namespace data
114} // namespace ore
Bond trade data model and serialization.
std::vector< BondUnderlying > underlyings_
void populateFromBondBasketReferenceData(const QuantLib::ext::shared_ptr< ReferenceDataManager > &ref)
const std::vector< BondUnderlying > & underlyings() const
const std::string & identifier() const
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
BondPositionData(const Real quantity, const std::vector< BondUnderlying > &underlyings)
BondPositionData originalData_
const std::vector< Real > & bidAskAdjustments() const
BondPositionData data_
std::map< AssetClass, std::set< std::string > > underlyingIndices(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
const BondPositionData & data() const
void fromXML(XMLNode *node) override
std::vector< Handle< Quote > > fxConversion_
void setNpvCurrencyConversion(const std::string &ccy, const Handle< Quote > &conversion)
XMLNode * toXML(XMLDocument &doc) const override
const std::vector< Real > & weights() const
std::vector< Real > weights_
BondPosition(const Envelope &env, const BondPositionData &data)
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
bool isSingleCurrency() const
std::vector< Real > bidAskAdjustments_
std::vector< BondBuilder::Result > bonds_
const std::vector< ore::data::BondBuilder::Result > & bonds() const
Equity Position instrument wrapper.
QuantLib::Real NPV() const override
Return the NPV of this instrument.
const std::map< std::string, boost::any > & additionalResults() const override
Return the additional results of this instrument.
void updateQlInstruments() override
call update on enclosed instrument(s)
std::vector< Handle< Quote > > fxConversion_
void initialise(const std::vector< QuantLib::Date > &dates) override
Initialise with the given date grid.
std::vector< QuantLib::ext::shared_ptr< QuantLib::Bond > > bonds_
void reset() override
reset is called every time a new path is about to be priced.
void setNpvCurrencyConversion(const Handle< Quote > &npvCcyConversion)
Serializable object holding generic trade data, reporting dimensions.
Definition: envelope.hpp:51
Trade base class.
Definition: trade.hpp:55
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
Base class for all serializable classes.
Definition: xmlutils.hpp:101
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23