diff --git a/src/ModelEquationBlock.cc b/src/ModelEquationBlock.cc
index d4d2d7172ea8e4d7e1e4ce155241f1aaff8acc99..04747614f7e1ff89e3973870b1e8c9801ae46517 100644
--- a/src/ModelEquationBlock.cc
+++ b/src/ModelEquationBlock.cc
@@ -367,20 +367,20 @@ Epilogue::writeEpilogueFile(const string &basename) const
     }
 
   ExprNodeOutputType output_type = ExprNodeOutputType::epilogueFile;
-  output << "function ds = epilogue(params, ds)" << endl
-         << "% function ds = epilogue(params, ds)" << endl
+  output << "function epilogue_dseries__ = epilogue(params, epilogue_dseries__)" << endl
+         << "% function epilogue_dseries__ = epilogue(params, epilogue_dseries__)" << endl
          << "% Epilogue file generated by Dynare preprocessor" << endl << endl
-         << "epilogue_ds_first_date__ = ds.firstdate;" << endl
-         << "epilogue_loop_begin_idx__ = lastdate(ds) - ds.lastobservedperiod;" << endl
-         << "epilogue_loop_end_idx__ = lastdate(ds) - firstdate(ds) + 1;" << endl << endl;
+         << "% loop range variables" << endl
+         << "epilogue_loop_begin_idx__ = lastdate(epilogue_dseries__) - epilogue_dseries__.lastobservedperiod;" << endl
+         << "epilogue_loop_end_idx__ = lastdate(epilogue_dseries__) - firstdate(epilogue_dseries__) + 1;" << endl << endl;
 
   output << "% endogenous" << endl;
   for (auto symb_id : endogs)
-    output << symbol_table.getName(symb_id) << " = ds." << symbol_table.getName(symb_id) << ".data;" << endl;
+    output << symbol_table.getName(symb_id) << " = epilogue_dseries__." << symbol_table.getName(symb_id) << ".data;" << endl;
   output << endl
          << "% exogenous" << endl;
   for (auto symb_id : exogs)
-    output << symbol_table.getName(symb_id) << " = ds." << symbol_table.getName(symb_id) << ".data;" << endl;
+    output << symbol_table.getName(symb_id) << " = epilogue_dseries__." << symbol_table.getName(symb_id) << ".data;" << endl;
   output << endl
          << "for epilogue_it__ = epilogue_loop_begin_idx__:epilogue_loop_end_idx__" << endl;
 
@@ -404,8 +404,8 @@ Epilogue::writeEpilogueFile(const string &basename) const
     }
   output << "end" << endl << endl;
   for (auto symb_id : endogs)
-    output << "ds." << symbol_table.getName(symb_id) << " = dseries(" << symbol_table.getName(symb_id)
-           << ", epilogue_ds_first_date__);" << endl;
+    output << "epilogue_dseries__." << symbol_table.getName(symb_id) << " = dseries(" << symbol_table.getName(symb_id)
+           << ", epilogue_dseries__.firstdate);" << endl;
   output << endl
          << "end" << endl;
   output.close();