Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
fxtarf.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/make_shared.hpp>
#include <ored/configuration/conventions.hpp>
#include <ored/configuration/curveconfigurations.hpp>
#include <ored/marketdata/csvloader.hpp>
#include <ored/marketdata/todaysmarketparameters.hpp>
#include <ored/portfolio/tarf.hpp>
#include <ored/portfolio/scriptedtrade.hpp>
#include <ored/portfolio/builders/scriptedtrade.hpp>
#include <ored/marketdata/todaysmarket.hpp>
#include <ored/portfolio/enginedata.hpp>
#include <ored/portfolio/enginefactory.hpp>
#include <ored/portfolio/portfolio.hpp>
#include <oret/datapaths.hpp>
#include <oret/toplevelfixture.hpp>
#include <ql/time/date.hpp>
#include <ql/pricingengines/blackformula.hpp>
#include <boost/math/distributions/normal.hpp>
#include <iostream>
#include <iomanip>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testNPV)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testNPV  )

Definition at line 57 of file fxtarf.cpp.

57 {
58 BOOST_TEST_MESSAGE("Testing Fx TaRF...");
59
63
64 Settings::instance().evaluationDate() = Date(31, Dec, 2018);
65 Date asof = Settings::instance().evaluationDate();
66 // Market
67 auto conventions = QuantLib::ext::make_shared<Conventions>();
68 conventions->fromFile(TEST_INPUT_FILE("conventions.xml"));
69 InstrumentConventions::instance().setConventions(conventions);
70
71 auto todaysMarketParams = QuantLib::ext::make_shared<TodaysMarketParameters>();
72 todaysMarketParams->fromFile(TEST_INPUT_FILE("todaysmarket.xml"));
73 auto curveConfigs = QuantLib::ext::make_shared<CurveConfigurations>();
74 curveConfigs->fromFile(TEST_INPUT_FILE("curveconfig.xml"));
75 auto loader = QuantLib::ext::make_shared<CSVLoader>(TEST_INPUT_FILE("market.txt"), TEST_INPUT_FILE("fixings.txt"), false);
76 auto market = QuantLib::ext::make_shared<TodaysMarket>(asof, todaysMarketParams, loader, curveConfigs, false);
77
78 // Portfolio to test market
79 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
80 engineData->fromFile(TEST_INPUT_FILE("pricingengine.xml"));
81 QuantLib::ext::shared_ptr<EngineFactory> factory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
82
83 // move cleanup to fixture once this code is in ore minus
84 struct cleanup {
85 ~cleanup() { ore::data::ScriptLibraryStorage::instance().clear(); }
86 } cleanup;
88 library.fromFile(TEST_INPUT_FILE("scriptlibrary.xml"));
89 ore::data::ScriptLibraryStorage::instance().set(std::move(library));
90
91 // Read in the trade
92 Portfolio p;
93 string trade = "FX_TaRF";
94 string portfolioFile = trade + ".xml";
95 p.fromFile(TEST_INPUT_FILE(portfolioFile));
96 BOOST_CHECK_NO_THROW(p.build(factory));
97
98 const Real spot = 1.1469;
99 const Real tol = 0.01;
100
101 // Test case 1: An FxTARF with no KnockOutBarrier,one fixing and one leverage range should be equivalent to an
102 // FxForward
103 BOOST_CHECK_NO_THROW(p.get("FX_TARF_1")->instrument()->NPV());
104 BOOST_TEST_MESSAGE(p.get("FX_TARF_1")->instrument()->NPV() * spot);
105 BOOST_TEST_MESSAGE(p.get("FX_FORWARD_1")->instrument()->NPV());
106
107 BOOST_CHECK_CLOSE(p.get("FX_TARF_1")->instrument()->NPV() * spot, p.get("FX_FORWARD_1")->instrument()->NPV(), tol);
108
109 // Test case 2: An FxTARF with no KnockOutBarrier,several fixing dates and one leverage range should be equivalent
110 // to the sum of FxForwards
111 BOOST_CHECK_CLOSE(p.get("FX_TARF_2")->instrument()->NPV() * spot,
112 p.get("FX_FORWARD_2A")->instrument()->NPV() + p.get("FX_FORWARD_2B")->instrument()->NPV() +
113 p.get("FX_FORWARD_2C")->instrument()->NPV(),
114 tol);
115
116 // Test case 3: The Value of an FxTARF with varying leverage ranges should be sum of FxTARFs with those individual
117 // leverages (and zero for the other ranges)
118 BOOST_CHECK_CLOSE(p.get("FX_TARF_3")->instrument()->NPV() * spot,
119 (p.get("FX_TARF_3A")->instrument()->NPV() + p.get("FX_TARF_3B")->instrument()->NPV() +
120 p.get("FX_TARF_3C")->instrument()->NPV()) *
121 spot,
122 tol);
123}
Utility class for loading market quotes and fixings from a file.
Definition: csvloader.hpp:41
Repository for currency dependent market conventions.
Container class for all Curve Configurations.
Pricing engine description.
Definition: enginedata.hpp:41
Pricing Engine Factory class.
void clear()
Clear all builders.
Singleton to hold conventions.
Serializable portfolio.
Definition: portfolio.hpp:43
void build(const QuantLib::ext::shared_ptr< EngineFactory > &, const std::string &context="unspecified", const bool emitStructuredError=true)
Call build on all trades in the portfolio, the context is included in error messages.
Definition: portfolio.cpp:122
QuantLib::ext::shared_ptr< Trade > get(const std::string &id) const
Definition: portfolio.cpp:194
void fromFile(const std::string &filename)
Definition: xmlutils.cpp:150
#define ORE_REGISTER_TRADE_BUILDER(NAME, CLASS, OVERWRITE)
#define ORE_REGISTER_ENGINE_BUILDER(CLASS, OVERWRITE)
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
vector< string > curveConfigs
+ Here is the call graph for this function: