Skip to content

Commit

Permalink
Move compound option from experimental to core
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Aug 24, 2023
1 parent bd88e67 commit 5dfcdca
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 147 deletions.
6 changes: 4 additions & 2 deletions QuantLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@
<ClInclude Include="ql\instruments\claim.hpp" />
<ClInclude Include="ql\instruments\cliquetoption.hpp" />
<ClInclude Include="ql\instruments\compositeinstrument.hpp" />
<ClInclude Include="ql\instruments\compoundoption.hpp" />
<ClInclude Include="ql\instruments\cpicapfloor.hpp" />
<ClInclude Include="ql\instruments\cpiswap.hpp" />
<ClInclude Include="ql\instruments\creditdefaultswap.hpp" />
Expand Down Expand Up @@ -1529,6 +1530,7 @@
<ClInclude Include="ql\pricingengines\credit\midpointcdsengine.hpp" />
<ClInclude Include="ql\pricingengines\exotic\all.hpp" />
<ClInclude Include="ql\pricingengines\exotic\analyticamericanmargrabeengine.hpp" />
<ClInclude Include="ql\pricingengines\exotic\analyticcompoundoptionengine.hpp" />
<ClInclude Include="ql\pricingengines\exotic\analyticeuropeanmargrabeengine.hpp" />
<ClInclude Include="ql\pricingengines\forward\all.hpp" />
<ClInclude Include="ql\pricingengines\forward\forwardengine.hpp" />
Expand Down Expand Up @@ -2018,7 +2020,6 @@
<ClCompile Include="ql\experimental\credit\riskyassetswapoption.cpp" />
<ClCompile Include="ql\experimental\credit\syntheticcdo.cpp" />
<ClCompile Include="ql\experimental\exoticoptions\analyticcomplexchooserengine.cpp" />
<ClCompile Include="ql\experimental\exoticoptions\analyticcompoundoptionengine.cpp" />
<ClCompile Include="ql\experimental\exoticoptions\analyticholderextensibleoptionengine.cpp" />
<ClCompile Include="ql\experimental\exoticoptions\analyticpartialtimebarrieroptionengine.cpp" />
<ClCompile Include="ql\experimental\exoticoptions\analyticpdfhestonengine.cpp" />
Expand All @@ -2027,7 +2028,6 @@
<ClCompile Include="ql\experimental\exoticoptions\analytictwoassetcorrelationengine.cpp" />
<ClCompile Include="ql\experimental\exoticoptions\analyticwriterextensibleoptionengine.cpp" />
<ClCompile Include="ql\experimental\exoticoptions\complexchooseroption.cpp" />
<ClCompile Include="ql\experimental\exoticoptions\compoundoption.cpp" />
<ClCompile Include="ql\experimental\exoticoptions\continuousarithmeticasianlevyengine.cpp" />
<ClCompile Include="ql\experimental\exoticoptions\continuousarithmeticasianvecerengine.cpp" />
<ClCompile Include="ql\experimental\exoticoptions\everestoption.cpp" />
Expand Down Expand Up @@ -2172,6 +2172,7 @@
<ClCompile Include="ql\instruments\claim.cpp" />
<ClCompile Include="ql\instruments\cliquetoption.cpp" />
<ClCompile Include="ql\instruments\compositeinstrument.cpp" />
<ClCompile Include="ql\instruments\compoundoption.cpp" />
<ClCompile Include="ql\instruments\cpicapfloor.cpp" />
<ClCompile Include="ql\instruments\cpiswap.cpp" />
<ClCompile Include="ql\instruments\creditdefaultswap.cpp" />
Expand Down Expand Up @@ -2586,6 +2587,7 @@
<ClCompile Include="ql\pricingengines\credit\isdacdsengine.cpp" />
<ClCompile Include="ql\pricingengines\credit\midpointcdsengine.cpp" />
<ClCompile Include="ql\pricingengines\exotic\analyticamericanmargrabeengine.cpp" />
<ClCompile Include="ql\pricingengines\exotic\analyticcompoundoptionengine.cpp" />
<ClCompile Include="ql\pricingengines\exotic\analyticeuropeanmargrabeengine.cpp" />
<ClCompile Include="ql\pricingengines\forward\mcforwardeuropeanbsengine.cpp" />
<ClCompile Include="ql\pricingengines\forward\mcforwardeuropeanhestonengine.cpp" />
Expand Down
18 changes: 12 additions & 6 deletions QuantLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,9 @@
<ClInclude Include="ql\instruments\compositeinstrument.hpp">
<Filter>instruments</Filter>
</ClInclude>
<ClInclude Include="ql\instruments\compoundoption.hpp">
<Filter>instruments</Filter>
</ClInclude>
<ClInclude Include="ql\instruments\creditdefaultswap.hpp">
<Filter>instruments</Filter>
</ClInclude>
Expand Down Expand Up @@ -2430,6 +2433,9 @@
<ClInclude Include="ql\pricingengines\exotic\analyticamericanmargrabeengine.hpp">
<Filter>pricingengines\exotic</Filter>
</ClInclude>
<ClInclude Include="ql\pricingengines\exotic\analyticcompoundoptionengine.hpp">
<Filter>pricingengines\exotic</Filter>
</ClInclude>
<ClInclude Include="ql\pricingengines\exotic\analyticeuropeanmargrabeengine.hpp">
<Filter>pricingengines\exotic</Filter>
</ClInclude>
Expand Down Expand Up @@ -4679,6 +4685,9 @@
<ClCompile Include="ql\instruments\compositeinstrument.cpp">
<Filter>instruments</Filter>
</ClCompile>
<ClCompile Include="ql\instruments\compoundoption.cpp">
<Filter>instruments</Filter>
</ClCompile>
<ClCompile Include="ql\instruments\creditdefaultswap.cpp">
<Filter>instruments</Filter>
</ClCompile>
Expand Down Expand Up @@ -5834,6 +5843,9 @@
<ClCompile Include="ql\pricingengines\exotic\analyticamericanmargrabeengine.cpp">
<Filter>pricingengines\exotic</Filter>
</ClCompile>
<ClCompile Include="ql\pricingengines\exotic\analyticcompoundoptionengine.cpp">
<Filter>pricingengines\exotic</Filter>
</ClCompile>
<ClCompile Include="ql\pricingengines\exotic\analyticeuropeanmargrabeengine.cpp">
<Filter>pricingengines\exotic</Filter>
</ClCompile>
Expand Down Expand Up @@ -6602,12 +6614,6 @@
<ClCompile Include="ql\experimental\barrieroption\vannavolgabarrierengine.cpp">
<Filter>experimental\barrieroption</Filter>
</ClCompile>
<ClCompile Include="ql\experimental\exoticoptions\analyticcompoundoptionengine.cpp">
<Filter>experimental\exoticoptions</Filter>
</ClCompile>
<ClCompile Include="ql\experimental\exoticoptions\compoundoption.cpp">
<Filter>experimental\exoticoptions</Filter>
</ClCompile>
<ClCompile Include="ql\experimental\inflation\yoycapfloortermpricesurface.cpp">
<Filter>experimental\inflation</Filter>
</ClCompile>
Expand Down
2 changes: 2 additions & 0 deletions cmake/GenerateHeaders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions ql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ql/experimental/exoticoptions/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ this_include_HEADERS = \

cpp_files = \
analyticcomplexchooserengine.cpp \
analyticcompoundoptionengine.cpp \
analyticholderextensibleoptionengine.cpp \
analyticpartialtimebarrieroptionengine.cpp \
analyticpdfhestonengine.cpp \
Expand All @@ -46,7 +45,6 @@ cpp_files = \
analytictwoassetcorrelationengine.cpp \
analyticwriterextensibleoptionengine.cpp \
complexchooseroption.cpp \
compoundoption.cpp \
continuousarithmeticasianlevyengine.cpp \
continuousarithmeticasianvecerengine.cpp \
everestoption.cpp \
Expand Down Expand Up @@ -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}/$@
Expand Down
2 changes: 0 additions & 2 deletions ql/experimental/exoticoptions/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* Add the files to be included into Makefile.am instead. */

#include <ql/experimental/exoticoptions/analyticcomplexchooserengine.hpp>
#include <ql/experimental/exoticoptions/analyticcompoundoptionengine.hpp>
#include <ql/experimental/exoticoptions/analyticholderextensibleoptionengine.hpp>
#include <ql/experimental/exoticoptions/analyticpartialtimebarrieroptionengine.hpp>
#include <ql/experimental/exoticoptions/analyticpdfhestonengine.hpp>
Expand All @@ -11,7 +10,6 @@
#include <ql/experimental/exoticoptions/analytictwoassetcorrelationengine.hpp>
#include <ql/experimental/exoticoptions/analyticwriterextensibleoptionengine.hpp>
#include <ql/experimental/exoticoptions/complexchooseroption.hpp>
#include <ql/experimental/exoticoptions/compoundoption.hpp>
#include <ql/experimental/exoticoptions/continuousarithmeticasianlevyengine.hpp>
#include <ql/experimental/exoticoptions/continuousarithmeticasianvecerengine.hpp>
#include <ql/experimental/exoticoptions/everestoption.hpp>
Expand Down
84 changes: 3 additions & 81 deletions ql/experimental/exoticoptions/analyticcompoundoptionengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ql/experimental/exoticoptions/compoundoption.hpp>
#include <ql/processes/blackscholesprocess.hpp>
#include <ql/math/distributions/bivariatenormaldistribution.hpp>

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<GeneralizedBlackScholesProcess> process);
void calculate() const override;

private:
CumulativeNormalDistribution N_;
NormalDistribution n_;
ext::shared_ptr<GeneralizedBlackScholesProcess> 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<PlainVanillaPayoff> payoffMother() const;
ext::shared_ptr<PlainVanillaPayoff> payoffDaughter() const;
};

}
// Deprecated in version 1.32
#pragma message("Warning: this file will disappear in a future release; include <ql/pricingengines/exotic/analyticcompoundoptionengine.hpp> instead.")

#endif
#include <ql/pricingengines/exotic/analyticcompoundoptionengine.hpp>
49 changes: 3 additions & 46 deletions ql/experimental/exoticoptions/compoundoption.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ql/instruments/oneassetoption.hpp>
#include <ql/instruments/payoffs.hpp>
#include <ql/exercise.hpp>

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<StrikedTypePayoff>& motherPayoff,
const ext::shared_ptr<Exercise>& motherExercise,
ext::shared_ptr<StrikedTypePayoff> daughterPayoff,
ext::shared_ptr<Exercise> daughterExercise);
void setupArguments(PricingEngine::arguments*) const override;

private:
ext::shared_ptr<StrikedTypePayoff> daughterPayoff_;
ext::shared_ptr<Exercise> daughterExercise_;
};

class CompoundOption::arguments : public OneAssetOption::arguments {
public:
ext::shared_ptr<StrikedTypePayoff> daughterPayoff;
ext::shared_ptr<Exercise> daughterExercise;
void validate() const override;
};

//! %Compound-option %engine base class
class CompoundOption::engine
: public GenericEngine<CompoundOption::arguments,
CompoundOption::results> {};

}
// Deprecated in version 1.32
#pragma message("Warning: this file will disappear in a future release; include <ql/instruments/compoundoption.hpp> instead.")

#endif
#include <ql/instruments/compoundoption.hpp>
2 changes: 2 additions & 0 deletions ql/instruments/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ this_include_HEADERS = \
claim.hpp \
cliquetoption.hpp \
compositeinstrument.hpp \
compoundoption.hpp \
cpicapfloor.hpp \
cpiswap.hpp \
creditdefaultswap.hpp \
Expand Down Expand Up @@ -86,6 +87,7 @@ cpp_files = \
claim.cpp \
cliquetoption.cpp \
compositeinstrument.cpp \
compoundoption.cpp \
cpicapfloor.cpp \
cpiswap.cpp \
creditdefaultswap.cpp \
Expand Down
1 change: 1 addition & 0 deletions ql/instruments/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <ql/instruments/claim.hpp>
#include <ql/instruments/cliquetoption.hpp>
#include <ql/instruments/compositeinstrument.hpp>
#include <ql/instruments/compoundoption.hpp>
#include <ql/instruments/cpicapfloor.hpp>
#include <ql/instruments/cpiswap.hpp>
#include <ql/instruments/creditdefaultswap.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
FOR A PARTICULAR PURPOSE. See the license for more details.
*/

#include <ql/experimental/exoticoptions/compoundoption.hpp>
#include <ql/instruments/compoundoption.hpp>
#include <utility>

namespace QuantLib {
Expand Down
Loading

0 comments on commit 5dfcdca

Please sign in to comment.