Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
analyticeuropeanforwardengine.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2003 Ferdinando Ametrano
3 Copyright (C) 2007 StatPro Italia srl
4
5 This file is part of QuantLib, a free-software/open-source library
6 for financial quantitative analysts and developers - http://quantlib.org/
7
8 QuantLib is free software: you can redistribute it and/or modify it
9 under the terms of the QuantLib license. You should have received a
10 copy of the license along with this program; if not, please email
11 <quantlib-dev@lists.sf.net>. The license is also available online at
12 <http://quantlib.org/license.shtml>.
13
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*
20 Copyright (C) 2020 Quaternion Risk Management Ltd
21 All rights reserved.
22
23 This file is part of ORE, a free-software/open-source library
24 for transparent pricing and risk analysis - http://opensourcerisk.org
25
26 ORE is free software: you can redistribute it and/or modify it
27 under the terms of the Modified BSD License. You should have received a
28 copy of the license along with this program.
29 The license is also available online at <http://opensourcerisk.org>
30
31 This program is distributed on the basis that it will form a useful
32 contribution to risk analytics and model standardisation, but WITHOUT
33 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
35*/
36
38#include <ql/pricingengines/blackcalculator.hpp>
39#include <ql/exercise.hpp>
40
41using QuantLib::Date;
42using QuantLib::DiscountFactor;
43using QuantLib::GeneralizedBlackScholesProcess;
44using QuantLib::Handle;
45using QuantLib::Null;
46using QuantLib::PricingEngine;
47using QuantLib::Real;
48using QuantLib::Settings;
49using QuantLib::StrikedTypePayoff;
50using QuantLib::Time;
51using QuantLib::VanillaOption;
52using QuantLib::YieldTermStructure;
53using QuantLib::Handle;
54using QuantLib::Exercise;
55using QuantLib::DayCounter;
56using QuantLib::Error;
57
58namespace QuantExt {
59
61 const QuantLib::ext::shared_ptr<QuantLib::GeneralizedBlackScholesProcess>& process)
62 : process_(process) {
63 registerWith(process_);
64 }
65
67 const QuantLib::ext::shared_ptr<QuantLib::GeneralizedBlackScholesProcess>& process,
68 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve)
69 : process_(process), discountCurve_(discountCurve) {
70 registerWith(process_);
71 registerWith(discountCurve_);
72 }
73
75
76 // if the discount curve is not specified, we default to the
77 // risk free rate curve embedded within the GBM process
78 QuantLib::ext::shared_ptr<YieldTermStructure> discountPtr =
79 discountCurve_.empty() ?
80 process_->riskFreeRate().currentLink() :
81 discountCurve_.currentLink();
82
83 QL_REQUIRE(arguments_.exercise->type() == Exercise::European,
84 "not an European option");
85
86 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff =
87 QuantLib::ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
88 QL_REQUIRE(payoff, "non-striked payoff given");
89
90 Real variance =
91 process_->blackVolatility()->blackVariance(
92 arguments_.exercise->lastDate(),
93 payoff->strike());
94 DiscountFactor dividendDiscount =
95 process_->dividendYield()->discount(
96 arguments_.forwardDate);
97 DiscountFactor df;
98 if (arguments_.paymentDate != Date())
99 df = discountPtr->discount(arguments_.paymentDate);
100 else
101 df = discountPtr->discount(arguments_.exercise->lastDate());
102 DiscountFactor riskFreeDiscountForFwdEstimation =
103 process_->riskFreeRate()->discount(arguments_.forwardDate);
104 Real spot = process_->stateVariable()->value();
105 QL_REQUIRE(spot > 0.0, "negative or null underlying given");
106 Real forwardPrice = spot * dividendDiscount / riskFreeDiscountForFwdEstimation;
107
108 QuantLib::BlackCalculator black(payoff, forwardPrice, std::sqrt(variance),df);
109
110
111 results_.value = black.value();
112 results_.delta = black.delta(spot);
113 results_.deltaForward = black.deltaForward();
114 results_.elasticity = black.elasticity(spot);
115 results_.gamma = black.gamma(spot);
116
117 DayCounter rfdc = discountPtr->dayCounter();
118 DayCounter divdc = process_->dividendYield()->dayCounter();
119 DayCounter voldc = process_->blackVolatility()->dayCounter();
120 Time t = rfdc.yearFraction(process_->riskFreeRate()->referenceDate(),
121 arguments_.exercise->lastDate());
122 results_.rho = black.rho(t);
123
124 t = divdc.yearFraction(process_->dividendYield()->referenceDate(),
125 arguments_.exercise->lastDate());
126 results_.dividendRho = black.dividendRho(t);
127
128 t = voldc.yearFraction(process_->blackVolatility()->referenceDate(),
129 arguments_.exercise->lastDate());
130 results_.vega = black.vega(t);
131 try {
132 results_.theta = black.theta(spot, t);
133 results_.thetaPerDay =
134 black.thetaPerDay(spot, t);
135 } catch (Error&) {
136 results_.theta = Null<Real>();
137 results_.thetaPerDay = Null<Real>();
138 }
139
140 results_.strikeSensitivity = black.strikeSensitivity();
141 results_.itmCashProbability = black.itmCashProbability();
142
143 Real tte = process_->blackVolatility()->timeFromReference(arguments_.exercise->lastDate());
144 results_.additionalResults["spot"] = spot;
145 results_.additionalResults["dividendDiscount"] = dividendDiscount;
146 results_.additionalResults["riskFreeDiscount"] = riskFreeDiscountForFwdEstimation;
147 results_.additionalResults["forward"] = forwardPrice;
148 results_.additionalResults["strike"] = payoff->strike();
149 results_.additionalResults["volatility"] = std::sqrt(variance / tte);
150 results_.additionalResults["timeToExpiry"] = tte;
151 results_.additionalResults["discountFactor"] = df;
152 }
153
154}
155
Analytic European Forward engine.
const Instrument::results * results_
Definition: cdsoption.cpp:81
QuantLib::ext::shared_ptr< QuantLib::GeneralizedBlackScholesProcess > process_
QuantLib::Handle< QuantLib::YieldTermStructure > discountCurve_
AnalyticEuropeanForwardEngine(const QuantLib::ext::shared_ptr< QuantLib::GeneralizedBlackScholesProcess > &)
RandomVariable variance(const RandomVariable &r)
RandomVariable black(const RandomVariable &omega, const RandomVariable &t, const RandomVariable &strike, const RandomVariable &forward, const RandomVariable &impliedVol)
Swap::arguments * arguments_