QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
forwardrateagreement.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006 Allen Kuo
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#include <ql/event.hpp>
21#include <ql/indexes/iborindex.hpp>
22#include <ql/instruments/forwardrateagreement.hpp>
23#include <utility>
24#include <iostream>
25
26namespace QuantLib {
27
29 const Date& maturityDate,
30 Position::Type type,
31 Rate strikeForwardRate,
32 Real notionalAmount,
33 const ext::shared_ptr<IborIndex>& index,
34 Handle<YieldTermStructure> discountCurve,
35 bool useIndexedCoupon)
36 : ForwardRateAgreement(index, valueDate, maturityDate, type, strikeForwardRate,
37 notionalAmount, std::move(discountCurve)) {
38 useIndexedCoupon_ = useIndexedCoupon;
39 }
40
42 Position::Type type,
43 Rate strikeForwardRate,
44 Real notionalAmount,
45 const ext::shared_ptr<IborIndex>& index,
46 Handle<YieldTermStructure> discountCurve)
47 : ForwardRateAgreement(index, valueDate, type, strikeForwardRate,
48 notionalAmount, std::move(discountCurve)) {}
49
50 ForwardRateAgreement::ForwardRateAgreement(const ext::shared_ptr<IborIndex>& index,
51 const Date& valueDate,
52 Position::Type type,
53 Rate strikeForwardRate,
54 Real notionalAmount,
55 Handle<YieldTermStructure> discountCurve)
56 : ForwardRateAgreement(index, valueDate, index->maturityDate(valueDate), type,
57 strikeForwardRate, notionalAmount, std::move(discountCurve)) {
58 useIndexedCoupon_ = true;
59 }
60
61 ForwardRateAgreement::ForwardRateAgreement(const ext::shared_ptr<IborIndex>& index,
62 const Date& valueDate,
63 const Date& maturityDate,
64 Position::Type type,
65 Rate strikeForwardRate,
66 Real notionalAmount,
67 Handle<YieldTermStructure> discountCurve)
68 : fraType_(type), notionalAmount_(notionalAmount), index_(index),
69 useIndexedCoupon_(false), dayCounter_(index->dayCounter()),
70 calendar_(index->fixingCalendar()), businessDayConvention_(index->businessDayConvention()),
71 valueDate_(valueDate), maturityDate_(maturityDate),
72 discountCurve_(std::move(discountCurve)) {
73
75
76 registerWith(Settings::instance().evaluationDate());
78
79 QL_REQUIRE(notionalAmount > 0.0, "notionalAmount must be positive");
80 QL_REQUIRE(valueDate_ < maturityDate_, "valueDate must be earlier than maturityDate");
81
82 strikeForwardRate_ = InterestRate(strikeForwardRate,
83 index->dayCounter(),
84 Simple, Once);
86 }
87
89 return index_->fixingDate(valueDate_);
90 }
91
94 }
95
97 calculate();
98 return amount_;
99 }
100
102 calculate();
103 return forwardRate_;
104 }
105
109 }
110
114 discountCurve_.empty() ? index_->forwardingTermStructure() : discountCurve_;
115 NPV_ = amount_ * discount->discount(valueDate_);
116 }
117
121 InterestRate(index_->fixing(fixingDate()), index_->dayCounter(), Simple, Once);
122 else
123 // par coupon approximation
125 InterestRate((index_->forwardingTermStructure()->discount(valueDate_) /
126 index_->forwardingTermStructure()->discount(maturityDate_) -
127 1.0) /
128 index_->dayCounter().yearFraction(valueDate_, maturityDate_),
129 index_->dayCounter(), Simple, Once);
130 }
131
134 Integer sign = fraType_ == Position::Long? 1 : -1;
135 Rate F = forwardRate_.rate();
138 amount_ = notionalAmount_ * sign * (F - K) * T / (1.0 + F * T);
139 }
140
141}
Date adjust(const Date &, BusinessDayConvention convention=Following) const
Definition: calendar.cpp:84
Concrete date class.
Definition: date.hpp:125
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
virtual bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const
returns true if an event has already occurred before a date
Definition: event.cpp:28
Forward rate agreement (FRA) class
void performCalculations() const override
Handle< YieldTermStructure > discountCurve_
InterestRate strikeForwardRate_
aka FRA fixing rate, contract rate
bool isExpired() const override
A FRA expires/settles on the value date.
QL_DEPRECATED ForwardRateAgreement(const Date &valueDate, const Date &maturityDate, Position::Type type, Rate strikeForwardRate, Real notionalAmount, const ext::shared_ptr< IborIndex > &index, Handle< YieldTermStructure > discountCurve={}, bool useIndexedCoupon=true)
InterestRate forwardRate_
aka FRA rate (the market forward rate)
Date maturityDate_
maturityDate of the underlying index; not the date the FRA is settled.
Real amount() const
The payoff on the value date.
Date valueDate_
the valueDate is the date the underlying index starts accruing and the FRA is settled.
InterestRate forwardRate() const
Returns the relevant forward rate associated with the FRA term.
BusinessDayConvention businessDayConvention_
ext::shared_ptr< IborIndex > index_
Shared handle to an observable.
Definition: handle.hpp:41
void calculate() const override
Definition: instrument.hpp:129
virtual void setupExpired() const
Definition: instrument.hpp:140
Concrete interest rate class.
const DayCounter & dayCounter() const
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
@ Once
only once, e.g., a zero-coupon
Definition: frequency.hpp:38
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
STL namespace.