From 812db2eda7b3763fcc66ce0a36e6f0d1ccb5bc71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hnenkamp?= Date: Wed, 28 Feb 2024 14:50:17 +0100 Subject: [PATCH] Update Inflation example Use dates to print --- Examples/Inflation/main.cpp | 77 +++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 29 deletions(-) diff --git a/Examples/Inflation/main.cpp b/Examples/Inflation/main.cpp index ae7bdd14c3..3792f66065 100644 --- a/Examples/Inflation/main.cpp +++ b/Examples/Inflation/main.cpp @@ -33,9 +33,9 @@ struct Coupon { Rate rate; }; -ext::shared_ptr nominalTermStructure(Date studyDate) { +ext::shared_ptr nominalTermStructure(Date studyDate, Rate baseRate) { return ext::shared_ptr( - new FlatForward(studyDate, 0.05, Actual360())); + new FlatForward(studyDate, baseRate, Actual360())); } template @@ -60,7 +60,7 @@ int main() { std::cout << "studyDate:" << studyDate << '\n'; Calendar calendar = UnitedKingdom(); BusinessDayConvention bdc = ModifiedFollowing; - DayCounter dc = Thirty360(Thirty360::BondBasis); + DayCounter dc = Thirty360(Thirty360::European); Frequency frequency = Monthly; // Common to YoY and ZC Actual360 dc360; @@ -71,6 +71,9 @@ int main() { RelinkableHandle relinkableZeroTermStructureHandle; Period availabilityLag(25, Days); ZeroInflationIndex kpiIndex("UKRPI", UKRegion(), false, Monthly, availabilityLag, GBPCurrency(), relinkableZeroTermStructureHandle); + + + boost::shared_ptr pKpiIndex = boost::make_shared(kpiIndex); @@ -103,7 +106,8 @@ int main() { /////////////// // YoY Inflation Swaps - YoYInflationIndex yyIndex(pKpiIndex, false); + bool interpolatedYoy = false; + YoYInflationIndex yyIndex(pKpiIndex, interpolatedYoy); boost::shared_ptr pYoyIndex = boost::make_shared(yyIndex); Rate yyRate = yyIndex.fixing(Date(1, January, 2024)); @@ -136,8 +140,10 @@ int main() { }; - // TODO - ext::shared_ptr yoyNominalTS = nominalTermStructure(studyDate); + //Rate baseYoYRate = 0.03645;//yyIndex.fixing(Date(1, January, 2024)); + Rate baseYoYRate = 0.056014;//yyIndex.fixing(Date(1, January, 2024)); + std::cout << "baseYoYRate: " << baseYoYRate << '\n'; + ext::shared_ptr yoyNominalTS = nominalTermStructure(studyDate, baseYoYRate); auto makeHelperYoY = [&](const Handle& quote, const Date& maturity) { return ext::make_shared( @@ -153,11 +159,6 @@ int main() { auto helpersYoY = makeHelpers(yoySwap, makeHelperYoY); - //Rate baseYoYRate = 0.03645;//yyIndex.fixing(Date(1, January, 2024)); - Rate baseYoYRate = 0.056014;//yyIndex.fixing(Date(1, January, 2024)); - - std::cout << "baseYoYRate: " << baseYoYRate << '\n'; - auto pYoYIS = ext::make_shared>( studyDate, baseDate, baseYoYRate, frequency, true, dc, helpersYoY); @@ -187,9 +188,11 @@ int main() { }; - boost::shared_ptr yieldTermStructure( - new FlatForward(studyDate, 0.05, Actual360())); - Handle nominalTermStructure(yieldTermStructure); + // boost::shared_ptr yieldTermStructure( + // new FlatForward(studyDate, 0.05, Actual360())); + // Handle nts(yieldTermStructure); + Rate zcBaseRate = 0.03756250; + ext::shared_ptr nts = nominalTermStructure(studyDate, zcBaseRate); auto makeHelper = [&](const Handle& quote, const Date& maturity) { return ext::make_shared(quote, @@ -199,8 +202,8 @@ int main() { bdc, dc, pKpiIndex, - CPI::AsIndex, - nominalTermStructure); + CPI::Linear, + Handle(nts)); }; std::vector>> helpers = @@ -230,18 +233,32 @@ int main() { ////////////////////// // Plot Inflation curve + std::vector dates = { + Date(1, January, 2024), Date(1, February, 2024), Date(1, March, 2024), + Date(1, April, 2024), Date(1, May, 2024), Date(1, June, 2024), + Date(1, July, 2024), Date(1, August, 2024), Date(1, September, 2024), + Date(1, October, 2024), Date(1, November, 2024), Date(1, December, 2024), + Date(1, January, 2025), Date(1, February, 2025), Date(1, March, 2025), + Date(1, April, 2025), Date(1, May, 2025), Date(1, June, 2025), + Date(1, July, 2025), Date(1, August, 2025), Date(1, September, 2025), + Date(1, October, 2025), Date(1, November, 2025), Date(1, December, 2025), + Date(1, December, 2026), Date(1, December, 2027), Date(1, December, 2028), + Date(1, February, 2029), Date(1, February, 2030), Date(1, February, 2031), + Date(1, February, 2032), Date(1, February, 2033), Date(1, February, 2034), + Date(1, February, 2036), Date(1, February, 2039), Date(1, February, 2044), + Date(1, February, 2049), Date(1, February, 2054), Date(1, February, 2064), + Date(1, December, 2073), + }; - Date startDay(1, January, 2024); // Must be after or equal base date - Date toDay(1, September, 2033); - Schedule printSchedule = MakeSchedule().from(startDay).to(toDay).withFrequency(Monthly); - - - std::vector