944 {
945
946 BOOST_TEST_MESSAGE("Testing correlation curve");
947
948
949 Handle<QuantExt::CorrelationTermStructure> correlationCurve1 =
950 market->correlationCurve("EUR-CMS-10Y", "EUR-CMS-2Y");
951 Handle<QuantExt::CorrelationTermStructure> correlationCurve2 =
952 market->correlationCurve("USD-CMS-10Y", "USD-CMS-2Y");
953 BOOST_CHECK(*correlationCurve1);
954 BOOST_CHECK(*correlationCurve2);
955
957 Date qlStartDate =
calendar.advance(
calendar.advance(market->asofDate(), 2 * Days), 0 * Months);
958 Date qlEndDate1Y =
calendar.advance(qlStartDate, 1 * Years, ModifiedFollowing);
959 Date qlEndDate2Y =
calendar.advance(qlStartDate, 2 * Years, ModifiedFollowing);
963
964 BOOST_TEST_MESSAGE(startDate);
965 BOOST_TEST_MESSAGE(endDate1Y);
966 BOOST_TEST_MESSAGE(endDate2Y);
967
970
971 Real fairSpread1Y = 0.00752401;
972 Real fairSpread2Y = 0.00755509;
973
974 LegData cms1YLeg(QuantLib::ext::make_shared<CMSSpreadLegData>(
975 "USD-CMS-10Y", "USD-CMS-2Y", 2, true, std::vector<Real>(1, 0.0), vector<string>(),
976 std::vector<Real>(1, fairSpread1Y), vector<string>(), vector<double>(), vector<string>(),
977 vector<double>(), vector<string>(), true),
978 false, "USD", cms1YSchedule, "A360", std::vector<Real>(1, 1));
979 vector<LegData> legs1Y;
980 legs1Y.push_back(cms1YLeg);
981
982 LegData cms2YLeg(QuantLib::ext::make_shared<CMSSpreadLegData>(
983 "USD-CMS-10Y", "USD-CMS-2Y", 2, true, std::vector<Real>(1, 0.0), vector<string>(),
984 std::vector<Real>(1, fairSpread2Y), vector<string>(), vector<double>(), vector<string>(),
985 vector<double>(), vector<string>(), true),
986 false, "USD", cms2YSchedule, "A360", std::vector<Real>(1, 1));
987 vector<LegData> legs2Y;
988 legs2Y.push_back(cms2YLeg);
989
991
994
995 Real expectedNpv1Y = 0.0038614;
996 Real expectedNpv2Y = 0.0105279;
997
998
999 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
1000 engineData->model("CMS") = "LinearTSR";
1001 engineData->engine("CMS") = "LinearTSRPricer";
1002
1003 map<string, string> engineparams1;
1004 engineparams1["MeanReversion"] = "0.0";
1005 engineparams1["Policy"] = "RateBound";
1006 engineparams1["LowerRateBoundLogNormal"] = "0.0001";
1007 engineparams1["UpperRateBoundLogNormal"] = "2";
1008 engineparams1["LowerRateBoundNormal"] = "-2";
1009 engineparams1["UpperRateBoundNormal"] = "2";
1010 engineparams1["VegaRatio"] = "0.01";
1011 engineparams1["PriceThreshold"] = "0.0000001";
1012 engineparams1["BsStdDev"] = "3";
1013 engineData->engineParameters("CMS") = engineparams1;
1014
1015 engineData->model("CMSSpread") = "BrigoMercurio";
1016 engineData->engine("CMSSpread") = "Analytic";
1017 map<string, string> engineparams2;
1018 engineparams2["IntegrationPoints"] = "16";
1019 engineData->engineParameters("CMSSpread") = engineparams2;
1020
1021 engineData->model("Swap") = "DiscountedCashflows";
1022 engineData->engine("Swap") = "DiscountingSwapEngine";
1023
1024 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
1025
1026 cmsSpread1YCap.build(engineFactory);
1027 cmsSpread2YCap.build(engineFactory);
1028
1029 Real npvCash = cmsSpread1YCap.instrument()->NPV();
1030
1031 BOOST_TEST_MESSAGE("NPV Cash 1Y = " << npvCash);
1032 BOOST_CHECK_SMALL(npvCash - expectedNpv1Y, 0.000001);
1033
1034 npvCash = cmsSpread2YCap.instrument()->NPV();
1035
1036 BOOST_TEST_MESSAGE("NPV Cash 2Y = " << npvCash);
1037
1038 BOOST_CHECK_SMALL(npvCash - expectedNpv2Y, 0.000001);
1039}
Serializable object holding generic trade data, reporting dimensions.
Serializable object holding leg data.
Serializable schedule data.
Serializable object holding schedule Rules data.
Serializable Swap, Single and Cross Currency.
std::string to_string(const LocationInfo &l)