Skip to content

InputParameters::setCreditMigrationAnalytic writes to the kvaTheirCvaRiskWeight key #361

Description

@dazivo

Summary

InputParameters::setCreditMigrationAnalytic(bool) stores its argument under the wrong parameter key (OREAnalytics/orea/app/inputparameters.hpp:734 as of 3b62ba248):

// credit simulation
void setCreditMigrationAnalytic(bool b) { parameters_.set("xva", "kvaTheirCvaRiskWeight", b); }

XvaAnalytic reads the flag from ("xva", "creditMigration") (orea/app/analytics/xvaanalytic.cpp:267), so the setter never enables the credit migration analytic. Worse, it plants a bool under ("xva", "kvaTheirCvaRiskWeight"), and when the KVA parameters are loaded (xvaanalytic.cpp:264) loadParameter<Real> first fails the typed any_cast<Real> (caught) and then falls back to loadParameterString(), whose any_cast<string> of the stored bool is not caught. Any call to the setter, true or false, therefore makes the XVA analytic's parameter loading throw a bad_any_cast with no hint of the cause.

Reachability: the setter is part of the Python API (ORE-SWIG/OREAnalytics-SWIG/SWIG/orea_app.i:413). Examples/ORE-API/oreApi.py:277 would call it, but that block is currently commented out ("set credit simulation parameters once added to swig"), so no shipped example hits it; anyone driving InputParameters from Python does. Introduced with the feature/1.114.1_to_master merge (9199569c5), first released in v1.8.16.0. Noticed while working on #359, which is otherwise unrelated.

Reproduction

auto inputs = QuantLib::ext::make_shared<InputParameters>();
inputs->setCreditMigrationAnalytic(true);

bool creditMigration = false;
inputs->loadParameter<bool>(creditMigration, "xva", "creditMigration", false, parseBool);   // returns false, flag stays false

QuantLib::Real riskWeight = 0.05;
inputs->loadParameter<QuantLib::Real>(riskWeight, "xva", "kvaTheirCvaRiskWeight", false, parseReal);  // throws bad_any_cast

Fix

Write to the creditMigration key. One-line PR with the above as a unit test to follow.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions