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
20#include <ql/instruments/margrabeoption.hpp>
21#include <ql/instruments/payoffs.hpp>
22
23namespace QuantLib {
24
25 MargrabeOption::MargrabeOption(Integer Q1,
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
32 Real MargrabeOption::delta1() const {
33 calculate();
34 QL_REQUIRE(delta1_ != Null<Real>(), "delta1 not provided");
35 return delta1_;
36 }
37
38 Real MargrabeOption::delta2() const {
39 calculate();
40 QL_REQUIRE(delta2_ != Null<Real>(), "delta2 not provided");
41 return delta2_;
42 }
43
44 Real MargrabeOption::gamma1() const {
45 calculate();
46 QL_REQUIRE(gamma1_ != Null<Real>(), "gamma1 not provided");
47 return gamma1_;
48 }
49
50 Real MargrabeOption::gamma2() const {
51 calculate();
52 QL_REQUIRE(gamma2_ != Null<Real>(), "gamma2 not provided");
53 return gamma2_;
54 }
55
56 void MargrabeOption::setupArguments(PricingEngine::arguments* args) const {
57 MultiAssetOption::setupArguments(args);
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
66 void MargrabeOption::arguments::validate() const {
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
75 void MargrabeOption::fetchResults(const PricingEngine::results* r) const {
76 MultiAssetOption::fetchResults(r);
77 const auto* results = dynamic_cast<const MargrabeOption::results*>(r);
78 QL_REQUIRE(results != nullptr, "wrong result type");
79 delta1_ = results->delta1;
80 delta2_ = results->delta2;
81 gamma1_ = results->gamma1;
82 gamma2_ = results->gamma2;
83 }
84
85}
86

source code of quantlib/ql/instruments/margrabeoption.cpp