From 5dfcdca0283b4d59d9dd82c784407dff46f30fdf Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Thu, 24 Aug 2023 18:03:17 +0200 Subject: [PATCH] Move compound option from experimental to core --- QuantLib.vcxproj | 6 +- QuantLib.vcxproj.filters | 18 ++-- cmake/GenerateHeaders.cmake | 2 + ql/CMakeLists.txt | 6 +- ql/experimental/exoticoptions/Makefile.am | 6 +- ql/experimental/exoticoptions/all.hpp | 2 - .../analyticcompoundoptionengine.hpp | 84 +-------------- .../exoticoptions/compoundoption.hpp | 49 +-------- ql/instruments/Makefile.am | 2 + ql/instruments/all.hpp | 1 + .../compoundoption.cpp | 2 +- ql/instruments/compoundoption.hpp | 66 ++++++++++++ ql/pricingengines/exotic/Makefile.am | 2 + ql/pricingengines/exotic/all.hpp | 1 + .../exotic}/analyticcompoundoptionengine.cpp | 2 +- .../exotic/analyticcompoundoptionengine.hpp | 101 ++++++++++++++++++ test-suite/compoundoption.cpp | 4 +- test-suite/quantlibtestsuite.cpp | 2 +- 18 files changed, 209 insertions(+), 147 deletions(-) rename ql/{experimental/exoticoptions => instruments}/compoundoption.cpp (97%) create mode 100644 ql/instruments/compoundoption.hpp rename ql/{experimental/exoticoptions => pricingengines/exotic}/analyticcompoundoptionengine.cpp (99%) create mode 100644 ql/pricingengines/exotic/analyticcompoundoptionengine.hpp diff --git a/QuantLib.vcxproj b/QuantLib.vcxproj index 2000809f276..b4553130279 100644 --- a/QuantLib.vcxproj +++ b/QuantLib.vcxproj @@ -910,6 +910,7 @@ + @@ -1529,6 +1530,7 @@ + @@ -2018,7 +2020,6 @@ - @@ -2027,7 +2028,6 @@ - @@ -2172,6 +2172,7 @@ + @@ -2586,6 +2587,7 @@ + diff --git a/QuantLib.vcxproj.filters b/QuantLib.vcxproj.filters index 61a5ef7cafa..6922e64616a 100644 --- a/QuantLib.vcxproj.filters +++ b/QuantLib.vcxproj.filters @@ -807,6 +807,9 @@ instruments + + instruments + instruments @@ -2430,6 +2433,9 @@ pricingengines\exotic + + pricingengines\exotic + pricingengines\exotic @@ -4679,6 +4685,9 @@ instruments + + instruments + instruments @@ -5834,6 +5843,9 @@ pricingengines\exotic + + pricingengines\exotic + pricingengines\exotic @@ -6602,12 +6614,6 @@ experimental\barrieroption - - experimental\exoticoptions - - - experimental\exoticoptions - experimental\inflation diff --git a/cmake/GenerateHeaders.cmake b/cmake/GenerateHeaders.cmake index acc2171577f..a41d580b1fd 100644 --- a/cmake/GenerateHeaders.cmake +++ b/cmake/GenerateHeaders.cmake @@ -54,6 +54,8 @@ function(generate_dir_headers source_dir binary_dir) list(FILTER children_hpp EXCLUDE REGEX "margrabeoption.hpp") list(FILTER children_hpp EXCLUDE REGEX "analyticamericanmargrabeengine.hpp") list(FILTER children_hpp EXCLUDE REGEX "analyticeuropeanmargrabeengine.hpp") + list(FILTER children_hpp EXCLUDE REGEX "compoundoption.hpp") + list(FILTER children_hpp EXCLUDE REGEX "analyticcompoundoptionengine.hpp") endif () list(FILTER children_hpp EXCLUDE REGEX "riskybond.hpp") diff --git a/ql/CMakeLists.txt b/ql/CMakeLists.txt index 886edaaeed8..6b15f93021c 100644 --- a/ql/CMakeLists.txt +++ b/ql/CMakeLists.txt @@ -124,7 +124,6 @@ set(QL_SOURCES experimental/credit/riskyassetswapoption.cpp experimental/credit/syntheticcdo.cpp experimental/exoticoptions/analyticcomplexchooserengine.cpp - experimental/exoticoptions/analyticcompoundoptionengine.cpp experimental/exoticoptions/analyticholderextensibleoptionengine.cpp experimental/exoticoptions/analyticpartialtimebarrieroptionengine.cpp experimental/exoticoptions/analyticpdfhestonengine.cpp @@ -133,7 +132,6 @@ set(QL_SOURCES experimental/exoticoptions/analytictwoassetcorrelationengine.cpp experimental/exoticoptions/analyticwriterextensibleoptionengine.cpp experimental/exoticoptions/complexchooseroption.cpp - experimental/exoticoptions/compoundoption.cpp experimental/exoticoptions/continuousarithmeticasianlevyengine.cpp experimental/exoticoptions/continuousarithmeticasianvecerengine.cpp experimental/exoticoptions/everestoption.cpp @@ -280,6 +278,7 @@ set(QL_SOURCES instruments/claim.cpp instruments/cliquetoption.cpp instruments/compositeinstrument.cpp + instruments/compoundoption.cpp instruments/cpicapfloor.cpp instruments/cpiswap.cpp instruments/creditdefaultswap.cpp @@ -699,6 +698,7 @@ set(QL_SOURCES pricingengines/credit/isdacdsengine.cpp pricingengines/credit/midpointcdsengine.cpp pricingengines/exotic/analyticamericanmargrabeengine.cpp + pricingengines/exotic/analyticcompoundoptionengine.cpp pricingengines/exotic/analyticeuropeanmargrabeengine.cpp pricingengines/forward/mcforwardeuropeanbsengine.cpp pricingengines/forward/mcforwardeuropeanhestonengine.cpp @@ -1325,6 +1325,7 @@ set(QL_HEADERS instruments/claim.hpp instruments/cliquetoption.hpp instruments/compositeinstrument.hpp + instruments/compoundoption.hpp instruments/cpicapfloor.hpp instruments/cpiswap.hpp instruments/creditdefaultswap.hpp @@ -1900,6 +1901,7 @@ set(QL_HEADERS pricingengines/credit/isdacdsengine.hpp pricingengines/credit/midpointcdsengine.hpp pricingengines/exotic/analyticamericanmargrabeengine.hpp + pricingengines/exotic/analyticcompoundoptionengine.hpp pricingengines/exotic/analyticeuropeanmargrabeengine.hpp pricingengines/forward/forwardengine.hpp pricingengines/forward/forwardperformanceengine.hpp diff --git a/ql/experimental/exoticoptions/Makefile.am b/ql/experimental/exoticoptions/Makefile.am index a42be6d0098..fd6f78163dd 100644 --- a/ql/experimental/exoticoptions/Makefile.am +++ b/ql/experimental/exoticoptions/Makefile.am @@ -37,7 +37,6 @@ this_include_HEADERS = \ cpp_files = \ analyticcomplexchooserengine.cpp \ - analyticcompoundoptionengine.cpp \ analyticholderextensibleoptionengine.cpp \ analyticpartialtimebarrieroptionengine.cpp \ analyticpdfhestonengine.cpp \ @@ -46,7 +45,6 @@ cpp_files = \ analytictwoassetcorrelationengine.cpp \ analyticwriterextensibleoptionengine.cpp \ complexchooseroption.cpp \ - compoundoption.cpp \ continuousarithmeticasianlevyengine.cpp \ continuousarithmeticasianvecerengine.cpp \ everestoption.cpp \ @@ -92,7 +90,9 @@ all.hpp: Makefile.am for i in $(filter-out all.hpp \ margrabeoption.hpp \ analyticamericanmargrabeengine.hpp \ - analyticeuropeanmargrabeengine.hpp, $(this_include_HEADERS)); do \ + analyticeuropeanmargrabeengine.hpp \ + compoundoption.hpp \ + analyticcompoundoptionengine.hpp, $(this_include_HEADERS)); do \ echo "#include <${subdir}/$$i>" >> ${srcdir}/$@; \ done echo >> ${srcdir}/$@ diff --git a/ql/experimental/exoticoptions/all.hpp b/ql/experimental/exoticoptions/all.hpp index b42058d3318..7cb3eb3cc99 100644 --- a/ql/experimental/exoticoptions/all.hpp +++ b/ql/experimental/exoticoptions/all.hpp @@ -2,7 +2,6 @@ /* Add the files to be included into Makefile.am instead. */ #include -#include #include #include #include @@ -11,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/ql/experimental/exoticoptions/analyticcompoundoptionengine.hpp b/ql/experimental/exoticoptions/analyticcompoundoptionengine.hpp index d9b342c11c8..23d6603bf27 100644 --- a/ql/experimental/exoticoptions/analyticcompoundoptionengine.hpp +++ b/ql/experimental/exoticoptions/analyticcompoundoptionengine.hpp @@ -17,85 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -/*! \file analyticcompoundoptionengine.hpp - \brief Analytic compound option engines -*/ - -#ifndef quantlib_analytic_compound_option_engine_hpp -#define quantlib_analytic_compound_option_engine_hpp - -#include -#include -#include - -namespace QuantLib { - - //! Pricing engine for compound options using analytical formulae - /*! The formulas are taken from "Foreign Exchange Risk", - Uwe Wystup, Risk 2002, where closed form Greeks are available. - (not available in Haug 2007). - Value: Page 84, Greeks: Pages 94-95. - - \test the correctness of the returned value is tested by - reproducing results available in literature. - */ - class AnalyticCompoundOptionEngine : public CompoundOption::engine { - public: - explicit AnalyticCompoundOptionEngine( - ext::shared_ptr process); - void calculate() const override; - - private: - CumulativeNormalDistribution N_; - NormalDistribution n_; - ext::shared_ptr process_; - - // helper methods - Time residualTimeMother() const; - Time residualTimeDaughter() const; - Time residualTimeMotherDaughter() const; - - Date maturityMother() const; - Date maturityDaughter() const; - - Real dPlus() const; - Real dMinus() const; - - Real dPlusTau12(Real S) const; - Real dMinusTau12() const; - - Real strikeDaughter() const; - Real strikeMother() const; - - Real spot() const; - - Real volatilityDaughter() const; - Real volatilityMother() const; - - Real riskFreeRateDaughter() const; - Real dividendRateDaughter() const; - - Real stdDeviationDaughter() const; - Real stdDeviationMother() const; - - Real typeDaughter() const; - Real typeMother() const; - - Real transformX(Real X) const; - Real e(Real X) const; - - DiscountFactor riskFreeDiscountDaughter() const; - DiscountFactor riskFreeDiscountMother() const; - DiscountFactor riskFreeDiscountMotherDaughter() const; - - DiscountFactor dividendDiscountDaughter() const; - DiscountFactor dividendDiscountMother() const; - DiscountFactor dividendDiscountMotherDaughter() const; - - ext::shared_ptr payoffMother() const; - ext::shared_ptr payoffDaughter() const; - }; - -} +// Deprecated in version 1.32 +#pragma message("Warning: this file will disappear in a future release; include instead.") -#endif +#include diff --git a/ql/experimental/exoticoptions/compoundoption.hpp b/ql/experimental/exoticoptions/compoundoption.hpp index a995fdfa21c..e3b27458cb8 100644 --- a/ql/experimental/exoticoptions/compoundoption.hpp +++ b/ql/experimental/exoticoptions/compoundoption.hpp @@ -17,50 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -/*! \file compoundoption.hpp - \brief Compound option on a single asset -*/ - -#ifndef quantlib_compound_option_hpp -#define quantlib_compound_option_hpp - -#include -#include -#include - -namespace QuantLib { - - //! %Compound option on a single asset. - /*! \ingroup instruments */ - class CompoundOption : public OneAssetOption { - public: - class arguments; - class engine; - // Mother is the compound Option. - // Daughter is the option which plays the role of the underlying. - CompoundOption(const ext::shared_ptr& motherPayoff, - const ext::shared_ptr& motherExercise, - ext::shared_ptr daughterPayoff, - ext::shared_ptr daughterExercise); - void setupArguments(PricingEngine::arguments*) const override; - - private: - ext::shared_ptr daughterPayoff_; - ext::shared_ptr daughterExercise_; - }; - - class CompoundOption::arguments : public OneAssetOption::arguments { - public: - ext::shared_ptr daughterPayoff; - ext::shared_ptr daughterExercise; - void validate() const override; - }; - - //! %Compound-option %engine base class - class CompoundOption::engine - : public GenericEngine {}; - -} +// Deprecated in version 1.32 +#pragma message("Warning: this file will disappear in a future release; include instead.") -#endif +#include diff --git a/ql/instruments/Makefile.am b/ql/instruments/Makefile.am index e2d45d44c17..3bbc358463c 100644 --- a/ql/instruments/Makefile.am +++ b/ql/instruments/Makefile.am @@ -20,6 +20,7 @@ this_include_HEADERS = \ claim.hpp \ cliquetoption.hpp \ compositeinstrument.hpp \ + compoundoption.hpp \ cpicapfloor.hpp \ cpiswap.hpp \ creditdefaultswap.hpp \ @@ -86,6 +87,7 @@ cpp_files = \ claim.cpp \ cliquetoption.cpp \ compositeinstrument.cpp \ + compoundoption.cpp \ cpicapfloor.cpp \ cpiswap.cpp \ creditdefaultswap.cpp \ diff --git a/ql/instruments/all.hpp b/ql/instruments/all.hpp index 83567ebc816..22a4c207bbf 100644 --- a/ql/instruments/all.hpp +++ b/ql/instruments/all.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/ql/experimental/exoticoptions/compoundoption.cpp b/ql/instruments/compoundoption.cpp similarity index 97% rename from ql/experimental/exoticoptions/compoundoption.cpp rename to ql/instruments/compoundoption.cpp index df041746c05..530cdd5aef7 100644 --- a/ql/experimental/exoticoptions/compoundoption.cpp +++ b/ql/instruments/compoundoption.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include +#include #include namespace QuantLib { diff --git a/ql/instruments/compoundoption.hpp b/ql/instruments/compoundoption.hpp new file mode 100644 index 00000000000..08f5bdce0b3 --- /dev/null +++ b/ql/instruments/compoundoption.hpp @@ -0,0 +1,66 @@ +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* + Copyright (C) 2009 Dimitri Reiswich + + This file is part of QuantLib, a free-software/open-source library + for financial quantitative analysts and developers - http://quantlib.org/ + + QuantLib is free software: you can redistribute it and/or modify it + under the terms of the QuantLib license. You should have received a + copy of the license along with this program; if not, please email + . The license is also available online at + . + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the license for more details. +*/ + +/*! \file compoundoption.hpp + \brief Compound option on a single asset +*/ + +#ifndef quantlib_compound_option_hpp +#define quantlib_compound_option_hpp + +#include +#include +#include + +namespace QuantLib { + + //! %Compound option (i.e., option on option) on a single asset. + /*! \ingroup instruments */ + class CompoundOption : public OneAssetOption { + public: + class arguments; + class engine; + /*! The mother option is the compound option. + The daughter option is its underlying option. + */ + CompoundOption(const ext::shared_ptr& motherPayoff, + const ext::shared_ptr& motherExercise, + ext::shared_ptr daughterPayoff, + ext::shared_ptr daughterExercise); + void setupArguments(PricingEngine::arguments*) const override; + + private: + ext::shared_ptr daughterPayoff_; + ext::shared_ptr daughterExercise_; + }; + + class CompoundOption::arguments : public OneAssetOption::arguments { + public: + ext::shared_ptr daughterPayoff; + ext::shared_ptr daughterExercise; + void validate() const override; + }; + + //! %Compound-option %engine base class + class CompoundOption::engine : public GenericEngine {}; + +} + +#endif diff --git a/ql/pricingengines/exotic/Makefile.am b/ql/pricingengines/exotic/Makefile.am index b3a4a56389a..faefadf1283 100644 --- a/ql/pricingengines/exotic/Makefile.am +++ b/ql/pricingengines/exotic/Makefile.am @@ -5,10 +5,12 @@ this_includedir=${includedir}/${subdir} this_include_HEADERS = \ all.hpp \ analyticamericanmargrabeengine.hpp \ + analyticcompoundoptionengine.hpp \ analyticeuropeanmargrabeengine.hpp cpp_files = \ analyticamericanmargrabeengine.cpp \ + analyticcompoundoptionengine.cpp \ analyticeuropeanmargrabeengine.cpp if UNITY_BUILD diff --git a/ql/pricingengines/exotic/all.hpp b/ql/pricingengines/exotic/all.hpp index d479fab5b4b..62f004097ae 100644 --- a/ql/pricingengines/exotic/all.hpp +++ b/ql/pricingengines/exotic/all.hpp @@ -2,5 +2,6 @@ /* Add the files to be included into Makefile.am instead. */ #include +#include #include diff --git a/ql/experimental/exoticoptions/analyticcompoundoptionengine.cpp b/ql/pricingengines/exotic/analyticcompoundoptionengine.cpp similarity index 99% rename from ql/experimental/exoticoptions/analyticcompoundoptionengine.cpp rename to ql/pricingengines/exotic/analyticcompoundoptionengine.cpp index 8c3c1b7c5f0..253c2e8d476 100644 --- a/ql/experimental/exoticoptions/analyticcompoundoptionengine.cpp +++ b/ql/pricingengines/exotic/analyticcompoundoptionengine.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include +#include #include #include #include diff --git a/ql/pricingengines/exotic/analyticcompoundoptionengine.hpp b/ql/pricingengines/exotic/analyticcompoundoptionengine.hpp new file mode 100644 index 00000000000..9083b4f9c89 --- /dev/null +++ b/ql/pricingengines/exotic/analyticcompoundoptionengine.hpp @@ -0,0 +1,101 @@ +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* + Copyright (C) 2009 Dimitri Reiswich + + This file is part of QuantLib, a free-software/open-source library + for financial quantitative analysts and developers - http://quantlib.org/ + + QuantLib is free software: you can redistribute it and/or modify it + under the terms of the QuantLib license. You should have received a + copy of the license along with this program; if not, please email + . The license is also available online at + . + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the license for more details. +*/ + +/*! \file analyticcompoundoptionengine.hpp + \brief Analytic compound option engines +*/ + +#ifndef quantlib_analytic_compound_option_engine_hpp +#define quantlib_analytic_compound_option_engine_hpp + +#include +#include +#include + +namespace QuantLib { + + //! Pricing engine for compound options using analytical formulae + /*! The formulas are taken from "Foreign Exchange Risk", + Uwe Wystup, Risk 2002, where closed form Greeks are available. + (not available in Haug 2007). + Value: Page 84, Greeks: Pages 94-95. + + \test the correctness of the returned value is tested by + reproducing results available in literature. + */ + class AnalyticCompoundOptionEngine : public CompoundOption::engine { + public: + explicit AnalyticCompoundOptionEngine( + ext::shared_ptr process); + void calculate() const override; + + private: + CumulativeNormalDistribution N_; + NormalDistribution n_; + ext::shared_ptr process_; + + // helper methods + Time residualTimeMother() const; + Time residualTimeDaughter() const; + Time residualTimeMotherDaughter() const; + + Date maturityMother() const; + Date maturityDaughter() const; + + Real dPlus() const; + Real dMinus() const; + + Real dPlusTau12(Real S) const; + Real dMinusTau12() const; + + Real strikeDaughter() const; + Real strikeMother() const; + + Real spot() const; + + Real volatilityDaughter() const; + Real volatilityMother() const; + + Real riskFreeRateDaughter() const; + Real dividendRateDaughter() const; + + Real stdDeviationDaughter() const; + Real stdDeviationMother() const; + + Real typeDaughter() const; + Real typeMother() const; + + Real transformX(Real X) const; + Real e(Real X) const; + + DiscountFactor riskFreeDiscountDaughter() const; + DiscountFactor riskFreeDiscountMother() const; + DiscountFactor riskFreeDiscountMotherDaughter() const; + + DiscountFactor dividendDiscountDaughter() const; + DiscountFactor dividendDiscountMother() const; + DiscountFactor dividendDiscountMotherDaughter() const; + + ext::shared_ptr payoffMother() const; + ext::shared_ptr payoffDaughter() const; + }; + +} + +#endif diff --git a/test-suite/compoundoption.cpp b/test-suite/compoundoption.cpp index a3a06c0779f..98afeb6ce40 100644 --- a/test-suite/compoundoption.cpp +++ b/test-suite/compoundoption.cpp @@ -19,8 +19,8 @@ #include "compoundoption.hpp" #include "utilities.hpp" -#include -#include +#include +#include #include #include #include diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 8925de2f48f..23986b0719e 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -378,6 +378,7 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(CliquetOptionTest::suite()); test->add(CmsTest::suite()); test->add(CmsNormalTest::suite()); + test->add(CompoundOptionTest::suite()); test->add(ConvertibleBondTest::suite()); test->add(CovarianceTest::suite()); test->add(CPISwapTest::suite()); @@ -498,7 +499,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(CmsSpreadTest::suite()); test->add(CommodityUnitOfMeasureTest::suite()); test->add(CompiledBoostVersionTest::suite()); - test->add(CompoundOptionTest::suite()); test->add(CreditRiskPlusTest::suite()); test->add(DoubleBarrierOptionTest::suite(speed)); test->add(DoubleBinaryOptionTest::suite());