@@ -622,10 +622,11 @@ void DividendOptionTest::testFdEuropeanValues() {
622
622
new BlackScholesMertonProcess (Handle<Quote>(spot),
623
623
qTS, rTS, volTS));
624
624
625
- ext::shared_ptr<PricingEngine> engine (
626
- new FDDividendEuropeanEngineMerton73<CrankNicolson>(stochProcess,
627
- timeSteps,
628
- gridPoints));
625
+ ext::shared_ptr<PricingEngine> engine =
626
+ MakeFdBlackScholesVanillaEngine (stochProcess)
627
+ .withTGrid (timeSteps)
628
+ .withXGrid (gridPoints)
629
+ .withCashDividendModel (FdBlackScholesVanillaEngine::Escrowed);
629
630
630
631
ext::shared_ptr<PricingEngine> ref_engine (
631
632
new AnalyticDividendEuropeanEngine (stochProcess));
@@ -674,9 +675,9 @@ void DividendOptionTest::testFdEuropeanValues() {
674
675
675
676
namespace {
676
677
677
- template <class Engine >
678
678
void testFdGreeks (const Date& today,
679
- const ext::shared_ptr<Exercise>& exercise) {
679
+ const ext::shared_ptr<Exercise>& exercise,
680
+ FdBlackScholesVanillaEngine::CashDividendModel model) {
680
681
681
682
std::map<std::string,Real> calculated, expected, tolerance;
682
683
tolerance[" delta" ] = 5.0e-3 ;
@@ -719,8 +720,10 @@ namespace {
719
720
new BlackScholesMertonProcess (Handle<Quote>(spot),
720
721
qTS, rTS, volTS));
721
722
722
- ext::shared_ptr<PricingEngine> engine (
723
- new Engine (stochProcess));
723
+ ext::shared_ptr<PricingEngine> engine =
724
+ MakeFdBlackScholesVanillaEngine (stochProcess)
725
+ .withCashDividendModel (model);
726
+
724
727
DividendVanillaOption option (payoff, exercise,
725
728
dividendDates, dividends);
726
729
option.setPricingEngine (engine);
@@ -809,8 +812,8 @@ void DividendOptionTest::testFdEuropeanGreeks() {
809
812
for (Size i=0 ; i<LENGTH (lengths); i++) {
810
813
Date exDate = today + lengths[i]*Years;
811
814
ext::shared_ptr<Exercise> exercise (new EuropeanExercise (exDate));
812
- testFdGreeks<FDDividendEuropeanEngineMerton73<CrankNicolson> > (today,exercise);
813
- testFdGreeks<FdBlackScholesVanillaEngine> (today,exercise);
815
+ testFdGreeks (today,exercise,FdBlackScholesVanillaEngine::Spot );
816
+ testFdGreeks (today,exercise,FdBlackScholesVanillaEngine::Escrowed );
814
817
}
815
818
}
816
819
@@ -826,19 +829,18 @@ void DividendOptionTest::testFdAmericanGreeks() {
826
829
827
830
for (Size i=0 ; i<LENGTH (lengths); i++) {
828
831
Date exDate = today + lengths[i]*Years;
829
- ext::shared_ptr<Exercise> exercise (
830
- new AmericanExercise (today,exDate));
831
- testFdGreeks<FDDividendAmericanEngineMerton73<CrankNicolson> >(today,exercise);
832
- testFdGreeks<FdBlackScholesVanillaEngine>(today,exercise);
832
+ ext::shared_ptr<Exercise> exercise (new AmericanExercise (today,exDate));
833
+ testFdGreeks (today,exercise,FdBlackScholesVanillaEngine::Spot);
834
+ testFdGreeks (today,exercise,FdBlackScholesVanillaEngine::Escrowed);
833
835
}
834
836
}
835
837
836
838
837
839
namespace {
838
840
839
- template <class Engine >
840
841
void testFdDegenerate (const Date& today,
841
- const ext::shared_ptr<Exercise>& exercise) {
842
+ const ext::shared_ptr<Exercise>& exercise,
843
+ FdBlackScholesVanillaEngine::CashDividendModel model) {
842
844
843
845
DayCounter dc = Actual360 ();
844
846
ext::shared_ptr<SimpleQuote> spot (new SimpleQuote (54.625 ));
@@ -853,8 +855,11 @@ namespace {
853
855
Size timeSteps = 300 ;
854
856
Size gridPoints = 300 ;
855
857
856
- ext::shared_ptr<PricingEngine> engine (
857
- new Engine (process,timeSteps,gridPoints));
858
+ ext::shared_ptr<PricingEngine> engine =
859
+ MakeFdBlackScholesVanillaEngine (process)
860
+ .withTGrid (timeSteps)
861
+ .withXGrid (gridPoints)
862
+ .withCashDividendModel (model);
858
863
859
864
ext::shared_ptr<StrikedTypePayoff> payoff (
860
865
new PlainVanillaPayoff (Option::Call, 55.0 ));
@@ -905,7 +910,8 @@ void DividendOptionTest::testFdEuropeanDegenerate() {
905
910
906
911
ext::shared_ptr<Exercise> exercise (new EuropeanExercise (exDate));
907
912
908
- testFdDegenerate<FDDividendEuropeanEngineMerton73<CrankNicolson> >(today,exercise);
913
+ testFdDegenerate (today,exercise,FdBlackScholesVanillaEngine::Spot);
914
+ testFdDegenerate (today,exercise,FdBlackScholesVanillaEngine::Escrowed);
909
915
}
910
916
911
917
void DividendOptionTest::testFdAmericanDegenerate () {
@@ -921,7 +927,8 @@ void DividendOptionTest::testFdAmericanDegenerate() {
921
927
922
928
ext::shared_ptr<Exercise> exercise (new AmericanExercise (today,exDate));
923
929
924
- testFdDegenerate<FDDividendAmericanEngineMerton73<CrankNicolson> >(today,exercise);
930
+ testFdDegenerate (today,exercise,FdBlackScholesVanillaEngine::Spot);
931
+ testFdDegenerate (today,exercise,FdBlackScholesVanillaEngine::Escrowed);
925
932
}
926
933
927
934
@@ -1001,23 +1008,6 @@ void DividendOptionTest::testEscrowedDividendModel() {
1001
1008
<< " \n difference: " << std::fabs (pdeNPV - analyticNPV)
1002
1009
<< " \n tolerance: " << tol);
1003
1010
}
1004
-
1005
- option.setPricingEngine (
1006
- ext::make_shared<FDDividendEuropeanEngineMerton73<> >(
1007
- process, 50 , 200 ));
1008
-
1009
- const Real deprecatedPDENPV = option.NPV ();
1010
-
1011
- if (std::fabs (deprecatedPDENPV - analyticNPV) > tol) {
1012
- BOOST_FAIL (" Failed to reproduce European option values "
1013
- " with the escrowed dividend model and the "
1014
- " FDDividendEuropeanEngineMerton73 engine"
1015
- << " \n calculated: " << pdeNPV
1016
- << " \n expected: " << analyticNPV
1017
- << " \n difference: "
1018
- << std::fabs (deprecatedPDENPV - analyticNPV)
1019
- << " \n tolerance: " << tol);
1020
- }
1021
1011
}
1022
1012
1023
1013
test_suite* DividendOptionTest::suite () {
0 commit comments