Coverage Report

Created: 2026-06-23 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/margrabeoption.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2010 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
/*! \file margrabeoption.hpp
21
    \brief Margrabe option on two assets
22
*/
23
24
#ifndef quantlib_margrabe_option_hpp
25
#define quantlib_margrabe_option_hpp
26
27
#include <ql/instruments/multiassetoption.hpp>
28
29
namespace QuantLib {
30
31
    //! Margrabe option on two assets
32
    /*! This option gives the holder the right to exchange Q2 stocks
33
        of the second asset for Q1 stocks of the first at expiration.
34
35
        \ingroup instruments
36
    */
37
    class MargrabeOption : public MultiAssetOption {
38
      public:
39
        class arguments;
40
        class results;
41
        class engine;
42
        MargrabeOption(Integer Q1,
43
                       Integer Q2,
44
                       const ext::shared_ptr<Exercise>&);
45
        void setupArguments(PricingEngine::arguments*) const override;
46
        Real delta1() const;
47
        Real delta2() const;
48
        Real gamma1() const;
49
        Real gamma2() const;
50
        void fetchResults(const PricingEngine::results*) const override;
51
52
      protected:
53
        Integer Q1_;
54
        Integer Q2_;
55
        mutable Real delta1_, delta2_, gamma1_, gamma2_;
56
    };
57
58
    //! Extra %arguments for Margrabe option
59
    class MargrabeOption::arguments : public MultiAssetOption::arguments {
60
      public:
61
0
        arguments() = default;
62
        void validate() const override;
63
        Integer Q1 = Null<Integer>();
64
        Integer Q2 = Null<Integer>();
65
    };
66
67
    //! Extra %results for Margrabe option
68
    class MargrabeOption::results : public MultiAssetOption::results {
69
      public:
70
0
        results() = default;
71
        Real delta1 = Null<Real>();
72
        Real delta2 = Null<Real>();
73
        Real gamma1 = Null<Real>();
74
        Real gamma2 = Null<Real>();
75
0
        void reset() override {
76
0
            MultiAssetOption::results::reset();
77
0
            delta1 = Null<Real>();
78
0
            delta2 = Null<Real>();
79
0
            gamma1 = Null<Real>();
80
0
            gamma2 = Null<Real>();
81
0
        }
82
    };
83
84
    //! %Margrabe option %engine base class
85
    class MargrabeOption::engine : public GenericEngine<MargrabeOption::arguments,
86
                                                        MargrabeOption::results> {};
87
}
88
89
90
#endif