diff --git a/matlab/perfect-foresight-models/perfect_foresight_setup.m b/matlab/perfect-foresight-models/perfect_foresight_setup.m
index 341d70aad67569ff9e5e48b655c538e9a3eadaf5..1b502c4adb8d127b8a3329d6fee6d552849b272e 100644
--- a/matlab/perfect-foresight-models/perfect_foresight_setup.m
+++ b/matlab/perfect-foresight-models/perfect_foresight_setup.m
@@ -51,6 +51,10 @@ if options_.periods == 0
     error('PERFECT_FORESIGHT_SETUP: number of periods for the simulation isn''t specified')
 end
 
+if options_.periods<max([M_.det_shocks.periods])
+    error('PERFECT_FORESIGHT_SETUP: number of periods for the simulation is specified to be smaller than the period of the last shock')
+end
+
 if ~options_.initval_file
     if isempty(options_.datafile)
         oo_=make_ex_(M_,options_,oo_);