Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
adjustmentfactors.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 Quaternion Risk Management Ltd
3
4 This file is part of ORE, a free-software/open-source library
5 for transparent pricing and risk analysis - http://opensourcerisk.org
6
7 ORE is free software: you can redistribute it and/or modify it
8 under the terms of the Modified BSD License. You should have received a
9 copy of the license along with this program.
10 The license is also available online at <http://opensourcerisk.org>
11
12 This program is distributed on the basis that it will form a useful
13 contribution to risk analytics and model standardisation, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
16*/
17
18#include <boost/test/unit_test.hpp>
20#include <oret/toplevelfixture.hpp>
21
22using namespace ore::data;
23using namespace QuantLib;
24using namespace boost::unit_test_framework;
25using namespace std;
26
27BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
28
29BOOST_AUTO_TEST_SUITE(AdjustmentFactorsTest)
30
31BOOST_AUTO_TEST_CASE(testAdjustmentFactors) {
32 BOOST_TEST_MESSAGE("Testing AdjustmentFactors...");
33
34 Date asof(28, September, 2018);
35
36 AdjustmentFactors adjFactors(asof);
37 adjFactors.addFactor("Equity1", Date(1, January, 2010), 0.5);
38 adjFactors.addFactor("Equity1", Date(8, November, 2013), 5);
39 adjFactors.addFactor("Equity1", Date(14, October, 2017), 0.1);
40
41 BOOST_CHECK_EQUAL(adjFactors.getFactor("Equity1", Date(10, December, 2009)), 0.25);
42 BOOST_CHECK_EQUAL(adjFactors.getFactor("Equity1", Date(12, February, 2012)), 0.5);
43 BOOST_CHECK_EQUAL(adjFactors.getFactor("Equity1", Date(6, October, 2015)), 0.10);
44 BOOST_CHECK_EQUAL(adjFactors.getFactor("Equity1", Date(27, September, 2018)), 1.0);
45}
46
47BOOST_AUTO_TEST_CASE(testAdjustmentFactorsFromXml) {
48 BOOST_TEST_MESSAGE("Testing parsing of Adjustment Factors from XML");
49
50 // Create an XML string representation of the Adjustment Factors curve configuration
51 string factorsXml;
52 factorsXml.append("<AdditionalData>");
53 factorsXml.append(" <AdjustmentFactors>");
54 factorsXml.append(" <AdjustmentFactor>");
55 factorsXml.append(" <Date>2018-09-28</Date>");
56 factorsXml.append(" <Quote>Equity1</Quote>");
57 factorsXml.append(" <Factor>0.5</Factor>");
58 factorsXml.append(" </AdjustmentFactor>");
59 factorsXml.append(" </AdjustmentFactors>");
60 factorsXml.append("</AdditionalData>");
61
62 // Create the XMLNode
63 XMLDocument doc;
64 doc.fromXMLString(factorsXml);
65 XMLNode* factorsNode = doc.getFirstNode("AdditionalData");
66
67 Date asof(30, September, 2018);
68
69 // Parse Adjustment Factors curve configuration from XML
70 AdjustmentFactors adjFactors(asof);
71 adjFactors.fromXML(factorsNode);
72
73 // Check fields
74 BOOST_CHECK_EQUAL(adjFactors.getFactor("Equity1", Date(27, September, 2018)), 0.5);
75}
76
77BOOST_AUTO_TEST_SUITE_END()
78
79BOOST_AUTO_TEST_SUITE_END()
Class to hold market data adjustment factors - for example equity stock splits.
QuantLib::Real getFactor(const std::string &name, const QuantLib::Date &d) const
Returns the adjustment factor for a name on a given date.
virtual void fromXML(ore::data::XMLNode *node) override
void addFactor(std::string name, QuantLib::Date d, QuantLib::Real factor)
Add an adjustment factor.
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
void fromXMLString(const string &xmlString)
load a document from a hard-coded string
Definition: xmlutils.cpp:103
XMLNode * getFirstNode(const string &name) const
Definition: xmlutils.cpp:116
BOOST_AUTO_TEST_CASE(testAdjustmentFactors)