@@ -56,8 +56,12 @@ SensitivityRecord ParSensitivityCubeStream::next() {
5656 tradeIdx_++;
5757 if (tradeIdx_ != cube_->zeroCubes ()[zeroCubeIdx_]->tradeIdx ().end ()) {
5858 // update trade currency
59- if (!tradeCurrency_.empty ())
60- currentTradeCurrency_ = tradeCurrency_.find (tradeIdx_->first )->second ;
59+ if (!tradeCurrency_.empty ()) {
60+ auto it = tradeCurrency_.find (tradeIdx_->first );
61+ QL_REQUIRE (it != tradeCurrency_.end (),
62+ " cannot find currency for trade " << tradeIdx_->first << " in tradeCurrency map" );
63+ currentTradeCurrency_ = it->second ;
64+ }
6165 // update par deltas
6266 DLOG (" Retrieving par deltas for trade " << tradeIdx_->first );
6367 currentDeltas_ = cube_->parDeltas (zeroCubeIdx_, tradeIdx_->second );
@@ -107,8 +111,12 @@ void ParSensitivityCubeStream::init() {
107111 // If we have trade IDs in the underlying cube
108112 if (!cube_->zeroCubes ()[zeroCubeIdx_]->tradeIdx ().empty ()) {
109113 tradeIdx_ = cube_->zeroCubes ()[zeroCubeIdx_]->tradeIdx ().begin ();
110- if (!tradeCurrency_.empty ())
111- currentTradeCurrency_ = tradeCurrency_.find (tradeIdx_->first )->second ;
114+ if (!tradeCurrency_.empty ()) {
115+ auto it = tradeCurrency_.find (tradeIdx_->first );
116+ QL_REQUIRE (it != tradeCurrency_.end (),
117+ " cannot find currency for trade " << tradeIdx_->first << " in tradeCurrency map" );
118+ currentTradeCurrency_ = it->second ;
119+ }
112120 DLOG (" Retrieving par deltas for trade " << tradeIdx_->first );
113121 currentDeltas_ = cube_->parDeltas (zeroCubeIdx_, tradeIdx_->second );
114122 itCurrent_ = currentDeltas_.begin ();
0 commit comments