Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
AdjustmentFactors Class Reference

Class to hold market data adjustment factors - for example equity stock splits. More...

#include <ored/marketdata/adjustmentfactors.hpp>

+ Inheritance diagram for AdjustmentFactors:
+ Collaboration diagram for AdjustmentFactors:

Public Member Functions

 AdjustmentFactors (QuantLib::Date asof)
 
bool hasFactor (const std::string &name) const
 Check if we have any adjustment factors for a name. More...
 
QuantLib::Real getFactor (const std::string &name, const QuantLib::Date &d) const
 Returns the adjustment factor for a name on a given date. More...
 
void addFactor (std::string name, QuantLib::Date d, QuantLib::Real factor)
 Add an adjustment factor. More...
 
- Public Member Functions inherited from XMLSerializable
virtual ~XMLSerializable ()
 
virtual void fromXML (XMLNode *node)=0
 
virtual XMLNodetoXML (XMLDocument &doc) const =0
 
void fromFile (const std::string &filename)
 
void toFile (const std::string &filename) const
 
void fromXMLString (const std::string &xml)
 Parse from XML string. More...
 
std::string toXMLString () const
 Parse from XML string. More...
 

Serilaisation

QuantLib::Date asof_
 Asof date - only apply adjustments before this date. More...
 
std::map< std::string, std::vector< std::pair< QuantLib::Date, QuantLib::Real > > > data_
 Map of names to adjustment factors. More...
 
virtual void fromXML (ore::data::XMLNode *node) override
 
virtual ore::data::XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
std::set< std::string > names () const
 names with adjustment factors More...
 
std::set< QuantLib::Date > dates (const std::string &name) const
 dates with contributions to an adjustment factor for a name More...
 
QuantLib::Real getFactorContribution (const std::string &name, const QuantLib::Date &d) const
 gets the contribution to an adjustment factor for a name on a given date More...
 

Detailed Description

Class to hold market data adjustment factors - for example equity stock splits.

Definition at line 28 of file adjustmentfactors.hpp.

Constructor & Destructor Documentation

◆ AdjustmentFactors()

AdjustmentFactors ( QuantLib::Date  asof)

Definition at line 30 of file adjustmentfactors.hpp.

30: asof_(asof){};
QuantLib::Date asof_
Asof date - only apply adjustments before this date.

Member Function Documentation

◆ hasFactor()

bool hasFactor ( const std::string &  name) const

Check if we have any adjustment factors for a name.

Definition at line 26 of file adjustmentfactors.cpp.

26{ return data_.find(name) != data_.end(); }
std::map< std::string, std::vector< std::pair< QuantLib::Date, QuantLib::Real > > > data_
Map of names to adjustment factors.
string name
+ Here is the caller graph for this function:

◆ getFactor()

Real getFactor ( const std::string &  name,
const QuantLib::Date &  d 
) const

Returns the adjustment factor for a name on a given date.

Definition at line 28 of file adjustmentfactors.cpp.

28 {
29 Real baseFactor = 1.0;
30 // If no adjustments return a factor of 1
31 if (!hasFactor(name))
32 return baseFactor;
33
34 // for the given name loop through all the adjustments
35 // adjustments are applied backwards to a time series,
36 // if the date is before asof date:
37 // we multiply by the factor from any future adjustments but before the asof date,
38 // this ensures all data is on the same scale at the asof date
39 // if date is after asof date:
40 // we divide by the factor from any historical adjustments between asof and date
41 for (auto f : data_.at(name)) {
42 if (d < f.first && asof_ > f.first) {
43 baseFactor = baseFactor * f.second;
44 }
45 if (asof_ < f.first && f.first <= d) {
46 baseFactor = baseFactor / f.second;
47 }
48 }
49 return baseFactor;
50}
bool hasFactor(const std::string &name) const
Check if we have any adjustment factors for a name.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addFactor()

void addFactor ( std::string  name,
QuantLib::Date  d,
QuantLib::Real  factor 
)

Add an adjustment factor.

Definition at line 52 of file adjustmentfactors.cpp.

52 {
53 data_[name].push_back(std::pair<Date, Real>(d, factor));
54}
+ Here is the caller graph for this function:

◆ fromXML()

void fromXML ( ore::data::XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 56 of file adjustmentfactors.cpp.

56 {
57 XMLUtils::checkNode(node, "AdditionalData");
58
59 XMLNode* childNode = XMLUtils::locateNode(node, "AdjustmentFactors");
60 for (XMLNode* child = XMLUtils::getChildNode(childNode); child; child = XMLUtils::getNextSibling(child)) {
61
62 Date date = parseDate(XMLUtils::getChildValue(child, "Date", true));
63 std::string quote = XMLUtils::getChildValue(child, "Quote", true);
64 Real factor = XMLUtils::getChildValueAsDouble(child, "Factor", true);
65
66 addFactor(quote, date, factor);
67 }
68}
void addFactor(std::string name, QuantLib::Date d, QuantLib::Real factor)
Add an adjustment factor.
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
static XMLNode * locateNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:393
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
Get a node's next sibling node.
Definition: xmlutils.cpp:484
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

XMLNode * toXML ( ore::data::XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Definition at line 70 of file adjustmentfactors.cpp.

70 {
71 XMLNode* node = doc.allocNode("AdjustmentFactors");
72 for (auto d : data_) {
73 for (auto f : d.second) {
74 XMLNode* factorNode = XMLUtils::addChild(doc, node, "AdjustmentFactor");
75 XMLUtils::addChild(doc, factorNode, "Date", ore::data::to_string(f.first));
76 XMLUtils::addChild(doc, factorNode, "Quote", d.first);
77 XMLUtils::addChild(doc, factorNode, "Factor", f.second);
78 }
79 }
80 return node;
81}
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

◆ names()

std::set< std::string > names ( ) const

names with adjustment factors

Definition at line 83 of file adjustmentfactors.cpp.

83 {
84 std::set<std::string> result;
85 for (auto const& m : data_)
86 result.insert(m.first);
87 return result;
88}

◆ dates()

std::set< QuantLib::Date > dates ( const std::string &  name) const

dates with contributions to an adjustment factor for a name

Definition at line 90 of file adjustmentfactors.cpp.

90 {
91 std::set<QuantLib::Date> result;
92 auto d = data_.find(name);
93 if (d != data_.end()) {
94 for (auto const& m : d->second)
95 result.insert(m.first);
96 }
97 return result;
98}

◆ getFactorContribution()

QuantLib::Real getFactorContribution ( const std::string &  name,
const QuantLib::Date &  d 
) const

gets the contribution to an adjustment factor for a name on a given date

Definition at line 100 of file adjustmentfactors.cpp.

100 {
101 auto adj = data_.find(name);
102 if (adj != data_.end()) {
103 auto it = std::find_if(adj->second.begin(), adj->second.end(),
104 [&d](const std::pair<QuantLib::Date, QuantLib::Real>& m) { return m.first == d; });
105 if (it != adj->second.end())
106 return it->second;
107 }
108 return 1.0;
109}

Member Data Documentation

◆ asof_

QuantLib::Date asof_
private

Asof date - only apply adjustments before this date.

Definition at line 54 of file adjustmentfactors.hpp.

◆ data_

std::map<std::string, std::vector<std::pair<QuantLib::Date, QuantLib::Real> > > data_
private

Map of names to adjustment factors.

Definition at line 56 of file adjustmentfactors.hpp.