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
20
21#include <ql/cashflows/fixedratecoupon.hpp>
22#include <ql/cashflows/simplecashflow.hpp>
23
24#include <boost/make_shared.hpp>
25
26using namespace QuantLib;
27
28namespace QuantExt {
29
30Deposit::Deposit(const Real nominal, const Rate rate, const Period& tenor, const Natural fixingDays,
31 const Calendar& calendar, const BusinessDayConvention convention, const bool endOfMonth,
32 const DayCounter& dayCounter, const Date& tradeDate, const bool isLong, const Period forwardStart) {
33
34 leg_.resize(3);
35 index_ = QuantLib::ext::make_shared<IborIndex>("deposit-helper-index", tenor, fixingDays, Currency(), calendar, convention,
36 endOfMonth, dayCounter);
37 // move to next good day
38 Date referenceDate = calendar.adjust(tradeDate);
39 startDate_ = index_->valueDate(referenceDate);
40 fixingDate_ = index_->fixingDate(startDate_);
41 maturityDate_ = index_->maturityDate(startDate_);
42 Real w = isLong ? 1.0 : -1.0;
43 leg_[0] = QuantLib::ext::make_shared<Redemption>(-w * nominal, startDate_);
44 leg_[1] =
45 QuantLib::ext::make_shared<FixedRateCoupon>(maturityDate_, w * nominal, rate, dayCounter, startDate_, maturityDate_);
46 leg_[2] = QuantLib::ext::make_shared<Redemption>(w * nominal, maturityDate_);
47}
48
49bool Deposit::isExpired() const { return detail::simple_event(maturityDate_).hasOccurred(); }
50
52 Instrument::setupExpired();
53 fairRate_ = Null<Real>();
54}
55
57
58 Deposit::arguments* arguments = dynamic_cast<Deposit::arguments*>(args);
59 QL_REQUIRE(arguments, "wrong argument type in deposit");
63}
64
65void Deposit::fetchResults(const PricingEngine::results* r) const {
66
67 Instrument::fetchResults(r);
68 const Deposit::results* results = dynamic_cast<const Deposit::results*>(r);
69 QL_REQUIRE(results, "wrong result type");
71}
72
74 QL_REQUIRE(leg.size() == 3,
75 "deposit arguments: unexpected number of cash flows (" << leg.size() << "), should be 3");
76}
77
79
80 Instrument::results::reset();
81 fairRate = Null<Real>();
82}
83} // namespace QuantExt
QuantLib::ext::shared_ptr< IborIndex > index
Definition: deposit.hpp:88
void validate() const override
Definition: deposit.cpp:73
void reset() override
Definition: deposit.cpp:78
Real fairRate() const
Definition: deposit.hpp:65
void setupArguments(PricingEngine::arguments *) const override
Definition: deposit.cpp:56
bool isExpired() const override
Definition: deposit.cpp:49
QuantLib::ext::shared_ptr< IborIndex > index_
Definition: deposit.hpp:79
Deposit(const Real nominal, const Rate rate, const Period &tenor, const Natural fixingDays, const Calendar &calendar, const BusinessDayConvention convention, const bool endOfMonth, const DayCounter &dayCounter, const Date &tradeDate, const bool isLong=true, const Period forwardStart=0 *Days)
Definition: deposit.cpp:30
void setupExpired() const override
Definition: deposit.cpp:51
void fetchResults(const PricingEngine::results *) const override
Definition: deposit.cpp:65
deposit instrument