@@ -211,16 +211,29 @@ QuantLib::ext::shared_ptr<EngineFactory> Analytic::Impl::engineFactory() {
211211}
212212
213213void Analytic::setUp () {
214+
214215 if (!portfolio_) {
215216 portfolio_ = QuantLib::ext::make_shared<Portfolio>();
216217 if (inputs ()->portfolio ()) {
217218 for (const auto & [tradeId, trade] : inputs ()->portfolio ()->trades ())
218219 portfolio_->add (trade);
219220 }
220221 }
222+
221223 buildConfigurations ();
222- if (inputs ()->enrichIndexFixings () && portfolio_)
223- enrichIndexFixings (portfolio_);
224+
225+ /* if we do not load all fixings, and the portfolio is not built at this point,
226+ we built it against a dummy market using the portfolio analyser, so that
227+ we can ask the portfolio for its required fixings in the market data loader
228+ and also enrich the index fixings here (if desired). */
229+ if (!portfolio_->empty () && !inputs ()->allFixings ()) {
230+ if (!portfolio_->isBuilt ()) {
231+ PortfolioAnalyser (portfolio_, inputs_->pricingEngine (), inputs_->baseCurrency (),
232+ configurations ().curveConfig , inputs_->refDataManager (), inputs_->iborFallbackConfig ());
233+ }
234+ if (inputs ()->enrichIndexFixings ())
235+ enrichIndexFixings (portfolio_);
236+ }
224237}
225238
226239void Analytic::buildMarket (const QuantLib::ext::shared_ptr<ore::data::InMemoryLoader>& loader,
@@ -344,13 +357,6 @@ void Analytic::enrichIndexFixings(const QuantLib::ext::shared_ptr<ore::data::Por
344357
345358 startTimer (" enrichIndexFixings()" );
346359 QL_REQUIRE (portfolio, " portfolio cannot be empty" );
347-
348- // ! if the portfolio is not built, create a portfolio analyser which builds the portfolio under a dummy market
349- if (!portfolio->isBuilt ()) {
350- PortfolioAnalyser (
351- portfolio_, inputs_->pricingEngine (), inputs_->baseCurrency (), configurations ().curveConfig ,
352- inputs_->refDataManager (), inputs_->iborFallbackConfig ());
353- }
354360
355361 auto isFallbackFixingDateWithinLimit = [this ](Date originalFixingDate, Date fallbackFixingDate) {
356362 if (fallbackFixingDate > originalFixingDate) {
0 commit comments