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
|
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2004 Neil Firth
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
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
<https://www.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/instruments/multiassetoption.hpp>
#include <ql/stochasticprocess.hpp>
#include <ql/exercise.hpp>
#include <ql/event.hpp>
namespace QuantLib {
MultiAssetOption::MultiAssetOption(
const ext::shared_ptr<Payoff>& payoff,
const ext::shared_ptr<Exercise>& exercise)
: Option(payoff, exercise) {}
bool MultiAssetOption::isExpired() const {
return detail::simple_event(exercise_->lastDate()).hasOccurred();
}
Real MultiAssetOption::delta() const {
calculate();
QL_REQUIRE(delta_ != Null<Real>(), "delta not provided");
return delta_;
}
Real MultiAssetOption::gamma() const {
calculate();
QL_REQUIRE(gamma_ != Null<Real>(), "gamma not provided");
return gamma_;
}
Real MultiAssetOption::theta() const {
calculate();
QL_REQUIRE(theta_ != Null<Real>(), "theta not provided");
return theta_;
}
Real MultiAssetOption::vega() const {
calculate();
QL_REQUIRE(vega_ != Null<Real>(), "vega not provided");
return vega_;
}
Real MultiAssetOption::rho() const {
calculate();
QL_REQUIRE(rho_ != Null<Real>(), "rho not provided");
return rho_;
}
Real MultiAssetOption::dividendRho() const {
calculate();
QL_REQUIRE(dividendRho_ != Null<Real>(), "dividend rho not provided");
return dividendRho_;
}
void MultiAssetOption::setupExpired() const {
NPV_ = delta_ = gamma_ = theta_ =
vega_ = rho_ = dividendRho_ = 0.0;
}
void MultiAssetOption::setupArguments(
PricingEngine::arguments* args) const {
auto* arguments = dynamic_cast<MultiAssetOption::arguments*>(args);
QL_REQUIRE(arguments != nullptr, "wrong argument type");
arguments->payoff = payoff_;
arguments->exercise = exercise_;
}
void MultiAssetOption::fetchResults(const PricingEngine::results* r) const {
Option::fetchResults(r);
const auto* results = dynamic_cast<const Greeks*>(r);
QL_ENSURE(results != nullptr, "no greeks returned from pricing engine");
delta_ = results->delta;
gamma_ = results->gamma;
theta_ = results->theta;
vega_ = results->vega;
rho_ = results->rho;
dividendRho_ = results->dividendRho;
}
}
|