[go: up one dir, main page]

1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2014 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 "twoassetcorrelationoption.hpp"
21#include "utilities.hpp"
22#include <ql/experimental/exoticoptions/twoassetcorrelationoption.hpp>
23#include <ql/experimental/exoticoptions/analytictwoassetcorrelationengine.hpp>
24#include <ql/quotes/simplequote.hpp>
25#include <ql/utilities/dataformatters.hpp>
26#include <ql/time/daycounters/actual360.hpp>
27
28using namespace QuantLib;
29using namespace boost::unit_test_framework;
30
31void TwoAssetCorrelationOptionTest::testAnalyticEngine() {
32 BOOST_TEST_MESSAGE(
33 "Testing analytic engine for two-asset correlation option...");
34
35 Date today = Settings::instance().evaluationDate();
36 DayCounter dc = Actual360();
37
38 Option::Type type = Option::Call;
39 Real strike1 = 50.0;
40 Real strike2 = 70.0;
41 Date exDate = today + 180;
42
43 ext::shared_ptr<Exercise> exercise =
44 ext::make_shared<EuropeanExercise>(args&: exDate);
45
46 TwoAssetCorrelationOption option(type, strike1, strike2, exercise);
47
48 Handle<Quote> underlying1(ext::make_shared<SimpleQuote>(args: 52.0));
49 Handle<Quote> underlying2(ext::make_shared<SimpleQuote>(args: 65.0));
50 Handle<YieldTermStructure> dividendTS1(flatRate(today, forward: 0.0, dc));
51 Handle<YieldTermStructure> dividendTS2(flatRate(today, forward: 0.0, dc));
52 Handle<YieldTermStructure> riskFreeTS(flatRate(today, forward: 0.1, dc));
53 Handle<BlackVolTermStructure> blackVolTS1(flatVol(today, volatility: 0.2, dc));
54 Handle<BlackVolTermStructure> blackVolTS2(flatVol(today, volatility: 0.3, dc));
55 Handle<Quote> correlation(ext::make_shared<SimpleQuote>(args: 0.75));
56
57 ext::shared_ptr<BlackScholesMertonProcess> process1 =
58 ext::make_shared<BlackScholesMertonProcess>(args&: underlying1,
59 args&: dividendTS1,
60 args&: riskFreeTS,
61 args&: blackVolTS1);
62
63 ext::shared_ptr<BlackScholesMertonProcess> process2 =
64 ext::make_shared<BlackScholesMertonProcess>(args&: underlying2,
65 args&: dividendTS2,
66 args&: riskFreeTS,
67 args&: blackVolTS2);
68
69 option.setPricingEngine(
70 ext::make_shared<AnalyticTwoAssetCorrelationEngine>(args&: process1,
71 args&: process2,
72 args&: correlation));
73
74 Real calculated = option.NPV();
75 Real expected = 4.7073;
76 Real error = std::fabs(x: calculated-expected);
77 Real tolerance = 1e-4;
78 if (error > tolerance)
79 BOOST_ERROR("Failed to reproduce holder-extensible option value"
80 << "\n expected: " << expected
81 << "\n calculated: " << calculated
82 << "\n error: " << error);
83}
84
85test_suite* TwoAssetCorrelationOptionTest::suite() {
86 auto* suite = BOOST_TEST_SUITE("Two-asset correlation option tests");
87
88 suite->add(QUANTLIB_TEST_CASE(
89 &TwoAssetCorrelationOptionTest::testAnalyticEngine));
90
91 return suite;
92}
93

source code of quantlib/test-suite/twoassetcorrelationoption.cpp