19#include <boost/make_shared.hpp>
20#include <boost/test/unit_test.hpp>
26#include <oret/toplevelfixture.hpp>
27#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
28#include <ql/termstructures/yield/flatforward.hpp>
29#include <ql/time/daycounters/actualactual.hpp>
32using namespace boost::unit_test_framework;
44 asof_ = Date(3, Feb, 2015);
46 QuantLib::ext::shared_ptr<Conventions> conventions = InstrumentConventions::instance().conventions();
49 QuantLib::ext::shared_ptr<ore::data::Convention> usdChfConv(
51 QuantLib::ext::shared_ptr<ore::data::Convention> usdGbpConv(
53 QuantLib::ext::shared_ptr<ore::data::Convention> usdEurConv(
56 conventions->add(usdChfConv);
57 conventions->add(usdGbpConv);
58 conventions->add(usdEurConv);
59 InstrumentConventions::instance().setConventions(conventions);
68 std::map<std::string, Handle<Quote>> quotes;
69 quotes[
"EURUSD"] = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.2));
70 quotes[
"EURGBP"] = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.4));
71 quotes[
"EURCHF"] = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.3));
72 fx_ = QuantLib::ext::make_shared<FXTriangulation>(quotes);
81 Handle<YieldTermStructure> flatRateYts(Real forward) {
82 QuantLib::ext::shared_ptr<YieldTermStructure> yts(
new FlatForward(0, NullCalendar(), forward, ActualActual(ActualActual::ISDA)));
83 return Handle<YieldTermStructure>(yts);
85 Handle<BlackVolTermStructure> flatRateFxv(Volatility forward) {
86 QuantLib::ext::shared_ptr<BlackVolTermStructure> fxv(
new BlackConstantVol(0, NullCalendar(), forward, ActualActual(ActualActual::ISDA)));
87 return Handle<BlackVolTermStructure>(fxv);
94void test(
string nearDate,
string farDate,
string nearBoughtCurrency,
double nearBoughtAmount,
string nearSoldCurrency,
95 double nearSoldAmount,
double farBoughtAmount,
double farSoldAmount,
const QuantLib::ext::shared_ptr<Market>& market) {
98 Settings::instance().evaluationDate() = market->asofDate();
103 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
104 engineData->model(
"FxForward") =
"DiscountedCashflows";
105 engineData->engine(
"FxForward") =
"DiscountingFxForwardEngine";
106 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
109 FxForward fxFor1(env1, nearDate, nearSoldCurrency, nearSoldAmount, nearBoughtCurrency, nearBoughtAmount);
111 fxFor1.build(engineFactory);
115 FxForward fxFor2(env2, farDate, nearSoldCurrency, farBoughtAmount, nearBoughtCurrency, farSoldAmount);
116 fxFor2.build(engineFactory);
122 FxSwap fxswap(env3, nearDate, farDate, nearBoughtCurrency, nearBoughtAmount, nearSoldCurrency, nearSoldAmount,
123 farBoughtAmount, farSoldAmount);
124 fxswap.build(engineFactory);
125 fxswap.instrument()->NPV();
126 Real fx1 = fxFor1.instrument()->NPV();
127 Real fx2 = fxFor2.instrument()->NPV();
128 Real npvForward = fx2 - fx1;
129 if (fxswap.instrument()->NPV() != npvForward)
130 BOOST_FAIL(
"The FxSwap has NPV: " << fxswap.instrument()->NPV()
131 <<
", which does not equal the sum of two Fxforwards: " << npvForward);
135BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
137BOOST_AUTO_TEST_SUITE(FXSwapTests)
141 BOOST_TEST_MESSAGE(
"Testing FXSwap...");
143 QuantLib::ext::shared_ptr<Market> market = QuantLib::ext::make_shared<TestMarket>();
145 string nearDate =
"2015-10-27";
146 string farDate =
"2015-11-03";
147 string nearBoughtCurrency =
"EUR";
148 Real nearBoughtAmount = 224557621.490000;
149 string nearSoldCurrency =
"USD";
150 Real nearSoldAmount = 250000000.000000;
151 Real farBoughtAmount = 250018000.00;
152 Real farSoldAmount = 224552207.77;
154 test(nearDate, farDate, nearBoughtCurrency, nearBoughtAmount, nearSoldCurrency, nearSoldAmount, farBoughtAmount,
155 farSoldAmount, market);
157 nearDate =
"2015-07-14";
158 farDate =
"2015-11-16";
159 nearBoughtCurrency =
"CHF";
160 nearBoughtAmount = 97000000;
161 nearSoldCurrency =
"USD";
162 nearSoldAmount = 103718911.06;
163 farBoughtAmount = 103923787.150000;
164 farSoldAmount = 96737000.000000;
166 test(nearDate, farDate, nearBoughtCurrency, nearBoughtAmount, nearSoldCurrency, nearSoldAmount, farBoughtAmount,
167 farSoldAmount, market);
169 nearDate =
"2015-08-04";
170 farDate =
"2015-11-30";
171 nearBoughtCurrency =
"GBP";
172 nearBoughtAmount = 100227439.19;
173 nearSoldCurrency =
"USD";
174 nearSoldAmount = 156000000;
175 farBoughtAmount = 156148000.000000;
176 farSoldAmount = 100400372.110000;
178 test(nearDate, farDate, nearBoughtCurrency, nearBoughtAmount, nearSoldCurrency, nearSoldAmount, farBoughtAmount,
179 farSoldAmount, market);
182BOOST_AUTO_TEST_SUITE_END()
184BOOST_AUTO_TEST_SUITE_END()
Serializable object holding generic trade data, reporting dimensions.
Container for storing FX Spot quote conventions.
static const string defaultConfiguration
Default configuration label.
map< pair< string, string >, Handle< BlackVolTermStructure > > fxVols_
QuantLib::ext::shared_ptr< FXTriangulation > fx_
map< tuple< string, YieldCurveType, string >, Handle< YieldTermStructure > > yieldCurves_
A class to hold pricing engine parameters.
FX Forward data model and serialization.
FX Option data model and serialization.
FX Swap data model and serialization.
An implementation of the Market class that stores the required objects in maps.
BOOST_AUTO_TEST_CASE(testFXSwap)