/usr/include/ql/pricingengines/quanto/quantoengine.hpp is in libquantlib0-dev 1.12-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2002, 2003, 2004 Ferdinando Ametrano
Copyright (C) 2007 StatPro Italia srl
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
/*! \file quantoengine.hpp
\brief Quanto option engine
*/
#ifndef quantlib_quanto_engine_hpp
#define quantlib_quanto_engine_hpp
#include <ql/instruments/quantovanillaoption.hpp>
#include <ql/processes/blackscholesprocess.hpp>
#include <ql/termstructures/yield/quantotermstructure.hpp>
#include <ql/instruments/payoffs.hpp>
namespace QuantLib {
//! Quanto engine
/*! \warning for the time being, this engine will only work with
simple Black-Scholes processes (i.e., no Merton.)
\ingroup quantoengines
\test
- the correctness of the returned value is tested by
reproducing results available in literature.
- the correctness of the returned greeks is tested by
reproducing numerical derivatives.
*/
template <class Instr, class Engine>
class QuantoEngine :
public GenericEngine<typename Instr::arguments,
QuantoOptionResults<typename Instr::results> > {
public:
QuantoEngine(
const boost::shared_ptr<GeneralizedBlackScholesProcess>&,
const Handle<YieldTermStructure>& foreignRiskFreeRate,
const Handle<BlackVolTermStructure>& exchangeRateVolatility,
const Handle<Quote>& correlation);
void calculate() const;
protected:
boost::shared_ptr<GeneralizedBlackScholesProcess> process_;
Handle<YieldTermStructure> foreignRiskFreeRate_;
Handle<BlackVolTermStructure> exchangeRateVolatility_;
Handle<Quote> correlation_;
};
// template definitions
template <class Instr, class Engine>
QuantoEngine<Instr,Engine>::QuantoEngine(
const boost::shared_ptr<GeneralizedBlackScholesProcess>& process,
const Handle<YieldTermStructure>& foreignRiskFreeRate,
const Handle<BlackVolTermStructure>& exchangeRateVolatility,
const Handle<Quote>& correlation)
: process_(process), foreignRiskFreeRate_(foreignRiskFreeRate),
exchangeRateVolatility_(exchangeRateVolatility),
correlation_(correlation) {
this->registerWith(process_);
this->registerWith(foreignRiskFreeRate_);
this->registerWith(exchangeRateVolatility_);
this->registerWith(correlation_);
}
template <class Instr, class Engine>
void QuantoEngine<Instr,Engine>::calculate() const {
// ATM exchangeRate level needed here
Real exchangeRateATMlevel = 1.0;
// determine strike from payoff
boost::shared_ptr<StrikedTypePayoff> payoff =
boost::dynamic_pointer_cast<StrikedTypePayoff>(
this->arguments_.payoff);
QL_REQUIRE(payoff, "non-striked payoff given");
Real strike = payoff->strike();
Handle<Quote> spot = process_->stateVariable();
QL_REQUIRE(spot->value() > 0.0, "negative or null underlying");
Handle<YieldTermStructure> riskFreeRate = process_->riskFreeRate();
// dividendTS needs modification
Handle<YieldTermStructure> dividendYield(
boost::shared_ptr<YieldTermStructure>(
new QuantoTermStructure(process_->dividendYield(),
process_->riskFreeRate(),
foreignRiskFreeRate_,
process_->blackVolatility(),
strike,
exchangeRateVolatility_,
exchangeRateATMlevel,
correlation_->value())));
Handle<BlackVolTermStructure> blackVol = process_->blackVolatility();
boost::shared_ptr<GeneralizedBlackScholesProcess> quantoProcess(
new GeneralizedBlackScholesProcess(spot, dividendYield,
riskFreeRate, blackVol));
boost::shared_ptr<Engine> originalEngine(new Engine(quantoProcess));
originalEngine->reset();
typename Instr::arguments* originalArguments =
dynamic_cast<typename Instr::arguments*>(
originalEngine->getArguments());
QL_REQUIRE(originalArguments, "wrong engine type");
*originalArguments = this->arguments_;
originalArguments->validate();
originalEngine->calculate();
const typename Instr::results* originalResults =
dynamic_cast<const typename Instr::results*>(
originalEngine->getResults());
QL_REQUIRE(originalResults, "wrong engine type");
this->results_.value = originalResults->value;
this->results_.delta = originalResults->delta;
this->results_.gamma = originalResults->gamma;
this->results_.theta = originalResults->theta;
if (originalResults->rho != Null<Real>() &&
originalResults->dividendRho != Null<Real>()) {
this->results_.rho = originalResults->rho +
originalResults->dividendRho;
this->results_.dividendRho = originalResults->dividendRho;
} else {
this->results_.rho = this->results_.dividendRho = Null<Real>();
}
Volatility exchangeRateFlatVol =
exchangeRateVolatility_->blackVol(
this->arguments_.exercise->lastDate(),
exchangeRateATMlevel);
if (originalResults->vega != Null<Real>()
&& originalResults->dividendRho != Null<Real>()) {
this->results_.vega = originalResults->vega +
correlation_->value() * exchangeRateFlatVol *
originalResults->dividendRho;
} else {
this->results_.vega = Null<Real>();
}
if (originalResults->dividendRho != Null<Real>()) {
Volatility volatility = process_->blackVolatility()->blackVol(
this->arguments_.exercise->lastDate(),
process_->stateVariable()->value());
this->results_.qvega = correlation_->value() *
process_->blackVolatility()->blackVol(
this->arguments_.exercise->lastDate(),
process_->stateVariable()->value()) *
originalResults->dividendRho;
this->results_.qrho = - originalResults->dividendRho;
this->results_.qlambda = exchangeRateFlatVol *
volatility * originalResults->dividendRho;
} else {
this->results_.qvega = this->results_.qrho =
this->results_.qlambda = Null<Real>();
}
}
}
#endif
|