Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
deposit.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/termstructures/yield/piecewiseyieldcurve.hpp>
22#include <ql/termstructures/yield/ratehelpers.hpp>
23#include <ql/time/calendars/target.hpp>
24#include <ql/time/daycounters/actual360.hpp>
26
27#include <boost/make_shared.hpp>
28
29using namespace QuantLib;
30using namespace QuantExt;
31using namespace boost::unit_test_framework;
32
33BOOST_FIXTURE_TEST_SUITE(QuantExtTestSuite, qle::test::TopLevelFixture)
34
35BOOST_AUTO_TEST_SUITE(DepositTest)
36
37BOOST_AUTO_TEST_CASE(testRepricing) {
38
39 BOOST_TEST_MESSAGE("Testing Repricing of a Deposit on a depo curve...");
40
41 SavedSettings backup;
42
43 Date refDate = Date(8, Dec, 2016);
44 Settings::instance().evaluationDate() = refDate;
45
46 std::vector<QuantLib::ext::shared_ptr<RateHelper> > helper;
47 helper.push_back(QuantLib::ext::make_shared<DepositRateHelper>(Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.02)),
48 7 * Months, 2, TARGET(), ModifiedFollowing, false,
49 Actual360()));
50
51 Handle<YieldTermStructure> curve(
52 QuantLib::ext::make_shared<PiecewiseYieldCurve<Discount, LogLinear> >(refDate, helper, Actual365Fixed()));
53
54 QuantLib::ext::shared_ptr<PricingEngine> engine = QuantLib::ext::make_shared<DepositEngine>(curve);
55
56 Deposit depo(100.0, 0.02, 7 * Months, 2, TARGET(), ModifiedFollowing, false, Actual360(), refDate, true, 0 * Days);
57 depo.setPricingEngine(engine);
58
59 Real tol = 1.0E-8;
60 BOOST_CHECK_MESSAGE(std::abs(depo.NPV()) <= tol,
61 "Deposit NPV(" << depo.NPV() << ") could not be verified, expected 0.0");
62
63 BOOST_CHECK_MESSAGE(std::abs(depo.fairRate() - 0.02) <= tol,
64 "Deposit fair rate (" << depo.fairRate() << ") could not be verified, expected 0.02");
65}
66
67BOOST_AUTO_TEST_SUITE_END()
68
69BOOST_AUTO_TEST_SUITE_END()
Deposit Instrument.
Definition: deposit.hpp:43
Real fairRate() const
Definition: deposit.hpp:65
deposit engine
QuantLib::BootstrapHelper< QuantLib::OptionletVolatilityStructure > helper
BOOST_AUTO_TEST_CASE(testRepricing)
Definition: deposit.cpp:37
Fixture that can be used at top level.