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
|
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2005 Klaus Spanderen
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.
*/
#include <ql/pricingengines/vanilla/batesengine.hpp>
#include <ql/instruments/payoffs.hpp>
namespace QuantLib {
BatesEngine::BatesEngine(const boost::shared_ptr<BatesModel> & model,
Size integrationOrder)
: AnalyticHestonEngine(model, integrationOrder) { }
BatesEngine::BatesEngine(const boost::shared_ptr<BatesModel>& model,
Real relTolerance, Size maxEvaluations)
: AnalyticHestonEngine(model, relTolerance, maxEvaluations) { }
std::complex<Real> BatesEngine::addOnTerm(
Real phi, Time t, Size j) const {
boost::shared_ptr<BatesModel> batesModel =
boost::dynamic_pointer_cast<BatesModel>(*model_);
const Real nu_ = batesModel->nu();
const Real delta2_ = 0.5*batesModel->delta()*batesModel->delta();
const Real lambda_ = batesModel->lambda();
const Real i = (j == 1)? 1.0 : 0.0;
const std::complex<Real> g(i, phi);
//it can throw: to be fixed
return t*lambda_*(std::exp(nu_*g + delta2_*g*g) - 1.0
-g*(std::exp(nu_+delta2_) - 1.0));
}
BatesDetJumpEngine::BatesDetJumpEngine(
const boost::shared_ptr<BatesDetJumpModel>& model,
Size integrationOrder)
: BatesEngine(model, integrationOrder) { }
BatesDetJumpEngine::BatesDetJumpEngine(
const boost::shared_ptr<BatesDetJumpModel>& model,
Real relTolerance, Size maxEvaluations)
: BatesEngine(model, relTolerance, maxEvaluations) { }
std::complex<Real> BatesDetJumpEngine::addOnTerm(
Real phi, Time t, Size j) const {
const std::complex<Real> l =
BatesEngine::addOnTerm(phi, t, j);
boost::shared_ptr<BatesDetJumpModel> batesDetJumpModel =
boost::dynamic_pointer_cast<BatesDetJumpModel>(*model_);
const Real lambda = batesDetJumpModel->lambda();
const Real kappaLambda = batesDetJumpModel->kappaLambda();
const Real thetaLambda = batesDetJumpModel->thetaLambda();
return (kappaLambda*t - 1.0 + std::exp(-kappaLambda*t))
* thetaLambda*l/(kappaLambda*t*lambda)
+ (1.0 - std::exp(-kappaLambda*t))*l/(kappaLambda*t);
}
BatesDoubleExpEngine::BatesDoubleExpEngine(
const boost::shared_ptr<BatesDoubleExpModel> & model,
Size integrationOrder)
: AnalyticHestonEngine(model, integrationOrder) { }
BatesDoubleExpEngine::BatesDoubleExpEngine(
const boost::shared_ptr<BatesDoubleExpModel>& model,
Real relTolerance, Size maxEvaluations)
: AnalyticHestonEngine(model, relTolerance, maxEvaluations) { }
std::complex<Real> BatesDoubleExpEngine::addOnTerm(
Real phi, Time t, Size j) const {
boost::shared_ptr<BatesDoubleExpModel> batesDoubleExpModel =
boost::dynamic_pointer_cast<BatesDoubleExpModel>(*model_);
const Real p_ = batesDoubleExpModel->p();
const Real q_ = 1.0-p_;
const Real nuDown_= batesDoubleExpModel->nuDown();
const Real nuUp_ = batesDoubleExpModel->nuUp();
const Real lambda_= batesDoubleExpModel->lambda();
const Real i = (j == 1)? 1.0 : 0.0;
const std::complex<Real> g(i, phi);
return t*lambda_*(p_/(1.0-g*nuUp_) + q_/(1.0+g*nuDown_) - 1.0
- g*(p_/(1-nuUp_) + q_/(1+nuDown_)-1));
}
BatesDoubleExpDetJumpEngine::BatesDoubleExpDetJumpEngine(
const boost::shared_ptr<BatesDoubleExpDetJumpModel> & model,
Size integrationOrder)
: BatesDoubleExpEngine(model, integrationOrder) { }
BatesDoubleExpDetJumpEngine::BatesDoubleExpDetJumpEngine(
const boost::shared_ptr<BatesDoubleExpDetJumpModel>& model,
Real relTolerance, Size maxEvaluations)
: BatesDoubleExpEngine(model, relTolerance, maxEvaluations) { }
std::complex<Real> BatesDoubleExpDetJumpEngine::addOnTerm(
Real phi, Time t, Size j) const {
const std::complex<Real> l =
BatesDoubleExpEngine::addOnTerm(phi, t, j);
boost::shared_ptr<BatesDoubleExpDetJumpModel> doubleExpDetJumpModel
= boost::dynamic_pointer_cast<BatesDoubleExpDetJumpModel>(*model_);
const Real lambda = doubleExpDetJumpModel->lambda();
const Real kappaLambda = doubleExpDetJumpModel->kappaLambda();
const Real thetaLambda = doubleExpDetJumpModel->thetaLambda();
return (kappaLambda*t - 1.0 + std::exp(-kappaLambda*t))
* thetaLambda*l/(kappaLambda*t*lambda)
+ (1.0 - std::exp(-kappaLambda*t))*l/(kappaLambda*t);
}
}
|