QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
analytic_cont_geom_av_price.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003, 2004 Ferdinando Ametrano
5 Copyright (C) 2007 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21#include <ql/exercise.hpp>
22#include <ql/pricingengines/asian/analytic_cont_geom_av_price.hpp>
23#include <ql/pricingengines/blackcalculator.hpp>
24#include <ql/processes/blackscholesprocess.hpp>
25#include <utility>
26
27namespace QuantLib {
28
31 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
32 : process_(std::move(process)) {
34 }
35
37 const {
39 "not a geometric average option");
40 QL_REQUIRE(arguments_.exercise->type() == Exercise::European,
41 "not an European Option");
42
43 Date exercise = arguments_.exercise->lastDate();
44
45 ext::shared_ptr<PlainVanillaPayoff> payoff =
46 ext::dynamic_pointer_cast<PlainVanillaPayoff>(arguments_.payoff);
47 QL_REQUIRE(payoff, "non-plain payoff given");
48
49 Volatility volatility =
50 process_->blackVolatility()->blackVol(exercise, payoff->strike());
51 Real variance =
52 process_->blackVolatility()->blackVariance(exercise,
53 payoff->strike());
54 DiscountFactor riskFreeDiscount =
55 process_->riskFreeRate()->discount(exercise);
56
57 DayCounter rfdc = process_->riskFreeRate()->dayCounter();
58 DayCounter divdc = process_->dividendYield()->dayCounter();
59 DayCounter voldc = process_->blackVolatility()->dayCounter();
60
61 Spread dividendYield = 0.5 * (
62 process_->riskFreeRate()->zeroRate(exercise, rfdc,
63 Continuous, NoFrequency).rate() +
64 process_->dividendYield()->zeroRate(exercise, divdc,
65 Continuous, NoFrequency).rate() +
66 volatility*volatility/6.0);
67
68 Time t_q = divdc.yearFraction(
69 process_->dividendYield()->referenceDate(), exercise);
70 DiscountFactor dividendDiscount = std::exp(-dividendYield*t_q);
71
72 Real spot = process_->stateVariable()->value();
73 QL_REQUIRE(spot > 0.0, "negative or null underlying");
74 Real forward = spot * dividendDiscount / riskFreeDiscount;
75
76 BlackCalculator black(payoff, forward, std::sqrt(variance/3.0),
77 riskFreeDiscount);
78
79 results_.value = black.value();
80 results_.delta = black.delta(spot);
81 results_.gamma = black.gamma(spot);
82
83 results_.dividendRho = black.dividendRho(t_q)/2.0;
84
85 Time t_r = rfdc.yearFraction(process_->riskFreeRate()->referenceDate(),
86 arguments_.exercise->lastDate());
87 results_.rho = black.rho(t_r) + 0.5 * black.dividendRho(t_q);
88
89 Time t_v = voldc.yearFraction(
90 process_->blackVolatility()->referenceDate(),
91 arguments_.exercise->lastDate());
92 results_.vega = black.vega(t_v)/std::sqrt(3.0) +
93 black.dividendRho(t_q)*volatility/6.0;
94 try {
95 results_.theta = black.theta(spot, t_v);
96 } catch (Error&) {
97 results_.theta = Null<Real>();
98 }
99 }
100
101}
102
AnalyticContinuousGeometricAveragePriceAsianEngine(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
virtual Real gamma(Real spot) const
virtual Real theta(Real spot, Time maturity) const
Real rho(Time maturity) const
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
Base error class.
Definition: errors.hpp:39
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
@ 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
Real Volatility
volatility
Definition: types.hpp:78
Real Spread
spreads on interest rates
Definition: types.hpp:74
Definition: any.hpp:35
STL namespace.