QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
forward.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/instruments/forward.hpp>
22#include <ql/termstructures/yieldtermstructure.hpp>
23#include <utility>
24
25namespace QuantLib {
26
28 Calendar calendar,
29 BusinessDayConvention businessDayConvention,
30 Natural settlementDays,
31 ext::shared_ptr<Payoff> payoff,
32 const Date& valueDate,
33 const Date& maturityDate,
34 Handle<YieldTermStructure> discountCurve)
35 : dayCounter_(std::move(dayCounter)), calendar_(std::move(calendar)),
36 businessDayConvention_(businessDayConvention), settlementDays_(settlementDays),
37 payoff_(std::move(payoff)), valueDate_(valueDate), maturityDate_(maturityDate),
38 discountCurve_(std::move(discountCurve)) {
39
42
43 registerWith(Settings::instance().evaluationDate());
45 }
46
47
49 Date d = calendar_.advance(Settings::instance().evaluationDate(),
51 return std::max(d,valueDate_);
52 }
53
54
55 bool Forward::isExpired() const {
58 }
59
60
62 calculate();
65 }
66
67
69 Real forwardValue,
70 Date settlementDate,
71 Compounding comp,
72 const DayCounter& dayCounter) {
73
75 Real compoundingFactor = forwardValue/
76 (underlyingSpotValue-spotIncome(incomeDiscountCurve_)) ;
77 return InterestRate::impliedRate(compoundingFactor,
78 dayCounter, comp, Annual,
79 t);
80 }
81
82
84
85 QL_REQUIRE(!discountCurve_.empty(),
86 "null term structure set to Forward");
87
88 ext::shared_ptr<ForwardTypePayoff> ftpayoff =
89 ext::dynamic_pointer_cast<ForwardTypePayoff>(payoff_);
90 Real fwdValue = forwardValue();
91 NPV_ = (*ftpayoff)(fwdValue) * discountCurve_->discount(maturityDate_);
92 }
93
94}
calendar class
Definition: calendar.hpp:61
Date adjust(const Date &, BusinessDayConvention convention=Following) const
Definition: calendar.cpp:84
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Definition: calendar.cpp:130
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
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
Calendar calendar_
Definition: forward.hpp:128
Forward(DayCounter dayCounter, Calendar calendar, BusinessDayConvention businessDayConvention, Natural settlementDays, ext::shared_ptr< Payoff > payoff, const Date &valueDate, const Date &maturityDate, Handle< YieldTermStructure > discountCurve=Handle< YieldTermStructure >())
Definition: forward.cpp:27
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
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
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
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_
Definition: forward.hpp:140
BusinessDayConvention businessDayConvention_
Definition: forward.hpp:129
Shared handle to an observable.
Definition: handle.hpp:41
void calculate() const override
Definition: instrument.hpp:129
Concrete interest rate class.
static InterestRate impliedRate(Real compound, const DayCounter &resultDC, Compounding comp, Frequency freq, Time t)
implied interest rate for a given compound factor at a given time.
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
BusinessDayConvention
Business Day conventions.
@ Annual
once a year
Definition: frequency.hpp:39
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
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
STL namespace.