QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
hestonmodelhelper.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2005 Klaus Spanderen
5 Copyright (C) 2007 StatPro Italia srl
6 Copyright (C) 2015 Peter Caspers
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22#include <ql/exercise.hpp>
28#include <utility>
29
30
31namespace QuantLib {
32
34 Calendar calendar,
35 const Real s0,
36 const Real strikePrice,
37 const Handle<Quote>& volatility,
38 const Handle<YieldTermStructure>& riskFreeRate,
39 const Handle<YieldTermStructure>& dividendYield,
41 : BlackCalibrationHelper(volatility, errorType), maturity_(maturity),
42 calendar_(std::move(calendar)), s0_(Handle<Quote>(ext::make_shared<SimpleQuote>(s0))),
43 strikePrice_(strikePrice), riskFreeRate_(riskFreeRate), dividendYield_(dividendYield) {
44 registerWith(riskFreeRate);
45 registerWith(dividendYield);
46 }
47
49 Calendar calendar,
50 const Handle<Quote>& s0,
51 const Real strikePrice,
52 const Handle<Quote>& volatility,
53 const Handle<YieldTermStructure>& riskFreeRate,
54 const Handle<YieldTermStructure>& dividendYield,
56 : BlackCalibrationHelper(volatility, errorType), maturity_(maturity),
57 calendar_(std::move(calendar)), s0_(s0), strikePrice_(strikePrice),
58 riskFreeRate_(riskFreeRate), dividendYield_(dividendYield) {
59 registerWith(s0);
60 registerWith(riskFreeRate);
61 registerWith(dividendYield);
62 }
63
66 calendar_.advance(riskFreeRate_->referenceDate(), maturity_);
67 tau_ = riskFreeRate_->timeFromReference(exerciseDate_);
68 type_ = strikePrice_ * riskFreeRate_->discount(tau_) >=
69 s0_->value() * dividendYield_->discount(tau_)
72 ext::shared_ptr<StrikedTypePayoff> payoff(
74 ext::shared_ptr<Exercise> exercise =
75 ext::make_shared<EuropeanExercise>(exerciseDate_);
76 option_ = ext::make_shared<VanillaOption>(payoff, exercise);
78 }
79
81 calculate();
82 option_->setPricingEngine(engine_);
83 return option_->NPV();
84 }
85
87 calculate();
88 const Real stdDev = volatility * std::sqrt(maturity());
89 return blackFormula(
91 s0_->value() * dividendYield_->discount(tau_), stdDev);
92 }
93}
94
Black formula.
liquid Black76 market instrument used during calibration
void performCalculations() const override
Handle< Quote > volatility() const
returns the volatility Handle
ext::shared_ptr< PricingEngine > engine_
calendar class
Definition: calendar.hpp:61
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Definition: calendar.cpp:130
Shared handle to an observable.
Definition: handle.hpp:41
void performCalculations() const override
Real blackPrice(Real volatility) const override
Black or Bachelier price given a volatility.
Real modelValue() const override
returns the price of the instrument according to the model
const Handle< YieldTermStructure > dividendYield_
HestonModelHelper(const Period &maturity, Calendar calendar, Real s0, Real strikePrice, const Handle< Quote > &volatility, const Handle< YieldTermStructure > &riskFreeRate, const Handle< YieldTermStructure > &dividendYield, BlackCalibrationHelper::CalibrationErrorType errorType=BlackCalibrationHelper::RelativePriceError)
ext::shared_ptr< VanillaOption > option_
const Handle< YieldTermStructure > riskFreeRate_
virtual void calculate() const
Definition: lazyobject.hpp:253
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Plain-vanilla payoff.
Definition: payoffs.hpp:105
purely virtual base class for market observables
Definition: quote.hpp:37
market element returning a stored value
Definition: simplequote.hpp:33
Option exercise classes and payoff function.
QL_REAL Real
real number
Definition: types.hpp:50
Heston-model calibration helper.
Heston stochastic process.
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
Real blackFormula(Option::Type optionType, Real strike, Real forward, Real stdDev, Real discount, Real displacement)
STL namespace.
Payoffs for various options.
simple quote class