Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
payment.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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#include "toplevelfixture.hpp"
20#include <boost/test/unit_test.hpp>
21#include <ql/currencies/europe.hpp>
22#include <ql/quotes/simplequote.hpp>
23#include <ql/termstructures/yield/flatforward.hpp>
24#include <ql/time/calendars/target.hpp>
25#include <ql/time/daycounters/actualactual.hpp>
28
29#include <boost/make_shared.hpp>
30
31using namespace QuantLib;
32using namespace QuantExt;
33using namespace boost::unit_test_framework;
34
35BOOST_FIXTURE_TEST_SUITE(QuantExtTestSuite, qle::test::TopLevelFixture)
36
37BOOST_AUTO_TEST_SUITE(PaymentTest)
38
39BOOST_AUTO_TEST_CASE(testDomesicPayment) {
40
41 BOOST_TEST_MESSAGE("Testing Domestic Payment NPV...");
42
43 SavedSettings backup;
44
45 Date refDate = Date(8, Dec, 2016);
46 Settings::instance().evaluationDate() = refDate;
47 Date paymentDate = refDate + 10 * Years;
48 Payment payment(100.0, EURCurrency(), paymentDate);
49 BOOST_CHECK_EQUAL(payment.cashFlow()->amount(), 100.0);
50 Handle<YieldTermStructure> yts(QuantLib::ext::make_shared<FlatForward>(0, TARGET(), 0.03, ActualActual(ActualActual::ISDA)));
51 QuantLib::ext::shared_ptr<PricingEngine> engine = QuantLib::ext::make_shared<PaymentDiscountingEngine>(yts);
52 payment.setPricingEngine(engine);
53
54 Real expectedNpv = 100.0 * yts->discount(paymentDate);
55
56 BOOST_CHECK_SMALL(payment.NPV() - expectedNpv, 0.000001);
57}
58
59BOOST_AUTO_TEST_CASE(testForeignPayment) {
60
61 BOOST_TEST_MESSAGE("Testing Foreign Payment NPV...");
62
63 SavedSettings backup;
64
65 Date refDate = Date(8, Dec, 2016);
66 Settings::instance().evaluationDate() = refDate;
67 Date paymentDate = refDate + 10 * Years;
68 Payment payment(100.0, EURCurrency(), paymentDate);
69 Handle<YieldTermStructure> yts(QuantLib::ext::make_shared<FlatForward>(0, TARGET(), 0.03, ActualActual(ActualActual::ISDA)));
70 Handle<Quote> fx(QuantLib::ext::make_shared<SimpleQuote>(0.789));
71 QuantLib::ext::shared_ptr<PricingEngine> engine = QuantLib::ext::make_shared<PaymentDiscountingEngine>(yts, fx);
72 payment.setPricingEngine(engine);
73
74 Real expectedNpv = 100.0 * yts->discount(paymentDate) * fx->value();
75
76 BOOST_CHECK_SMALL(payment.NPV() - expectedNpv, 0.000001);
77}
78
79BOOST_AUTO_TEST_SUITE_END()
80
81BOOST_AUTO_TEST_SUITE_END()
Payment Instrument.
Definition: payment.hpp:43
const QuantLib::ext::shared_ptr< SimpleCashFlow > & cashFlow() const
Definition: payment.hpp:60
payment instrument
Single payment discounting engine.
BOOST_AUTO_TEST_CASE(testDomesicPayment)
Definition: payment.cpp:39
Fixture that can be used at top level.