Coverage Report

Created: 2025-08-28 06:30

/src/quantlib/ql/instruments/multiassetoption.cpp
Line
Count
Source (jump to first uncovered line)
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
29
    MultiAssetOption::MultiAssetOption(
30
        const ext::shared_ptr<Payoff>& payoff,
31
        const ext::shared_ptr<Exercise>& exercise)
32
0
    : Option(payoff, exercise) {}
Unexecuted instantiation: QuantLib::MultiAssetOption::MultiAssetOption(boost::shared_ptr<QuantLib::Payoff> const&, boost::shared_ptr<QuantLib::Exercise> const&)
Unexecuted instantiation: QuantLib::MultiAssetOption::MultiAssetOption(boost::shared_ptr<QuantLib::Payoff> const&, boost::shared_ptr<QuantLib::Exercise> const&)
33
34
0
    bool MultiAssetOption::isExpired() const {
35
0
        return detail::simple_event(exercise_->lastDate()).hasOccurred();
36
0
    }
37
38
0
    Real MultiAssetOption::delta() const {
39
0
        calculate();
40
0
        QL_REQUIRE(delta_ != Null<Real>(), "delta not provided");
41
0
        return delta_;
42
0
    }
43
44
0
    Real MultiAssetOption::gamma() const {
45
0
        calculate();
46
0
        QL_REQUIRE(gamma_ != Null<Real>(), "gamma not provided");
47
0
        return gamma_;
48
0
    }
49
50
0
    Real MultiAssetOption::theta() const {
51
0
        calculate();
52
0
        QL_REQUIRE(theta_ != Null<Real>(), "theta not provided");
53
0
        return theta_;
54
0
    }
55
56
0
    Real MultiAssetOption::vega() const {
57
0
        calculate();
58
0
        QL_REQUIRE(vega_ != Null<Real>(), "vega not provided");
59
0
        return vega_;
60
0
    }
61
62
0
    Real MultiAssetOption::rho() const {
63
0
        calculate();
64
0
        QL_REQUIRE(rho_ != Null<Real>(), "rho not provided");
65
0
        return rho_;
66
0
    }
67
68
0
    Real MultiAssetOption::dividendRho() const {
69
0
        calculate();
70
0
        QL_REQUIRE(dividendRho_ != Null<Real>(), "dividend rho not provided");
71
0
        return dividendRho_;
72
0
    }
73
74
0
    void MultiAssetOption::setupExpired() const {
75
0
        NPV_ = delta_ = gamma_ = theta_ =
76
0
            vega_ = rho_ = dividendRho_ =  0.0;
77
0
    }
78
79
    void MultiAssetOption::setupArguments(
80
0
                                       PricingEngine::arguments* args) const {
81
0
        auto* arguments = dynamic_cast<MultiAssetOption::arguments*>(args);
82
0
        QL_REQUIRE(arguments != nullptr, "wrong argument type");
83
84
0
        arguments->payoff = payoff_;
85
0
        arguments->exercise = exercise_;
86
0
    }
87
88
0
    void MultiAssetOption::fetchResults(const PricingEngine::results* r) const {
89
0
        Option::fetchResults(r);
90
0
        const auto* results = dynamic_cast<const Greeks*>(r);
91
0
        QL_ENSURE(results != nullptr, "no greeks returned from pricing engine");
92
0
        delta_          = results->delta;
93
0
        gamma_          = results->gamma;
94
0
        theta_          = results->theta;
95
0
        vega_           = results->vega;
96
0
        rho_            = results->rho;
97
0
        dividendRho_    = results->dividendRho;
98
0
    }
99
100
}