2020#include < orea/scenario/scenarioutilities.hpp>
2121#include < orea/scenario/simplescenario.hpp>
2222#include < orea/scenario/simplescenariofactory.hpp>
23+ #include < orea/engine/parsensitivityanalysis.hpp>
2324
2425using namespace QuantLib ;
2526
@@ -39,13 +40,22 @@ ZeroToParScenarioGenerator::ZeroToParScenarioGenerator(
3940
4041 // build a base and base par scenario off the zero base scenario, and update with the calculated par rates
4142 // base scenario must be the minimum of the simulation (hsg baseScenario) and sensitivity configuration
43+
4244 baseScenario_ = QuantLib::ext::make_shared<SimpleScenario>(bs->asof (), bs->label (), bs->getNumeraire ());
4345 baseParScenario_ = QuantLib::ext::make_shared<SimpleScenario>(bs->asof (), bs->label (), bs->getNumeraire ());
4446 baseParScenario_->setPar (true );
45- for (const auto & kv : baseValues) {
46- if (bs->has (kv.first )) {
47- baseScenario_->add (kv.first , bs->get (kv.first ));
48- baseParScenario_->add (kv.first , kv.second );
47+ for (auto & k : bs->keys ()) {
48+ auto bv = bs->get (k);
49+ if (ParSensitivityAnalysis::isParType (k.keytype )) {
50+ auto it = baseValues.find (k);
51+ if (it != baseValues.end ()) {
52+ // found in par rates
53+ baseScenario_->add (k, bv);
54+ baseParScenario_->add (k, it->second );
55+ }
56+ } else {
57+ baseScenario_->add (k, bv);
58+ baseParScenario_->add (k, bv);
4959 }
5060 }
5161}
@@ -54,10 +64,10 @@ QuantLib::ext::shared_ptr<Scenario> ZeroToParScenarioGenerator::next(const Date&
5464 auto zeroScenario = HistoricalScenarioGenerator::next (d);
5565
5666 // create a par scenario to hold the par shifts
57- QuantLib::ext::shared_ptr<Scenario> parScenario = QuantLib::ext::make_shared<SimpleScenario>(
58- baseScenario_-> asof (), baseScenario_-> label (), baseScenario_->getNumeraire ());
67+ QuantLib::ext::shared_ptr<Scenario> parScenario =
68+ addDifferenceToScenario (baseScenario_, zeroScenario, d, baseScenario_->getNumeraire (), true );
5969 parScenario->setPar (true );
60- parScenario->label (zeroScenario-> label ( ));
70+ parScenario->label (to_string (d ));
6171
6272 // get the par shifts and update the par scenario
6373 auto parShifts = shiftConverter_->parShifts (zeroScenario);
0 commit comments