QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
analyticcliquetengine.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004, 2007 StatPro Italia srl
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/exercise.hpp>
21#include <ql/pricingengines/blackcalculator.hpp>
22#include <ql/pricingengines/cliquet/analyticcliquetengine.hpp>
23#include <utility>
24
25namespace QuantLib {
26
28 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
29 : process_(std::move(process)) {
31 }
32
34
35 QL_REQUIRE(arguments_.accruedCoupon == Null<Real>() &&
37 "this engine cannot price options already started");
38 QL_REQUIRE(arguments_.localCap == Null<Real>() &&
42 "this engine cannot price capped/floored options");
43
44 QL_REQUIRE(arguments_.exercise->type() == Exercise::European,
45 "not an European option");
46
47 ext::shared_ptr<PercentageStrikePayoff> moneyness =
48 ext::dynamic_pointer_cast<PercentageStrikePayoff>(
49 arguments_.payoff);
50 QL_REQUIRE(moneyness, "wrong payoff given");
51
52 std::vector<Date> resetDates = arguments_.resetDates;
53 resetDates.push_back(arguments_.exercise->lastDate());
54
55 Real underlying = process_->stateVariable()->value();
56 QL_REQUIRE(underlying > 0.0, "negative or null underlying");
57 Real strike = underlying * moneyness->strike();
58 ext::shared_ptr<StrikedTypePayoff> payoff(
59 new PlainVanillaPayoff(moneyness->optionType(),strike));
60
61 results_.value = 0.0;
62 results_.delta = results_.gamma = 0.0;
63 results_.theta = 0.0;
64 results_.rho = results_.dividendRho = 0.0;
65 results_.vega = 0.0;
66
67 for (Size i = 1; i < resetDates.size(); i++) {
68
69 Real weight =
70 process_->dividendYield()->discount(resetDates[i-1]);
71 DiscountFactor discount =
72 process_->riskFreeRate()->discount(resetDates[i]) /
73 process_->riskFreeRate()->discount(resetDates[i-1]);
74 DiscountFactor qDiscount =
75 process_->dividendYield()->discount(resetDates[i]) /
76 process_->dividendYield()->discount(resetDates[i-1]);
77 Real forward = underlying*qDiscount/discount;
78 Real variance =
79 process_->blackVolatility()->blackForwardVariance(
80 resetDates[i-1],resetDates[i],strike);
81
82 BlackCalculator black(payoff, forward, std::sqrt(variance), discount);
83
84 DayCounter rfdc = process_->riskFreeRate()->dayCounter();
85 DayCounter divdc = process_->dividendYield()->dayCounter();
86 DayCounter voldc = process_->blackVolatility()->dayCounter();
87
88 results_.value += weight * black.value();
89 results_.delta += weight * (black.delta(underlying) +
90 moneyness->strike() * discount *
91 black.beta());
92 results_.gamma += 0.0;
93 results_.theta += process_->dividendYield()->forwardRate(
94 resetDates[i-1], resetDates[i], rfdc, Continuous, NoFrequency) *
95 weight * black.value();
96
97 Time dt = rfdc.yearFraction(resetDates[i-1],resetDates[i]);
98 results_.rho += weight * black.rho(dt);
99
100 Time t = divdc.yearFraction(
101 process_->dividendYield()->referenceDate(),
102 resetDates[i-1]);
103 dt = divdc.yearFraction(resetDates[i-1],resetDates[i]);
104 results_.dividendRho += weight * (black.dividendRho(dt) -
105 t * black.value());
106
107 dt = voldc.yearFraction(resetDates[i-1], resetDates[i]);
108 results_.vega += weight * black.vega(dt);
109 }
110
111 }
112
113}
114
AnalyticCliquetEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process)
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
Black 1976 calculator class.
Real dividendRho(Time maturity) const
virtual Real delta(Real spot) const
Real vega(Time maturity) const
Real rho(Time maturity) const
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
template class providing a null value for a given type.
Definition: null.hpp:76
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Plain-vanilla payoff.
Definition: payoffs.hpp:105
@ NoFrequency
null frequency
Definition: frequency.hpp:37
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.