QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
forward.hpp
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
24#ifndef quantlib_forward_hpp
25#define quantlib_forward_hpp
26
27#include <ql/instrument.hpp>
28#include <ql/position.hpp>
29#include <ql/time/calendar.hpp>
30#include <ql/time/daycounter.hpp>
31#include <ql/interestrate.hpp>
32#include <ql/types.hpp>
33#include <ql/handle.hpp>
34#include <ql/payoff.hpp>
35#include <ql/termstructures/yieldtermstructure.hpp>
36
37namespace QuantLib {
38
40
66 class Forward : public Instrument {
67 public:
69
70 virtual Date settlementDate() const;
71 const Calendar& calendar() const;
73 const DayCounter& dayCounter() const;
79 bool isExpired() const override;
81
83 virtual Real spotValue() const = 0;
86 incomeDiscountCurve) const = 0;
87
89
90
94 virtual Real forwardValue() const;
95
105 InterestRate impliedYield(Real underlyingSpotValue,
108 Compounding compoundingConvention,
109 const DayCounter& dayCounter);
111 protected:
115 Natural settlementDays,
116 ext::shared_ptr<Payoff> payoff,
117 const Date& valueDate,
118 const Date& maturityDate,
120
121 void performCalculations() const override;
126
131 ext::shared_ptr<Payoff> payoff_;
141 };
142
143
145 class ForwardTypePayoff : public Payoff {
146 public:
148 : type_(type),strike_(strike) {
149 QL_REQUIRE(strike >= 0.0,"negative strike given");
150 }
151 Position::Type forwardType() const { return type_; };
152 Real strike() const { return strike_; };
154
155 std::string name() const override { return "Forward"; }
156 std::string description() const override;
157 Real operator()(Real price) const override;
159 protected:
162 };
163
164
165
166 // inline definitions
167
168 inline const Calendar& Forward::calendar() const {
169 return calendar_;
170 }
171
174 }
175
176 inline const DayCounter& Forward::dayCounter() const {
177 return dayCounter_;
178 }
179
181 return discountCurve_;
182 }
183
186 }
187
188
189 inline std::string ForwardTypePayoff::description() const {
190 std::ostringstream result;
191 result << name() << ", " << strike() << " strike";
192 return result.str();
193 }
194
196 switch (type_) {
197 case Position::Long:
198 return (price-strike_);
199 case Position::Short:
200 return (strike_-price);
201 default:
202 QL_FAIL("unknown/illegal position type");
203 }
204 }
205
206}
207
208
209#endif
210
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Abstract base forward class.
Definition: forward.hpp:66
Calendar calendar_
Definition: forward.hpp:128
virtual Real spotValue() const =0
returns spot value/price of an underlying financial instrument
void performCalculations() const override
Definition: forward.cpp:83
Real underlyingSpotValue_
Definition: forward.hpp:125
Handle< YieldTermStructure > discountCurve_
Definition: forward.hpp:138
bool isExpired() const override
returns whether the instrument is still tradable.
Definition: forward.cpp:55
const DayCounter & dayCounter() const
Definition: forward.hpp:176
ext::shared_ptr< Payoff > payoff_
Definition: forward.hpp:131
Handle< YieldTermStructure > discountCurve() const
term structure relevant to the contract (e.g. repo curve)
Definition: forward.hpp:180
const Calendar & calendar() const
Definition: forward.hpp:168
InterestRate impliedYield(Real underlyingSpotValue, Real forwardValue, Date settlementDate, Compounding compoundingConvention, const DayCounter &dayCounter)
Definition: forward.cpp:68
virtual Real forwardValue() const
forward value/price of underlying, discounting income/dividends
Definition: forward.cpp:61
DayCounter dayCounter_
Definition: forward.hpp:127
virtual Real spotIncome(const Handle< YieldTermStructure > &incomeDiscountCurve) const =0
NPV of income/dividends/storage-costs etc. of underlying instrument.
Natural settlementDays_
Definition: forward.hpp:130
virtual Date settlementDate() const
Definition: forward.cpp:48
BusinessDayConvention businessDayConvention() const
Definition: forward.hpp:172
Date maturityDate_
maturityDate of the forward contract or delivery date of underlying
Definition: forward.hpp:137
Real underlyingIncome_
Definition: forward.hpp:123
Handle< YieldTermStructure > incomeDiscountCurve() const
term structure that discounts the underlying's income cash flows
Definition: forward.hpp:184
Handle< YieldTermStructure > incomeDiscountCurve_
Definition: forward.hpp:140
BusinessDayConvention businessDayConvention_
Definition: forward.hpp:129
Class for forward type payoffs.
Definition: forward.hpp:145
Real operator()(Real price) const override
Definition: forward.hpp:195
std::string description() const override
Definition: forward.hpp:189
std::string name() const override
Definition: forward.hpp:155
Position::Type forwardType() const
Definition: forward.hpp:151
ForwardTypePayoff(Position::Type type, Real strike)
Definition: forward.hpp:147
Shared handle to an observable.
Definition: handle.hpp:41
Abstract instrument class.
Definition: instrument.hpp:44
Concrete interest rate class.
Abstract base class for option payoffs.
Definition: payoff.hpp:36
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Definition: any.hpp:35
Compounding
Interest rate coumpounding rule.
Definition: compounding.hpp:32