1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2004 Neil Firth 5 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl 6 Copyright (C) 2007 StatPro Italia srl 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/instruments/multiassetoption.hpp> 23 #include <ql/stochasticprocess.hpp> 24 #include <ql/exercise.hpp> 25 #include <ql/event.hpp> 26 27 namespace QuantLib { 28 MultiAssetOption(const ext::shared_ptr<Payoff> & payoff,const ext::shared_ptr<Exercise> & exercise)29 MultiAssetOption::MultiAssetOption( 30 const ext::shared_ptr<Payoff>& payoff, 31 const ext::shared_ptr<Exercise>& exercise) 32 : Option(payoff, exercise) {} 33 isExpired() const34 bool MultiAssetOption::isExpired() const { 35 return detail::simple_event(exercise_->lastDate()).hasOccurred(); 36 } 37 delta() const38 Real MultiAssetOption::delta() const { 39 calculate(); 40 QL_REQUIRE(delta_ != Null<Real>(), "delta not provided"); 41 return delta_; 42 } 43 gamma() const44 Real MultiAssetOption::gamma() const { 45 calculate(); 46 QL_REQUIRE(gamma_ != Null<Real>(), "gamma not provided"); 47 return gamma_; 48 } 49 theta() const50 Real MultiAssetOption::theta() const { 51 calculate(); 52 QL_REQUIRE(theta_ != Null<Real>(), "theta not provided"); 53 return theta_; 54 } 55 vega() const56 Real MultiAssetOption::vega() const { 57 calculate(); 58 QL_REQUIRE(vega_ != Null<Real>(), "vega not provided"); 59 return vega_; 60 } 61 rho() const62 Real MultiAssetOption::rho() const { 63 calculate(); 64 QL_REQUIRE(rho_ != Null<Real>(), "rho not provided"); 65 return rho_; 66 } 67 dividendRho() const68 Real MultiAssetOption::dividendRho() const { 69 calculate(); 70 QL_REQUIRE(dividendRho_ != Null<Real>(), "dividend rho not provided"); 71 return dividendRho_; 72 } 73 setupExpired() const74 void MultiAssetOption::setupExpired() const { 75 NPV_ = delta_ = gamma_ = theta_ = 76 vega_ = rho_ = dividendRho_ = 0.0; 77 } 78 setupArguments(PricingEngine::arguments * args) const79 void MultiAssetOption::setupArguments( 80 PricingEngine::arguments* args) const { 81 MultiAssetOption::arguments* arguments = 82 dynamic_cast<MultiAssetOption::arguments*>(args); 83 QL_REQUIRE(arguments != 0, "wrong argument type"); 84 85 arguments->payoff = payoff_; 86 arguments->exercise = exercise_; 87 } 88 fetchResults(const PricingEngine::results * r) const89 void MultiAssetOption::fetchResults(const PricingEngine::results* r) const { 90 Option::fetchResults(r); 91 const Greeks* results = dynamic_cast<const Greeks*>(r); 92 QL_ENSURE(results != 0, 93 "no greeks returned from pricing engine"); 94 delta_ = results->delta; 95 gamma_ = results->gamma; 96 theta_ = results->theta; 97 vega_ = results->vega; 98 rho_ = results->rho; 99 dividendRho_ = results->dividendRho; 100 } 101 102 } 103