QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
forwardrateagreement.cpp
Go to the documentation of this file.
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>
23#include <utility>
24#include <iostream>
25
26namespace QuantLib {
27
28 ForwardRateAgreement::ForwardRateAgreement(const ext::shared_ptr<IborIndex>& index,
29 const Date& valueDate,
30 Position::Type type,
31 Rate strikeForwardRate,
32 Real notionalAmount,
33 Handle<YieldTermStructure> discountCurve)
34 : ForwardRateAgreement(index, valueDate, index->maturityDate(valueDate), type,
35 strikeForwardRate, notionalAmount, std::move(discountCurve)) {
36 useIndexedCoupon_ = true;
37 }
38
39 ForwardRateAgreement::ForwardRateAgreement(const ext::shared_ptr<IborIndex>& index,
40 const Date& valueDate,
41 const Date& maturityDate,
42 Position::Type type,
43 Rate strikeForwardRate,
44 Real notionalAmount,
45 Handle<YieldTermStructure> discountCurve)
46 : fraType_(type), notionalAmount_(notionalAmount), index_(index),
47 useIndexedCoupon_(false), dayCounter_(index->dayCounter()),
48 calendar_(index->fixingCalendar()), businessDayConvention_(index->businessDayConvention()),
49 valueDate_(valueDate), maturityDate_(maturityDate),
50 discountCurve_(std::move(discountCurve)) {
51
53
54 registerWith(Settings::instance().evaluationDate());
56
57 QL_REQUIRE(notionalAmount > 0.0, "notionalAmount must be positive");
58 QL_REQUIRE(valueDate_ < maturityDate_, "valueDate must be earlier than maturityDate");
59
60 strikeForwardRate_ = InterestRate(strikeForwardRate,
61 index->dayCounter(),
62 Simple, Once);
64 }
65
67 return index_->fixingDate(valueDate_);
68 }
69
72 }
73
75 calculate();
76 return amount_;
77 }
78
80 calculate();
81 return forwardRate_;
82 }
83
87 }
88
92 discountCurve_.empty() ? index_->forwardingTermStructure() : discountCurve_;
93 NPV_ = amount_ * discount->discount(valueDate_);
94 }
95
99 InterestRate(index_->fixing(fixingDate()), index_->dayCounter(), Simple, Once);
100 else
101 // par coupon approximation
103 InterestRate((index_->forwardingTermStructure()->discount(valueDate_) /
104 index_->forwardingTermStructure()->discount(maturityDate_) -
105 1.0) /
106 index_->dayCounter().yearFraction(valueDate_, maturityDate_),
107 index_->dayCounter(), Simple, Once);
108 }
109
112 Integer sign = fraType_ == Position::Long? 1 : -1;
116 amount_ = notionalAmount_ * sign * (F - K) * T / (1.0 + F * T);
117 }
118
119}
const YieldTermStructure & discountCurve_
Definition: cashflows.cpp:418
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.
InterestRate forwardRate_
aka FRA rate (the market forward rate)
ForwardRateAgreement(const ext::shared_ptr< IborIndex > &index, const Date &valueDate, Position::Type type, Rate strikeForwardRate, Real notionalAmount, Handle< YieldTermStructure > discountCurve={})
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:226
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Base class for events associated with a given date.
forward rate agreement
@ 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
base class for Inter-Bank-Offered-Rate indexes
Definition: any.hpp:37
STL namespace.
Real F
Definition: sabr.cpp:200