/* -*- 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 . The license is also available online at . 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 #include #include #include namespace QuantLib { MultiAssetOption::MultiAssetOption( const boost::shared_ptr& process, const boost::shared_ptr& payoff, const boost::shared_ptr& exercise, const boost::shared_ptr& engine) : Option(payoff, exercise, engine), stochasticProcess_(process) { registerWith(stochasticProcess_); } bool MultiAssetOption::isExpired() const { return exercise_->lastDate() < Settings::instance().evaluationDate(); } Real MultiAssetOption::delta() const { calculate(); QL_REQUIRE(delta_ != Null(), "delta not provided"); return delta_; } Real MultiAssetOption::gamma() const { calculate(); QL_REQUIRE(gamma_ != Null(), "gamma not provided"); return gamma_; } Real MultiAssetOption::theta() const { calculate(); QL_REQUIRE(theta_ != Null(), "theta not provided"); return theta_; } Real MultiAssetOption::vega() const { calculate(); QL_REQUIRE(vega_ != Null(), "vega not provided"); return vega_; } Real MultiAssetOption::rho() const { calculate(); QL_REQUIRE(rho_ != Null(), "rho not provided"); return rho_; } Real MultiAssetOption::dividendRho() const { calculate(); QL_REQUIRE(dividendRho_ != Null(), "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 { MultiAssetOption::arguments* arguments = dynamic_cast(args); QL_REQUIRE(arguments != 0, "wrong argument type"); arguments->payoff = payoff_; arguments->stochasticProcess = stochasticProcess_; arguments->exercise = exercise_; Size n = exercise_->dates().size(); arguments->stoppingTimes.clear(); arguments->stoppingTimes.reserve(n); for (Size i=0; istoppingTimes.push_back( stochasticProcess_->time(exercise_->date(i))); } } void MultiAssetOption::fetchResults(const PricingEngine::results* r) const { Option::fetchResults(r); const Greeks* results = dynamic_cast(r); QL_ENSURE(results != 0, "no greeks returned from pricing engine"); delta_ = results->delta; gamma_ = results->gamma; theta_ = results->theta; vega_ = results->vega; rho_ = results->rho; dividendRho_ = results->dividendRho; } void MultiAssetOption::arguments::validate() const { Option::arguments::validate(); QL_REQUIRE(stochasticProcess, "no process given"); } }