-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfrbuseview.nw
8134 lines (6583 loc) · 243 KB
/
frbuseview.nw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass{book}
\usepackage{noweb}
\usepackage{hyperref}
\hypersetup{final=true}
\usepackage[toc,page]{appendix}
\usepackage{multicol}
\usepackage{framed}
\usepackage{xcolor}
\let\oldquote=\quote
\let\endoldquote=\endquote
\colorlet{shadecolor}{orange!15}
\renewenvironment{quote}{\begin{shaded*}\begin{oldquote}}{\end{oldquote}\end{shaded*}}
\title{Reverse Engineering the Eview Code in the FRB/US Model}
\author{Gary Young}
\begin{document}
\pagestyle{noweb}
\frontmatter
\maketitle
\tableofcontents
\mainmatter
\chapter{Introduction}
\chapter{FRB/US Package}
\section{example1 program}
<<frbus example1>>=
' Program for simple simulation under VAR expectations
'
' See FRB/US Simulation Basics document for information about
' this program
' *************************************************************
' Initial filename and parameter settings
' *************************************************************
' Subroutines
include ../subs/master_library
' Workfile
%wfstart = "1975q1"
%wfend = "2030q4"
%mainpage = "main"
wfcreate(wf=aaa,page={%mainpage}) q {%wfstart} {%wfend}
' FRB/US model name and location
%varmod = "stdver"
%varpath = "../mods/"
' Input datbase
%dbin = "../data/longbase"
' Simulation range
%simstart = "2020q1"
%simend = "2025q4"
' ****************************************************************
' Retrieve data, model equations and coefficients, set
' policy options, and compute tracking residuals
' ****************************************************************
' Load equations and coefficients
ld_frbus_eqs(modelname=%varmod,modelpath=%varpath)
ld_frbus_cfs(modelname=%varmod,modelpath=%varpath)
' Load data
dbopen %dbin as longbase
fetch(d=longbase) *
' Set monetary policy rule
smpl @all
call set_mp("dmpintay")
' Turn off zero bound and policy thresholds; hold policymaker's
' perceived equilibrium real interest rate constant
smpl @all
dmptrsh = 0
rffmin = -9999
drstar = 0
' Set fiscal policy
smpl @all
call set_fp("dfpsrp")
' Set _aerr variables to zero
smpl @all
{%varmod}.makegroup(a,n) endog @endog
call groupnew("endog","_aerr")
call group2zero("endog_aerr")
' Standard solution options
{%varmod}.solveopt(o=b,g=12,z=1e-12)
' Assign baseline tracking add factors
%suftrk = "_0"
smpl %simstart %simend
{%varmod}.addassign @all
{%varmod}.addinit(v=n) @all
{%varmod}.scenario(n,a={%suftrk}) "track"
{%varmod}.solve
scalar mm = @max(@abs(xgap{%suftrk}-xgap))
if mm > .0001 then
statusline dynamic tracking simulation failed for {%varmod}
stop
endif
' *************************************************************
' Simulate a shock to monetary policy rule
' *************************************************************
%sufsim = "_1"
{%varmod}.scenario(n,a={%sufsim}) "sim"
smpl %simstart %simstart
rffintay_aerr = rffintay_aerr + 1
smpl %simstart %simend
{%varmod}.solve
'***********************************************************
' Make a graph
'***********************************************************
smpl %simstart %simend
series zero = 0
series d_rff = rff{%sufsim} - rff
series d_rg10 = rg10{%sufsim} - rg10
series d_lur = lur{%sufsim} - lur
series d_pic4 = pic4{%sufsim} - pic4
graph fig1a.line zero d_rff
fig1a.addtext(t,just(c),font("arial",12)) Federal Funds Rate
fig1a.legend -display
graph fig1b.line zero d_rg10
fig1b.addtext(t,just(c),font("arial",12)) 10-Year Treasury Yield
fig1b.legend -display
graph fig1c.line zero d_lur
fig1c.addtext(t,just(c),font("arial",12)) Unemployment Rate
fig1c.legend -display
graph fig1d.line zero d_pic4
fig1d.addtext(t,just(c),font("arial",12)) Inflation Rate (4-Quarter)
fig1d.legend -display
graph fig1.merge fig1a fig1b fig1c fig1d
fig1.addtext(t,just(c),font("Arial",16)) Macroeconomic Effects of Funds Rate Perturbation\r(VAR Expectations)
fig1.align(2,1,1.25)
show fig1
@
\section{example2 program}
<<frbus example2>>=
' Program for simple simulation with MCE expectations
'
' The switch variables %mcvars_wp and %mcvars_all control whether
' the assumption of MC expectations extends beyond the financial
' sector
' See the Simulation Basics document for information about
' this program
' *************************************************************
' Initial filename and parameter settings
' *************************************************************
' Subroutines
include ../subs/master_library
include ../subs/mce_solve_library
' Workfile
%wfstart = "1975q1"
%wfend = "2100q4"
%mainpage = "main"
wfcreate(wf=aaa,page={%mainpage}) q {%wfstart} {%wfend}
' FRB/US model names and locations
%varmod = "stdver"
%varpath = "../mods/"
%mcemod = "pfver"
%mcepath = "../mods/"
' Input datbase
%dbin = "../data/longbase"
' Simulation range
%simstart = "2020q1"
%simend = "2069q4"
' ****************************************************************
' Retrieve data, model equations and coefficients, set
' policy options, and compute tracking residuals
' ****************************************************************
' Specify MC expectations variables
%mcvars_wp = "yes"
%mcvars_all = "no"
' MCE asset pricing
%zvars = "zdivgr zgap05 zgap10 zgap30 zrff5 zrff10 zrff30 zpi10 zpi10f zpic30 zpib5 zpic58 "
' MCE elsewhere
if %mcvars_wp = "yes" and %mcvars_all = "no" then
%zvars = %zvars + "zpicxfe zpieci "
endif
if %mcvars_all = "yes" then
%zvars = %zvars + "zpicxfe zpieci "
%zvars = %zvars + "zecd zeco zeh zgapc2 zlhp zpi5 zvpd zvpi zvps zxbd zxbi zxbs zyh zyhp zyht zynid "
endif
' Load equations and coefficients
call mce_load_frbus("mce_vars=%zvars,mod_b=%varmod,path_b=%varpath,mod_f=%mcemod,path_f=%mcepath")
' Load data
dbopen %dbin as longdata
fetch(d=longdata) *
' Data for extra variables associated with MC expectations
smpl @all
call make_frbus_mcevars(%zvars)
' Set monetary policy
smpl @all
call set_mp("dmpintay")
' Turn off zero bound and policy thresholds; hold policymaker's
' perceived equilibrium real interest rate constant
smpl @all
dmptrsh = 0
rffmin = -9999
drstar = 0
' Set fiscal policy
smpl @all
call set_fp("dfpsrp")
' Set _aerr variables to zero
smpl @all
{%varmod}.makegroup(a,n) endog @endog
call groupnew("endog","_aerr")
call group2zero("endog_aerr")
' Standard solution options
{%varmod}.solveopt(o=b,g=12,z=1e-12)
{%mcemod}.solveopt(o=b,g=12,z=1e-12)
' Assign baseline tracking add factors
%suftrk = "_0"
smpl %simstart %simend
{%varmod}.addassign @all
{%varmod}.addinit(v=n) @all
{%varmod}.scenario(n,a={%suftrk}) "track"
{%varmod}.solve
scalar mm = @max(@abs(xgap{%suftrk}-xgap))
if mm > .0001 then
statusline dynamic tracking simulation failed for {%varmod}
stop
endif
{%mcemod}.addassign @all
{%mcemod}.addinit(v=n) @all
' *************************************************************
' Simulate a monetary policy shock
' *************************************************************
%sufsim = "_1"
{%varmod}.scenario(n,a={%sufsim}) "sim"
{%mcemod}.scenario(n,a={%sufsim}) "sim"
smpl %simstart %simstart
rffintay_a = rffintay_a + 1
%modstr = "mod_b=%varmod,mod_f=%mcemod,mce_vars=%zvars"
%algstr = "meth=qnewton"
%simstr = "type=single"
smpl %simstart %simend
call mce_run(%modstr,%algstr,%simstr)
'***********************************************************
' Make a graph
'***********************************************************
smpl %simstart %simstart + 39
series zero = 0
series d_rff = rff{%sufsim} - rff
series d_rg10 = rg10{%sufsim} - rg10
series d_lur = lur{%sufsim} - lur
series d_pic4 = pic4{%sufsim} - pic4
graph fig1a.line zero d_rff
fig1a.addtext(t,just(c),font("arial",12)) Federal Funds Rate
fig1a.legend -display
graph fig1b.line zero d_rg10
fig1b.addtext(t,just(c),font("arial",12)) 10-Year Treasury Yield
fig1b.legend -display
graph fig1c.line zero d_lur
fig1c.addtext(t,just(c),font("arial",12)) Unemployment Rate
fig1c.legend -display
graph fig1d.line zero d_pic4
fig1d.addtext(t,just(c),font("arial",12)) Inflation Rate (4-Quarter)
fig1d.legend -display
graph fig1.merge fig1a fig1b fig1c fig1d
%title = " Macroeconomic Effects of Funds Rate Shock\r"
if %mcvars_wp = "no" and %mcvars_all = "no" then
%title = %title + "(MC Expectations in Asset Pricing)"
endif
if %mcvars_wp = "yes" and %mcvars_all = "no" then
%title = %title + "(MC Expectations in Asset Pricing and Price-Wage Setting)"
endif
if %mcvars_all = "yes" then
%title = %title + "(MC Expectations in All Sectors)"
endif
fig1.addtext(t,just(c),font("Arial",16)) {%title}
fig1.align(2,1,1.25)
show fig1
@
\section{example3 program}
<<frbus example3>>=
' Program for simulation under VAR expectations that illustrates how
' to set the monetary policy options that impose the zero lower bound
' on the funds rate and delay the liftoff of the funds rate from the
' ZLB until either the unemployment rate falls below a threshold or
' inflation rises above a threshold.
'
' See FRB/US Simulation Basics document for general information about
' this program.
' Additional notes:
' 1. The scenario involves a set of negative aggregate demand
' shocks and a positive risk premium shock that start in 2003q3,
' when the baseline (historical) funds rate is about one percent.
' The shocks are equal to the equation errors actually observed
' in the four quarters starting in 2008q4.
' 2. To impose the ZLB set %zb = "yes" (rather than "no")
' 3. To impose the policy liftfoff threshold conditions set both
' %zb = "yes" and %threshold = "yes". For illustrative purposes
' and reflecting the baseline conditions in 2003 and the years
' that immediately follow, the inflation threshold is set to 3.0
' and the unemployment threshold is set to 7.0, subject to the
' the adjustments described next.
' 4. Because the threshold conditions only make sense once the ZLB is
' binding, unemployment is above its threshold level (lurtrsh),
' and inflation is below its threshold (pitrsh), which is not the
' case in the initial simulation quarters, the program turns on the
' threshold code (using dmptrsh) in the 5th simulation quarter,
' at which point these conditions hold. In addition, for the threshold
' code to work properly, the endogenous switch variable dmptr must be
' zero in the quarter prior to the quarter in which the threshold code is
' turned on. This is accomplished by setting the baseline data on dmptr
' to zero and by setting the unemployment and inflation thresholds
' (lurtrsh, pitrsh) to values in the first four simulation quarters that
' would not flip the dmptr switch to one.
' 4. Choose one of the five available policy rules by setting
' %policy to one of rffintay, rfftay, rfftlr, rffalt, or rffgen.
' 5. If neither the ZLB or thresholds are imposed, the monetary policy
' equations have baseline-tracking adds and the simulation is
' a standard deviations-from-baseline exercise.
' 6. If either the ZLB or thresholds are imposed, the add factors on
' monetary policy equations are set to zero after the tracking adds
' are computed so that the ZLB and threshold conditions are based on the
' actual simulated outcomes for the funds rate and inflation and unemployment,
' not their deviations from baseline.
' *************************************************************
' Initial filename and parameter settings
' *************************************************************
' Subroutines
include ../subs/master_library
' Workfile
%wfstart = "1975q1"
%wfend = "2012q4"
%mainpage = "main"
wfcreate(wf=aaa,page={%mainpage}) q {%wfstart} {%wfend}
' FRB/US model name and location
%varmod = "stdver"
%varpath = "../mods/"
' Input datbase
%dbin = "../data/longbase"
' Simulation range
%simstart = "2003q3"
%simend = "2008q2"
' Policy
%zb = "yes"
%threshold = "yes"
%policy = "rfftay"
' ****************************************************************
' Retrieve data, model equations and coefficients, set
' policy options, and compute tracking residuals
' ****************************************************************
' Load equations and coefficients
ld_frbus_eqs(modelname=%varmod,modelpath=%varpath)
ld_frbus_cfs(modelname=%varmod,modelpath=%varpath)
' Load data
dbopen %dbin as longbase
fetch(d=longbase) *
' Set monetary policy rule
smpl @all
%policydmp = @replace(%policy,"rff","dmp")
call set_mp(%policydmp)
' Set ZLB
if %zb = "yes" then
rffmin = .125
else
rffmin = -9999
endif
' Set threshold variables
if %threshold = "yes" then
if %zb = "no" then
@uiprompt("When policy thresholds are imposed, the zero bound must also be imposed")
stop
endif
smpl @all
call dateshift(%simstart,%quarter4,3)
' thresholds (dmptrsh and dmptr) not active in first 4 qtrs
smpl %simstart - 1 %quarter4
dmptrsh = 0
lurtrsh = -9999
pitrsh = 9999
dmptr = 0
' thresholds (dmptrsh and dmptr) active starting in qtr 5
smpl %quarter4 + 1 %simend
dmptrsh = 1
lurtrsh = 7.0
pitrsh = 3.0
smpl @all
else
smpl @all
dmptrsh = 0
endif
smpl @all
drstar = 0
' Set fiscal policy
smpl @all
call set_fp("dfpsrp")
' Set _aerr variables to zero
smpl @all
{%varmod}.makegroup(a,n) endog @endog
call groupnew("endog","_aerr")
call group2zero("endog_aerr")
' Standard solution options
{%varmod}.solveopt(o=b,g=12,z=1e-12)
' Assign baseline tracking add factors
%suftrk = "_0"
smpl %simstart 2012q4
{%varmod}.addassign @all
{%varmod}.addinit(v=n) @all
{%varmod}.scenario(n,a={%suftrk}) "track"
{%varmod}.solve
scalar mm = @max(@abs(xgap{%suftrk}-xgap))
if mm > .0001 then
statusline dynamic tracking simulation failed for {%varmod}
stop
endif
' Set monetary policy add factors to zero when ZLB or threshold are
' imposed
if %zb = "yes" then
smpl @all
{%policy}_a = 0
rffrule_a = 0
rffe_a = 0
if %threshold = "yes" then
dmptpi_a = 0
dmptlur_a = 0
dmptmax_a = 0
dmptr_a = 0
endif
endif
' *************************************************************
' Simulation
' *************************************************************
%sufsim = "_1"
{%varmod}.scenario(n,a={%sufsim}) "sim"
' shock values are taken from equation residuals for 2008q4-2009q3
eco_a.fill(o=%simstart) -.006, -.006, -.011, -.001
ecd_a.fill(o=%simstart) -.091, -.018, -.021, .029
eh_a.fill(o=%simstart) -.076, -.078, -.040, .073
epd_a.fill(o=%simstart) -.096, -.062, .014, .032
eps_a.fill(o=%simstart) -.018, -.046, -.036, -.017
rbbbp_a.fill(o=%simstart) 2.70, 0.38, -0.89, -1.35
smpl %simstart %simend
{%varmod}.solve
'***********************************************************
' Make a graph
'***********************************************************
smpl %simstart %simend
graph fig1a.line rff rff{%sufsim}
fig1a.addtext(t,just(c),font("arial",12)) Federal Funds Rate
fig1a.legend -display
graph fig1b.line rg10 rg10{%sufsim}
fig1b.addtext(t,just(c),font("arial",12)) 10-Year Treasury Yield
fig1b.legend -display
graph fig1c.line lur lur{%sufsim}
fig1c.addtext(t,just(c),font("arial",12)) Unemployment Rate
fig1c.legend -display
graph fig1d.line pic4 pic4{%sufsim}
fig1d.addtext(t,just(c),font("arial",12)) Inflation Rate (4-Quarter)
fig1d.legend -display
%title = "Macroeconomic Effects of Negative AD Shock\r(VAR Expectations"
%title = %title + "; Policy = " + %policy + ")"
if %zb = "yes" and %threshold = "no" then
%title = %title + "\r(ZLB Imposed)"
endif
if %zb = "yes" and %threshold = "yes" then
%title = %title + "\r(ZLB and Thresholds Imposed)"
endif
graph fig1.merge fig1a fig1b fig1c fig1d
fig1.addtext(t,just(c),font("Arial",16)) {%title}
fig1.addtext(b,just(c),font("Arial",16)) Blue: Actual; Red: Simulated
fig1.align(2,1,1.25)
show fig1
@
\section{example4 program}
<<frbus example4>>=
' This MCE example program illustrates:
'
' 1. how to use a monetary policy rule that is not one of the policy
' alternatives included in FRB/US;
' 2. how to add new MCE expectations variables;
' 3. how to drop one of the regular FRB/US equations as part of the process
' of loading the model
' Most of the code needed illustrate these issues is located between
' the "start of new code" and "end of new code" comments below
' The switch variables %mcvars_wp and %mcvars_all control whether
' the assumption of MC expectations extends beyond the financial
' sector
' See the Simulation Basics document for information about
' this program
' *************************************************************
' Initial filename and parameter settings
' *************************************************************
' Subroutines
include ../subs/master_library
include ../subs/mce_solve_library
' Workfile
%wfstart = "1975q1"
%wfend = "2100q4"
%mainpage = "main"
wfcreate(wf=aaa,page={%mainpage}) q {%wfstart} {%wfend}
' FRB/US model names and locations
%varmod = "stdver"
%varpath = "../mods/"
%mcemod = "pfver"
%mcepath = "../mods/"
' Input datbase
%dbin = "../data/longbase"
' Simulation range
%simstart = "2010q1"
%simend = "2069q4"
' ****************************************************************
' Retrieve data, model equations and coefficients, set
' policy options, and compute tracking residuals
' ****************************************************************
' Specify MC expectations variables
%mcvars_wp = "no"
%mcvars_all = "yes"
' MCE asset pricing
%zvars = "zdivgr zgap05 zgap10 zgap30 zrff5 zrff10 zrff30 zpi10 zpi10f zpic30 zpib5 zpic58 "
' MCE elsewhere
if %mcvars_wp = "yes" and %mcvars_all = "no" then
%zvars = %zvars + "zpicxfe zpieci "
endif
if %mcvars_all = "yes" then
%zvars = %zvars + "zpicxfe zpieci "
%zvars = %zvars + "zecd zeco zeh zgapc2 zlhp zpi5 zvpd zvpi zvps zxbd zxbi zxbs zyh zyhp zyht zynid "
endif
' Load equations and coefficients
' drop one of the FRB/US monetary policy rule equations (rffgen) so that it can be
' replaced below with an alternative rule
%allbut = "rffgen"
call mce_load_frbus("mce_vars=%zvars,mod_b=%varmod,path_b=%varpath,mod_f=%mcemod,path_f=%mcepath,allbut=%allbut")
' Load data
dbopen %dbin as longdata
fetch(d=longdata) *
' *****************************************************************************
' *****************************************************************************
' start of new code (aside from the change above to mce_load_frbus and
' the change below to the call to set_mp)
' Code a first-difference interest rate rule as rffgen. The first-difference rule depends on
' the expected output gap three quarters ahead (zgap3) and on expected 4-qtr inflation three
' quarters ahead (zpic43). The name of each new expectation must start with a "z".
{%varmod}.append rffgen-rffgen_aerr = rffe(-1) + .5*(zpic43-pitarg) + .5*(zgap3-zgap3(-4))
' Add the MCE definitions of zgap3 and zpic43 to the forward-looking model,
' noting that the MCE names of these variables must start with a "w" rather than a "z".
{%mcemod}.append wgap3-wgap3_aerr = xgap2(3)
{%mcemod}.append wpic43-wpic43_aerr = picx4(3)
' Add expectations error equations to the MCE model
{%mcemod}.append ezgap3 = zgap3-wgap3
{%mcemod}.append ezpic43 = zpic43-wpic43
' Add to the backward-looking model simple equations for the new expectations variables.
' Technically, these equations should be the appropriate VAR expectations formulas, but
' because in this program these expectations will always be MCE, the form of their
' backward-looking identities is not very important.
{%varmod}.append zgap3-zgap3_aerr = .5*xgap2(-1)
{%varmod}.append zpic43-zpic43_aerr = .5*picx4(-1)+.5*ptr(-1)
' Add the new MCE variables to the %zvars string
%zvars = %zvars + " zgap3 zpic43"
' Define baseline values of the new expectations variables
smpl @all
series zgap3 = xgap2(3)
series zpic43 = picx4(3)
' Make sure that the baseline data for rffgen matches the baseline data for rffe
rffgen = rffe
' end of new code
' *****************************************************************************
' *****************************************************************************
' Data for extra variables associated with MC expectations
smpl @all
call make_frbus_mcevars(%zvars)
' Set monetary policy to use the first-difference policy rule (coded as rffgen)
smpl @all
call set_mp("dmpgen")
' Turn off zero bound and policy thresholds; hold policymaker's
' perceived equilibrium real interest rate constant
smpl @all
dmptrsh = 0
rffmin = -9999
drstar = 0
' Set fiscal policy
smpl @all
call set_fp("dfpsrp")
' Set _aerr variables to zero
smpl @all
{%varmod}.makegroup(a,n) endog @endog
call groupnew("endog","_aerr")
call group2zero("endog_aerr")
' Standard solution options
{%varmod}.solveopt(o=b,g=12,z=1e-12)
{%mcemod}.solveopt(o=b,g=12,z=1e-12)
' Assign baseline tracking add factors
%suftrk = "_0"
smpl %simstart %simend
{%varmod}.addassign @all
{%varmod}.addinit(v=n) @all
{%varmod}.scenario(n,a={%suftrk}) "track"
{%varmod}.solve
scalar mm = @max(@abs(xgap{%suftrk}-xgap))
if mm > .0001 then
statusline dynamic tracking simulation failed for {%varmod}
stop
endif
{%mcemod}.addassign @all
{%mcemod}.addinit(v=n) @all
' *************************************************************
' Simulate the effects of a one-percent consumption shock
' *************************************************************
%sufsim = "_1"
{%varmod}.scenario(n,a={%sufsim}) "sim"
{%mcemod}.scenario(n,a={%sufsim}) "sim"
smpl %simstart %simstart
eco_a = eco_a + .01
%modstr = "mod_b=%varmod,mod_f=%mcemod,mce_vars=%zvars"
%algstr = "meth=qnewton"
%simstr = "type=single"
smpl %simstart %simend
call mce_run(%modstr,%algstr,%simstr)
'***********************************************************
' Make a graph
'***********************************************************
smpl %simstart %simstart + 39
series zero = 0
series d_rff = rff{%sufsim} - rff
series d_rg10 = rg10{%sufsim} - rg10
series d_lur = lur{%sufsim} - lur
series d_pic4 = pic4{%sufsim} - pic4
graph fig1a.line zero d_rff
fig1a.addtext(t,just(c),font("arial",12)) Federal Funds Rate
fig1a.legend -display
graph fig1b.line zero d_rg10
fig1b.addtext(t,just(c),font("arial",12)) 10-Year Treasury Yield
fig1b.legend -display
graph fig1c.line zero d_lur
fig1c.addtext(t,just(c),font("arial",12)) Unemployment Rate
fig1c.legend -display
graph fig1d.line zero d_pic4
fig1d.addtext(t,just(c),font("arial",12)) Inflation Rate (4-Quarter)
fig1d.legend -display
graph fig1.merge fig1a fig1b fig1c fig1d
%title = " Macroeconomic Effects of a Shock to Consumption\r"
if %mcvars_wp = "no" and %mcvars_all = "no" then
%title = %title + "(MC Expectations in Asset Pricing)"
endif
if %mcvars_wp = "yes" and %mcvars_all = "no" then
%title = %title + "(MC Expectations in Asset Pricing and Price-Wage Setting)"
endif
if %mcvars_all = "yes" then
%title = %title + "(MC Expectations in All Sectors)"
endif
fig1.addtext(t,just(c),font("Arial",16)) {%title}
fig1.align(2,1,1.25)
show fig1
@
\section{ocpolicy program}
<<frbus ocpolicy>>=
' Routine to simulate how the SEP baseline forecast would change if
' policymakers commit to a path for the federal funds rate that is
' determined by optimal-control (OC) techniques to minimize a
' quadratic loss function.
'
' Detailed information on the mechanics of the OC algorithm and the
' various required and optional parameters that set up and guide its
' execution is available in the MCE Solve Users Guide in the
' documentation directory. Most relevant is the part of section 5
' that describes the "opt" simulation type as well as table 7.
' As specified below, the loss function penalizes equally weighted
' squared deviations of the unemployment rate from the natural rate,
' squared deviations of inflation from a 2 percent, and squared
' quarterly changes in the funds rate.
' In the SEP baseline, agents with model-consistent (MC) expectations
' are initially assumed to project that the funds rate will follow the
' baseline path and to set their baseline expectations
' accordingly. At the start of the optimal control simulation, however,
' these agents immediately and fully revise their expectations to be
' consistent with the revision to the funds rate path that occurs under
' optimal control -- that is, agents have rational expectations and
' announced policy actions are completely credible.
'
' The experiment can be run with the zero lower bound (ZLB) imposed
' (%zerobound = "yes") or not imposed (%zerobound = "no"). When
' the ZLB is imposed, a penalty term is added to the loss function.
' *************************************************************
' Initial filename and parameter settings
' *************************************************************
' Subroutines
include ../subs/master_library
include ../subs/mce_solve_library
' Workfile
%wfstart = "1975q1"
%wfend = "2100q4"
%mainpage = "main"
wfcreate(wf=aaa,page={%mainpage}) q {%wfstart} {%wfend}
' FRB/US model names and locations
%varmod = "stdver"
%varpath = "../mods/"
%mcemod = "pfver"
%mcepath = "../mods/"
' Input datbase
%dbin = "../data/longbase"
' Simulation range
%simstart = "2014q4"
%simend = "2070q4"
' Primary loss function parameters: The value of the policy instrument
' is chosen optimally from %drvstart to %drvend (60 qtrs) to minimize
' the loss function from %evlstart to %evlend (80 qtrs). The three
' arguments of the period loss function are weighted by the the
' weight parameters and over time losses are discounted at the rate
' %discount
%evlstart = %simstart
%drvstart = %simstart
call dateshift(%evlstart,%evlend,79)
call dateshift(%drvstart,%drvend,59)
%discount = ".99"
%u_weight = "1.0"
%p_weight = "1.0"
%r_weight = "1.0"
' Optionally impose the zero lower bound
%zerobound = "yes"
' ****************************************************************
' Retrieve data, model equations and coefficients, set
' policy options, and compute tracking residuals
' ****************************************************************
' Specify MC expectations variables
%mcvars_wp = "yes"
%mcvars_all = "no"
' MCE asset pricing
%zvars = "zdivgr zgap05 zgap10 zgap30 zrff5 zrff10 zrff30 zpi10 zpi10f zpic30 zpib5 zpic58 "
' MCE elsewhere
if %mcvars_wp = "yes" and %mcvars_all = "no" then
%zvars = %zvars + "zpicxfe zpieci "
endif
if %mcvars_all = "yes" then
%zvars = %zvars + "zpicxfe zpieci "
%zvars = %zvars + "zecd zeco zeh zgapc2 zlhp zpi5 zvpd zvpi zvps zxbd zxnfbi zxnfbs zyh zyhp zyht zynid "
endif
' Load equations and coefficients
call mce_load_frbus("mce_vars=%zvars,mod_b=%varmod,path_b=%varpath,mod_f=%mcemod,path_f=%mcepath")
' Add a ugap equation
{%varmod}.append ugap - ugap_aerr = lur - lurnat
' Load data
dbopen %dbin as longdata
fetch(d=longdata) *
' Define SEP-consistent ustar and ugap series; this step is needed because
' the baseline value of lurnat may not be fully SEP-consistent in the
' short-to-medium ruun
smpl @all
series ustar = lurnat
smpl %simstart 2025q4
ustar = 5.35
smpl @all
series ugap = lur-ustar
series ugap_aerr = 0
' Data for extra variables associated with MC expectations
smpl @all
call make_frbus_mcevars(%zvars)
' Set monetary policy option (the residual on the equation of
' the chosen option is the OC policy instrument)
smpl @all
call set_mp("dmptay")
' Initially turn off zero lower bound; if %zerobound = "yes", it will be
' imposed below by adding a penalty term to the loss function.
smpl @all
rffmin = -9999
' Turn off policy thresholds
dmptrsh = 0
' Let the perceived equilibrium real interest rate vary
drstar = 1
' Set fiscal policy so that it is exogenous for first 20 qtrs and then
' turns on debt targeting rule
smpl %simstart %simstart + 19
call set_fp("dfpex")
smpl %simstart + 20 %simend
call set_fp("dfpdbt")
' Set _aerr variables to zero
smpl @all
{%varmod}.makegroup(a,n) endog @endog
call groupnew("endog","_aerr")
call group2zero("endog_aerr")
' Standard solution options
{%varmod}.solveopt(o=b,g=12,z=1e-12)
{%mcemod}.solveopt(o=b,g=12,z=1e-12)
' Assign baseline tracking add factors
%suftrk = "_0"
smpl %simstart %simend
{%varmod}.addassign @all
{%varmod}.addinit(v=n) @all
{%varmod}.scenario(n,a={%suftrk}) "track"
{%varmod}.solve
scalar mm = @max(@abs(xgap{%suftrk}-xgap))
if mm > .0001 then
statusline dynamic tracking simulation failed for {%varmod}
stop
endif
{%mcemod}.addassign @all
{%mcemod}.addinit(v=n) @all
'*************************************************************
' optimal policy setup
'*************************************************************
' The policy instrument is a time varying constant in the equation
' for the selected policy rule
group opt_instrus rfftay_aerr
' Loss function variables (unemployment gap, 4-qtr PCE inflation,
' and the first difference of the federal funds rate)
group opt_targs ugap pic4 delrff
' The desired paths of the loss function variables are specified in
' series with "_t" suffix.
smpl @all
series ugap_t = 0
series delrff_t = 0
series pic4_t = 2.0
' The weights on the loss function arguments are specified in
' series with "_w" suffix.
series ugap_w = @val(%u_weight)
series pic4_w = @val(%p_weight)