From bd11eaa4a220dcf7dd26c2cce380ca3e2a9ade1e Mon Sep 17 00:00:00 2001 From: Danijel Zivoi Date: Thu, 10 Sep 2026 16:38:55 +0200 Subject: [PATCH] Fix the parameter key of setCreditMigrationAnalytic (#361) The setter wrote its flag to kvaTheirCvaRiskWeight instead of creditMigration, so credit migration was never enabled from the API and the bool left under the risk weight key made the XVA parameter loading throw a bad_any_cast. Add an InputParameters test for the setter. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01Q5n2ExoAFe9qtbybzMxnsQ --- OREAnalytics/orea/app/inputparameters.hpp | 2 +- OREAnalytics/test/CMakeLists.txt | 1 + OREAnalytics/test/inputparameters.cpp | 51 +++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 OREAnalytics/test/inputparameters.cpp diff --git a/OREAnalytics/orea/app/inputparameters.hpp b/OREAnalytics/orea/app/inputparameters.hpp index 66c3a8b090..24e3451121 100644 --- a/OREAnalytics/orea/app/inputparameters.hpp +++ b/OREAnalytics/orea/app/inputparameters.hpp @@ -731,7 +731,7 @@ class InputParameters : public QuantLib::ext::enable_shared_from_this& grid) { parameters_.set("xva", "creditMigrationDistributionGrid", grid); } void setCreditSimulationParameters(const QuantLib::ext::shared_ptr& c) { parameters_.set("xva", "creditMigrationConfig", c); } void setCreditSimulationParametersFromBuffer(const std::string& xml ) { parameters_.set("xva", "creditMigrationConfig", xml); } diff --git a/OREAnalytics/test/CMakeLists.txt b/OREAnalytics/test/CMakeLists.txt index 354d3cf848..c886b6a889 100644 --- a/OREAnalytics/test/CMakeLists.txt +++ b/OREAnalytics/test/CMakeLists.txt @@ -4,6 +4,7 @@ set(OREAnalytics-Test_SRC aggregationscenariodata.cpp amcbermudanswaption.cpp cube.cpp historicalscenariogenerator.cpp +inputparameters.cpp nettedexpsoure.cpp observationmode.cpp parsensitivityanalysis.cpp diff --git a/OREAnalytics/test/inputparameters.cpp b/OREAnalytics/test/inputparameters.cpp new file mode 100644 index 0000000000..a1c27c63ac --- /dev/null +++ b/OREAnalytics/test/inputparameters.cpp @@ -0,0 +1,51 @@ +/* + Copyright (C) 2026 Quaternion Risk Management Ltd + All rights reserved. + + This file is part of ORE, a free-software/open-source library + for transparent pricing and risk analysis - http://opensourcerisk.org + + ORE is free software: you can redistribute it and/or modify it + under the terms of the Modified BSD License. You should have received a + copy of the license along with this program. + The license is also available online at + + This program is distributed on the basis that it will form a useful + contribution to risk analytics and model standardisation, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. +*/ + +#include +#include + +#include +#include + +using namespace ore::analytics; +using namespace ore::data; +using namespace boost::unit_test_framework; + +BOOST_FIXTURE_TEST_SUITE(OREAnalyticsTestSuite, ore::test::OreaTopLevelFixture) + +BOOST_AUTO_TEST_SUITE(InputParametersTest) + +BOOST_AUTO_TEST_CASE(testCreditMigrationAnalyticSetter) { + BOOST_TEST_MESSAGE("Testing that setCreditMigrationAnalytic sets the creditMigration flag and nothing else"); + + auto inputs = QuantLib::ext::make_shared(); + inputs->setCreditMigrationAnalytic(true); + + bool creditMigration = false; + BOOST_CHECK(inputs->loadParameter(creditMigration, "xva", "creditMigration", false, parseBool)); + BOOST_CHECK(creditMigration); + + QuantLib::Real riskWeight = 0.05; + BOOST_CHECK_NO_THROW( + inputs->loadParameter(riskWeight, "xva", "kvaTheirCvaRiskWeight", false, parseReal)); + BOOST_CHECK_EQUAL(riskWeight, 0.05); +} + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END()