QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
margrabeoption.cpp
Go to the documentation of this file.
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 <http://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
22
23namespace QuantLib {
24
26 Integer Q2,
27 const ext::shared_ptr<Exercise>& exercise)
28 : MultiAssetOption(ext::shared_ptr<Payoff>(new NullPayoff), exercise),
29 Q1_(Q1),
30 Q2_(Q2) {}
31
33 calculate();
34 QL_REQUIRE(delta1_ != Null<Real>(), "delta1 not provided");
35 return delta1_;
36 }
37
39 calculate();
40 QL_REQUIRE(delta2_ != Null<Real>(), "delta2 not provided");
41 return delta2_;
42 }
43
45 calculate();
46 QL_REQUIRE(gamma1_ != Null<Real>(), "gamma1 not provided");
47 return gamma1_;
48 }
49
51 calculate();
52 QL_REQUIRE(gamma2_ != Null<Real>(), "gamma2 not provided");
53 return gamma2_;
54 }
55
58
59 auto* moreArgs = dynamic_cast<MargrabeOption::arguments*>(args);
60 QL_REQUIRE(moreArgs != nullptr, "wrong argument type");
61
62 moreArgs->Q1 = Q1_;
63 moreArgs->Q2 = Q2_;
64 }
65
67 MultiAssetOption::arguments::validate();
68
69 QL_REQUIRE(Q1 != Null<Integer>(), "unspecified quantity for asset 1");
70 QL_REQUIRE(Q2 != Null<Integer>(), "unspecified quantity for asset 2");
71 QL_REQUIRE(Q1 > 0, "quantity of asset 1 must be positive");
72 QL_REQUIRE(Q2 > 0, "quantity of asset 2 must be positive");
73 }
74
77 const auto* results = dynamic_cast<const MargrabeOption::results*>(r);
78 QL_REQUIRE(results != nullptr, "wrong result type");
83 }
84
85}
void calculate() const override
Definition: instrument.hpp:129
Extra arguments for Margrabe option.
Extra results for Margrabe option.
void setupArguments(PricingEngine::arguments *) const override
MargrabeOption(Integer Q1, Integer Q2, const ext::shared_ptr< Exercise > &)
void fetchResults(const PricingEngine::results *) const override
Base class for options on multiple assets.
void setupArguments(PricingEngine::arguments *) const override
void fetchResults(const PricingEngine::results *) const override
template class providing a null value for a given type.
Definition: null.hpp:76
Dummy payoff class.
Definition: payoffs.hpp:36
Abstract base class for option payoffs.
Definition: payoff.hpp:36
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Margrabe option on two assets.
Definition: any.hpp:35
Payoffs for various options.
ext::shared_ptr< YieldTermStructure > r