-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathspectre2018rbarSV.f90
2412 lines (1898 loc) · 83.1 KB
/
spectre2018rbarSV.f90
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
PROGRAM main
! JAN 2017
! VAR model for rollingstone -- observable ugap
! QUARTERLY MODEL
! handles also missing data
! shockslopes
! NEW: predictive density, including 4-quarter inflation
! added a flag to switch on/off pdf computations
! allowing for correlated SV shocks
! SETUP:
! Nsv SV shocks, but only Ngap of them are correlated (in levels and variances)
! i.e. Nsv: hbar, hrho, SVol, but only NGap hSigma and Nsv-Ngap hvar
! This version track two SVol blocks: "h" are correlated, "horth" are orthogonal
USE embox, only: hrulefill, savemat, savevec, storeestimatesOMP, storeestimates, lofT, int2str, timestampstr, es30d16, logtwopi
USE blaspack, only: eye, sandwich
USE gibbsbox, only: GelmanTest1, simpriormaxroot, igammadraw
use densitybox, only : crps, logGaussianScore, logGaussianScoreMV
USE vslbox
USE timerbox
USE omp_lib
IMPLICIT NONE
! ----------------------------------------------------------------------------------
LOGICAL, PARAMETER :: doTimestamp = .false.
INTEGER :: Nyield, Ny, Nbar, Ngap, Nsvorth, Nsv, Nshock, Nshockslopes
INTEGER :: gapOrderKey = 1234
! gapOrderKey is a 4-digit code that specifies the order of variables within the gap block:
! - the first digit (from the left) specifies the position of inflation
! - the 2nd digit is for ugap
! - 3rd digit is the policy rate gap
! - 4th digit is the yield block
! - the implementation is handled via a select case statement in thissampler, missing cases can simply be added there
INTEGER :: p
INTEGER :: NhSigma
INTEGER, PARAMETER :: longrateHorizon = 4 * 5 ! in quarters
LOGICAL :: ZLBrejection = .false., doPDF = .false., doPInoise = .false.
LOGICAL :: doZLBasZeroes = .false.
INTEGER, PARAMETER :: ndxSVpinoise = 2 ! hard coded, just needed to whack out Gelman stats if doPInoise = .false.
! forecasting parameters
integer :: NNyy
INTEGER, PARAMETER :: Nforecastdraws = 50
integer :: NNxx
! horizons are consecutive sequence up to maxhorizon
integer, parameter :: maxhorizons = 8
integer, dimension(maxhorizons) :: horizons
! forecast obs
! double precision, dimension(NNyy,maxhorizons) :: ypred
! logical, dimension(NNyy,maxhorizons) :: yNaNpred
double precision, allocatable, dimension(:,:) :: ypred
logical, allocatable, dimension(:,:) :: yNaNpred
! forecast results
! double precision, allocatable, dimension(:,:,:,:) :: DRAWypdf, DRAWyforecast, DRAWymedian, DRAWyprobLB, DRAWycondvar
double precision, allocatable, dimension(:,:,:,:,:) :: DRAWy
INTEGER :: Tdata
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:) :: yhatmean, yhatmedian ! , yavgcondvar, yvarcondexp, ycondvar
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:) :: crpsScore, logScore
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: logScoreMV
INTEGER :: Nx, Nf, Nstates
INTEGER :: Nsim, Burnin, Nstreams
INTEGER :: T,h,i,j,k,n,status,Ndraws
INTEGER :: T0 = 0 ! jump off when reading in data
! LOGICAL :: OK
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:,:) :: DRAWstates, DRAWsvol, DRAWsvolorth
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:) :: DRAWavgtermpremia
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:) :: DRAWhsigma, DRAWhbar, DRAWhrho
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:) :: DRAWhorthvar, DRAWhorthbar, DRAWhorthrho
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:) :: DRAWf, DRAWmaxlambda, DRAWshockslopes
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: Ef0, Eshockslopes0
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: Eh0, hrho0, minSV, maxSV, SVol0
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:) :: hSigmaT, sqrtVh0, hrhoV0
INTEGER :: hSigmaDof
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: Ehorth0, Vhorth0, horthrho0, horthrhoV0, minSVorth, maxSVorth, horthvarT, SVol0orth
INTEGER, ALLOCATABLE, DIMENSION(:) :: horthvarDof
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:) :: sqrtVf0, sqrtVshockslopes0
DOUBLE PRECISION :: lambda1Vf, lambda2Vf
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:) :: GELMANstates, GELMANsvol, GELMANsvolorth
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:) :: theta
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: theta1
! DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:) :: thetaDraws
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: GELMANf, GELMANshockslopes
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: GELMANhorthvar, GELMANhorthbar, GELMANhorthrho
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: GELMANhbar, GELMANhSigma, GELMANhrho
! DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: thetaprob
INTEGER :: ndxRealrate, ndxPIbar, ndxRbar, ndxLONGRbar, ndxPIgap, ndxPInoise, ndxUgap, ndxINTgap, ndxLONGINTgap, ndxSHADOWRATE !, ndxLONGSHADOW, ndxLONGRATE, ndxZLBPROB1, ndxZLBPROB2, ndxZLBPROB3
INTEGER :: yndxPolicyRate = 3
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:) :: y
LOGICAL, ALLOCATABLE, DIMENSION(:,:) :: yNaN, zlb
TYPE(progresstimer) :: timer
CHARACTER (LEN=200) :: filename, datafile, nandatafile, filext, datalabel
! VSL Random Stuff
! type (vsl_stream_state), allocatable, dimension(:) :: VSLstreams
type (vsl_stream_state) :: VSLdefaultstream, VSLstream
integer :: seed
! integer :: brng
integer :: errcode
INTEGER, PARAMETER :: VSLmethodGaussian = 0, VSLmethodUniform = 0
! OPEN MP
INTEGER :: NTHREADS, TID
! Lower Bound
DOUBLE PRECISION, PARAMETER :: ELBound = 0.25d0
! ----------------------------------------------------------------------------------
! MODEL PARAMETERS
! ----------------------------------------------------------------------------------
! runtime parameters :start:
! first: set default values
Nyield = 3 ! just a default, can be overriden by command line arguments
p = 2 ! just a default, can be overriden by command line arguments
Nsvorth = 3 ! this could actually have been defined as a parameter
! TOC
Nsim = 2 * (10 ** 4)
Burnin = (10 ** 5)
Nsim = 10 ** 4
Burnin = 10 ** 4
! Nsim = 10 ** 4
! Burnin = 10 ** 5
Nsim = (10 ** 3)
Burnin = (10 ** 3)
! ! QUICK
! Nsim = (10 ** 2)
! Burnin = (10 ** 2)
! ----------------------------------------------------------------------------------
! INIT
! ----------------------------------------------------------------------------------
! INIT OMP
NTHREADS = 1
!$OMP PARALLEL SHARED(NTHREADS)
!$ NTHREADS = OMP_GET_NUM_THREADS()
!$OMP END PARALLEL
Nstreams = max(NTHREADS, 4)
print *, "Number of Threads:", NTHREADS
print *, "Number of Streams:", Nstreams
! VSL
call hrulefill
write (*,*) 'Allocating VSLstreams ...'
seed = 0
errcode = vslnewstream(VSLdefaultstream, vsl_brng_mt2203, seed)
WRITE(*,*) "... default VSLstream ", VSLdefaultstream
write (*,*) '... VSLstreams done.'
call hrulefill
! define forecast horizons
forall (k=1:maxhorizons) horizons(k) = k
! read data
datalabel = 'spectreTB3MSGS020510Headline2018Q4' ! just a placeholder
! datalabel = 'spectreGS5Headline2016Q4';
! datafile = trim(datalabel) // '.yData.txt'
! Tdata = loft(datafile)
! IF (Tdata < 10) THEN
! print *, 'Less than 10 observations in input file!', datafile
! STOP 1
! END IF
! T0 = 120 ! T0 = 120 skips data prior to 1990Q1
T = Tdata - T0! default
call getarguments(ZLBrejection, doPDF, doPInoise, doZLBasZeroes, T, T0, gapOrderKey, datalabel, Nyield, p, Nsim, burnin, Nstreams)
! set parameters that depend on Nyield
Ny = 3 + Nyield
Nbar = 1 + 1 + Nyield
Ngap = Ny
Nsv = Ngap
Nshock = 1 + Nsv + Nsvorth
Nshockslopes = Nsv * (Nsv - 1) / 2
NhSigma = Nsv * (Nsv + 1) / 2
NNyy = Ny + 2 ! adding 4q-MA of inflation and the shadowrate
Nx = Nbar + (Ngap * p) + 1 ! Nbar and Ngaps (with lags), pinoise
Nf = Ngap * (Ngap * p)
! runtime parameters :end:
Nstates = 8 + 2 * Nyield ! see list of ndxXXX below
ndxRealrate = 1
ndxPIbar = 2
ndxRbar = 3
ndxLONGRbar = 4
ndxPIgap = ndxLONGRbar + Nyield
ndxUgap = ndxPIgap + 1
ndxINTgap = ndxUgap + 1
ndxLONGINTgap = ndxINTgap + 1
ndxPInoise = ndxLONGINTgap + Nyield
ndxSHADOWRATE = ndxPInoise + 1
if (ndxSHADOWrate .ne. Nstates) then
print *, 'state indices are off'
stop 1
end if
if (doZLBasZeroes) then
! doShadowObsGap = .false.
ZLBrejection = .false.
end if
datafile = trim(datalabel) // '.yData.txt'
nandatafile = trim(datalabel) // '.yNaN.txt'
print *, datalabel
print *, datafile
Tdata = loft(datafile)
IF (Tdata < T) THEN
print *, 'Data file has less than T obs', datafile, T, Tdata
STOP 1
END IF
! read in data
ALLOCATE (yNaN(Ny,T), zlb(Ny,T), y(Ny,T), STAT=status)
IF (status /= 0) THEN
WRITE (*,*) 'Allocation problem (Y)'
END IF
! print *, 'trying to read', T, 'obs from', datafile
CALL readdata(y,datafile,Ny,T,T0)
CALL readnandata(yNaN,nandatafile,Ny,T,T0)
if (doZLBasZeroes .eqv. .true.) then
yNaN(yndxPolicyRate,:) = .false.
end if
! call savemat(y, 'y.debug')
! call savemat(dble(yNaN), 'yNaN.debug')
! define a separate ZLB index to distinguish rates at ZLB from actually missing observations
zlb = .false.
! for now: zlb matters only for poliyc rate not longer-term yields
! NOTE: key assumption is that missing obs for policy rate are solely due to ZLB!!
zlb(yndxPolicyRate,:) = yNaN(yndxPolicyRate,:)
ALLOCATE (ypred(NNyy,maxhorizons), ynanpred(NNyy,maxhorizons), STAT=status)
IF (status /= 0) THEN
WRITE (*,*) 'Allocation problem (Y)'
END IF
ypred = readpreddata(datafile,Ny,NNyy,maxhorizons,Tdata,T+T0)
yNaNpred = readprednandata(nandatafile,Ny,NNyy,maxhorizons,Tdata,T+T0)
! fix ELB predictions for the policy rate:
! they are read in as missing data, but should be set to the ELB
! assumptions:
! -- there are no missing data for the policy rate in sample
! -- ELB obs are encoded as exact zeros
where (ypred(yndxPolicyRate,:) == 0.0d0)
ypred(yndxPolicyRate,:) = ELBound
yNaNpred(yndxPolicyRate,:) = .false.
end where
! same for the shadowrate
where (ypred(NNyy,:) == 0.0d0)
ypred(NNyy,:) = ELBound
yNaNpred(NNyy,:) = .false.
end where
! call savemat(ypred, 'ypred.debug')
! call savemat(dble(ynanpred), 'nanypred.debug')
! stop 11
! setup number of states in extended state vector (used for forecasting; append 3 inflation lags)
NNxx = Nx + 3
filext = '.SPECTREVAR.' // trim(datalabel) // '.VARlags' // trim(int2str(p)) // '.order' // trim(int2str(gapOrderKey)) // '.ar1svcorRbarSV.T' // trim(int2str(T)) // '.Tjumpoff' // trim(int2str(T0)) // '.dat'
if (ZLBrejection) then
filext = '.zlb' // filext
end if
if (.not. doPInoise) then
filext = '.nopinoise' // filext
end if
if (doZLBasZeroes) then
filext = '.zlbaszeroes' // filext
end if
if (doTimeStamp) filext = '.' // timestampstr() // filext
! Model parameters and priors
ALLOCATE (Ef0(Nf), sqrtVf0(Nf,Nf))
ALLOCATE (SVol0(Nsv), Eh0(Nsv), minSV(Nsv), maxSV(Nsv), sqrtVh0(Nsv,Nsv), hSigmaT(Nsv,Nsv), hrho0(Nsv), hrhoV0(Nsv,Nsv))
ALLOCATE (SVol0orth(Nsvorth), Ehorth0(Nsvorth), minSVorth(Nsvorth), maxSVorth(Nsvorth), Vhorth0(Nsvorth), horthvarT(Nsvorth), horthvarDof(Nsvorth), horthrho0(Nsvorth), horthrhoV0(Nsvorth))
! horthrhoV0 is a vector since prior is independend in case of orthogona;l SV's
ALLOCATE (Eshockslopes0(Nshockslopes), sqrtVshockslopes0(Nshockslopes,Nshockslopes))
! ----------------------------------------------------------
! Sigma
! ----------------------------------------------------------
! SV
! TODO recalibrate?
SVol0 = 0.1d0
Eh0 = log(SVol0 ** 2)
call eye(sqrtVh0, 5.0d0)
hSigmaDof = Nsv + 1 + 10
call eye(hSigmaT, (.2d0 ** 2) * dble(hSigmaDof - Nsv - 1))
hrho0 = 0.8d0
call eye(hrhoV0, 0.2d0 ** 2)
minSV = 0.001d0 ! 0.0001d0 causes failure for t=123
maxSV = 100.0d0
SVol0orth = 0.1d0
Vhorth0 = 5.0d0 ** 2
Ehorth0 = log(SVol0 ** 2)
horthvarDof = 12
horthvarT = (0.2d0 ** 2) * dble(horthvarDof - 2) ! was 0.1 ...
horthrho0 = 0.8d0
horthrhoV0 = 0.2d0 ** 2
minSVorth = 0.001d0 ! 0.0001d0 causes failure for t=123
maxSVorth = 100.0d0
! cycle VAR coefficients
Ef0 = 0.0d0
lambda1Vf = 0.3d0
lambda2Vf = 1.0d0
lambda1Vf = 0.5d0
lambda2Vf = 0.2d0
call minnesotaVCVsqrt(sqrtVf0, Ny, p, lambda1Vf, lambda2Vf)
! gap-shockslopes
Eshockslopes0 = 0.0d0
call eye(sqrtVshockslopes0, 1.0d0) ! NEW: value was 1.0d0
! REPORT PARAMETERS TO SCREEN
CALL HRULEFILL
print *, 'data = ' // trim(datalabel)
print *, 'T = ', T
print *, 'T0 = ', T0
! print *, 'longrateHorizon= ', longrateHorizon
print *, 'Nsim = ', Nsim
print *, 'Burnin = ', Burnin
print *, 'Nstreams = ', Nstreams
print *, 'p = ', p
print *, 'gapOrderKey= ', gapOrderKey
print *, 'ELBound = ', ELBound
if (doPInoise) then
print *, 'with PI noise'
else
print *, 'without PI noise'
end if
if (ZLBrejection) print *, 'with ZLB rejection'
! if (doLongRateTruncation) print *, 'with LongRateTruncation'
if (doPDF) print *, 'with PDF computation'
if (doZLBasZeroes) print *, 'treating policy rate at ELB as data'
CALL HRULEFILL
! ----------------------------------------------------------------------------
! GENERATE AND STORE DRAWS FROM PRIORS
! ----------------------------------------------------------------------------
Ndraws = max(10000, Nsim * Nstreams)
! ! hvar
! ALLOCATE (theta(Nsv,Ndraws))
! DO j = 1, Nsv
! DO k = 1, Ndraws
! call igammaDraw(theta(j,k), hvarT(j), hvarDof(j), VSLdefaultstream)
! END DO
! END DO
! filename = 'hvar' // '.prior' // filext
! call savemat(transpose(theta), filename)
! WRITE (*,*) 'STORED PRIOR HVAR'
! DEALLOCATE (theta)
! TODO: hbar
! ! hrho
! ALLOCATE (theta(Nsv,Ndraws),theta2(Ndraws))
! theta = 10.0d0
! do j=1,Nsv
! OK = .FALSE.
! do while (.not. OK)
! errcode = vdrnggaussian(VSLmethodGaussian, VSLdefaultstream, Ndraws, theta2, 0.0d0, 1.0d0)
! where (abs(theta(j,:)) > 1.0d0) theta(j,:) = theta2 * sqrt(hrhoV0(j)) + hrho0(j)
! ok = all(abs(theta(j,:)) < 1.0d0)
! end do
! end do
! filename = 'hrho' // '.prior' // filext
! call savemat(transpose(theta), filename)
! WRITE (*,*) 'STORED PRIOR hrho'
! DEALLOCATE (theta,theta2)
! ! SVol0
! ALLOCATE (theta(Nsv,Ndraws))
! errcode = vdrnggaussian(VSLmethodGaussian, VSLdefaultstream, Ndraws * Nsv, theta, 0.0d0, 1.0d0)
! FORALL (j = 1:Nsv) theta(j,:) = theta(j,:) * sqrt(Vh0(j)) + Eh0(j)
! theta = exp(theta * 0.5d0)
! filename = 'SVol0' // '.prior' // filext
! call savemat(transpose(theta), filename)
! WRITE (*,*) 'STORED PRIOR SVol0'
! DEALLOCATE (theta)
! maxlambda
ALLOCATE (theta(Ndraws,1))
call simPriorMaxroot(theta(:,1), Ndraws, Ef0, sqrtVf0, Ny, p, VSLdefaultstream)
filename = 'maxlambda' // '.prior' // filext
call savevec(theta(:,1), filename)
WRITE (*,*) 'STORED PRIOR MAXLAMBDA'
DEALLOCATE (theta)
! shockslopes
ALLOCATE (theta(Nshockslopes,Ndraws))
errcode = vdrnggaussian(VSLmethodGaussian, VSLdefaultstream, Ndraws * Nshockslopes, theta, 0.0d0, 1.0d0)
CALL DTRMM('L', 'U', 'N', 'N', Nshockslopes, Ndraws, 1.0d0, sqrtVshockslopes0, Nshockslopes, theta, Nshockslopes)
filename = 'shockslopes' // '.prior' // filext
call savemat(transpose(theta), filename)
WRITE (*,*) 'STORED PRIOR SHOCKSLOPES'
DEALLOCATE (theta)
! ----------------------------------------------------------------------------
! DONE: SIMULATING PRIORS
! ----------------------------------------------------------------------------
! allocate memory for draws
ALLOCATE (DRAWmaxlambda(1,Nsim,Nstreams), DRAWf(Nf,Nsim,Nstreams), DRAWshockslopes(Nshockslopes,Nsim,Nstreams), DRAWstates(Nstates,0:T,Nsim,Nstreams), STAT=status)
ALLOCATE (DRAWavgtermpremia(Nyield,Nsim,Nstreams), STAT=status)
ALLOCATE (DRAWhorthvar(Nsvorth,Nsim,Nstreams), DRAWhorthbar(Nsvorth,Nsim,Nstreams), DRAWsvolorth(Nsvorth,0:T,Nsim,Nstreams), STAT=status)
ALLOCATE (DRAWhorthrho(Nsvorth,Nsim,Nstreams), STAT=status)
ALLOCATE (DRAWhsigma(Nhsigma,Nsim,Nstreams), DRAWhbar(Nsv,Nsim,Nstreams), DRAWsvol(Nsv,0:T,Nsim,Nstreams), STAT=status)
ALLOCATE (DRAWhrho(Nsv,Nsim,Nstreams), STAT=status)
! IF (status /= 0) THEN
! WRITE (*,*) 'Allocation problem (draws)'
! END IF
allocate(DRAWy(NNyy,maxhorizons,Nforecastdraws,Nsim,Nstreams))
call hrulefill
WRITE(*,*) 'STARTING SWEEPS'
call hrulefill
!$OMP PARALLEL DO SHARED(DRAWy,DRAWavgtermpremia,DRAWstates,DRAWsvol,DRAWf,DRAWshockslopes,DRAWhorthvar,DRAWhorthbar,DRAWhorthrho,DRAWsvolorth, DRAWhSigma,DRAWhbar,DRAWhrho,DRAWmaxlambda), FIRSTPRIVATE(ZLBrejection,doPDF,doPInoise, gapOrderKey, Nstreams, Nsim,Burnin,T,y,yNaN,zlb,Nstates,Nx, Nf, Eshockslopes0, sqrtVshockslopes0, Ef0, sqrtVf0, Eh0, sqrtVh0, minSV, maxSV, hSigmaT, hSigmaDof, hrho0, hrhoV0, Ehorth0, Vhorth0, minSVorth, maxSVorth, horthvarT, horthvarDof, horthrho0, horthrhoV0, NNxx), PRIVATE(VSLstream,TID,errcode,timer) SHARED(Nyield,Ny,Nbar,Ngap,Nshock,Nshockslopes,p,Nsv,Nhsigma,Nsvorth,NNyy) DEFAULT(NONE) SCHEDULE(STATIC)
DO j=1,Nstreams
TID = 0
!$ TID = OMP_GET_THREAD_NUM()
errcode = vslnewstream(VSLstream, vsl_brng_mt2203 + 1 + j, 0)
if (errcode /= 0) then
print *,'VSL new stream failed'
stop 1
end if
WRITE(*,'(a16, i2, a5, i2, a8, i20, i20)') ' LAUNCHING SWEEP ', j, ' TID ', TID, ' Stream ', VSLstream%descriptor1, VSLstream%descriptor2
! print *,' TID ', TID, VSLstream
CALL initprogressbar(timer, 15.0d0, j)
call thissampler(ZLBrejection, ELBound, doPDF, doPInoise, gapOrderKey, T, Ny, Nyield, y, yNaN, zlb, NNyy, NNxx, DRAWy(:,:,:,:,j), Nforecastdraws, maxhorizons, DRAWavgtermpremia(:,:,j), DRAWstates(:,:,:,j), Nstates, Nx, Nshock, Nbar, Ngap, p, DRAWf(:,:,j), Nf, Ef0, sqrtVf0, DRAWmaxlambda(:,:,j), DRAWsvol(:,:,:,j), Nsv, Eh0, sqrtVh0, minSV, maxSV, DRAWhbar(:,:,j), DRAWhSigma(:,:,j), NhSigma, hSigmaT, hSigmaDof, DRAWhrho(:,:,j), hrho0, hrhoV0, DRAWsvolorth(:,:,:,j), Nsvorth, Ehorth0, Vhorth0, minSVorth, maxSVorth, DRAWhorthbar(:,:,j), DRAWhorthvar(:,:,j), horthvarT, horthvarDof, DRAWhorthrho(:,:,j), horthrho0, horthrhoV0, DRAWshockslopes(:,:,j), Nshockslopes, Eshockslopes0, sqrtVshockslopes0, Nsim, Burnin, VSLstream, timer)
! WRITE(*,*) 'STREAM', j, 'IS DONE.', ' (TID: ', TID, ')'
errcode = vsldeletestream(VSLstream)
END DO
!$OMP END PARALLEL DO
CALL HRULEFILL
WRITE (*,*) 'ALL STREAMS ARE DONE!'
CALL HRULEFILL
! WRITE SETTINGS
CALL HRULEFILL
filename = 'settings' // trim(adjustl(filext))
OPEN (UNIT=4, FILE=filename, STATUS='REPLACE', ACTION='WRITE')
WRITE(4,'(a20,a20)') 'TIME: ', timestampstr()
WRITE(4,'(a20,a20)') 'Data: ', datalabel
! WRITE(4,'(a20,I20)') 'longrateHorizon: ', longrateHorizon
WRITE(4,'(a60)') repeat('-',60)
WRITE(4,'(a20,I20)') 'Sims: ', Nsim
WRITE(4,'(a20,I20)') 'Burnin: ', Burnin
WRITE(4,'(a20,I20)') 'Streams: ', Nstreams
WRITE(4,'(a20,I20)') 'p: ', p
WRITE(4,'(a20,F4.2)') 'ELBound: ', ELBound
WRITE(4,'(a60)') repeat('-',60)
WRITE(4,'(a60)') repeat('-',60)
CLOSE(UNIT=4)
CALL HRULEFILL
! ----------------------------------------------------------------------------
! STORE
! ----------------------------------------------------------------------------
CALL HRULEFILL
WRITE (*,*) 'STARTING W/STORAGE'
CALL HRULEFILL
! STORE ESTIMATES
! Note: manual reshape avoids segmentation faults
Ndraws = Nsim * Nstreams
filename = 'YDATA' // filext
call savemat(y, filename)
filename = 'YNAN' // filext
call savemat(dble(ynan), filename)
ALLOCATE (theta(T,Ndraws))
! filename = 'INFLATIONTREND.DRAWS' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxRealrate,1:T,k,j)
! call savemat(theta, filename)
filename = 'REALRATE' // filext
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED REALRATE'
! filename = 'INFLATIONTREND.DRAWS' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxPIbar,1:T,k,j)
! call savemat(theta, filename)
filename = 'INFLATIONTREND' // filext
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED INFLATIONTREND'
! filename = 'REALRATETREND.DRAWS' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxRbar,1:T,k,j)
! call savemat(theta, filename)
filename = 'REALRATETREND' // filext
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED REALRATETREND'
do i = 1,Nyield
! filename = 'LONGREALRATETREND.DRAWS' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxLONGRbar+i-1,1:T,k,j)
! call savemat(theta, filename)
filename = 'LONGREALRATETREND' // trim(int2str(i)) // filext
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED LONGREALRATETREND'
! filename = 'LONGNOMINALRATETREND.DRAWS' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxPIbar,1:T,k,j) + DRAWstates(ndxLONGRbar+1,1:T,k,j)
! call savemat(theta, filename)
filename = 'LONGNOMINALRATETREND' // trim(int2str(i)) // filext
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED LONGNOMINALRATETREND'
end do
filename = 'INFLATIONGAP' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxPIgap,1:T,k,j)
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED INFLATIONGAP'
filename = 'UGAP' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxUgap,1:T,k,j)
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED UGAP'
filename = 'INTGAP' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxINTgap,1:T,k,j)
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED INTGAP'
do i = 1,Nyield
filename = 'LONGINTGAP' // trim(int2str(i)) // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxLONGINTgap+i-1,1:T,k,j)
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED LONGINTGAP', i
end do
if (doPInoise) then
filename = 'INFLATIONNOISE' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxPINOISE,1:T,k,j)
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED INFLATIONNOISE'
end if
! filename = 'SHADOWRATE.DRAWS' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxSHADOWRATE,1:T,k,j)
! call savemat(theta, filename)
filename = 'SHADOWRATE' // filext
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED SHADOWRATE'
filename = 'NOMINALRATETREND' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxPIbar,1:T,k,j) + DRAWstates(ndxRbar,1:T,k,j)
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED NOMINALRATETREND'
DO i=1,Nsv
filename = 'SV' // trim(int2str(i)) // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWsvol(i,1:T,k,j)
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED SV', i
END DO
DO i=1,Nsvorth
filename = 'SVORTH' // trim(int2str(i)) // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWsvolorth(i,1:T,k,j)
CALL storeEstimatesOMP(theta,T,Ndraws,filename)
WRITE (*,*) 'STORED SVORTH', i
END DO
DEALLOCATE(theta)
! STORE PARAMETERS
ALLOCATE(theta(1,Ndraws))
filename = 'DELTAREALRATETREND' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWstates(ndxRbar,T,k,j) - DRAWstates(ndxRbar,0,k,j)
CALL savevec(theta(1,:),filename)
DEALLOCATE(theta)
WRITE (*,*) 'STORED DELTAREALRATETREND'
ALLOCATE(theta(Nf,Ndraws))
filename = 'F' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWf(:,k,j)
CALL storeEstimatesOMP(theta,Nf,Ndraws,filename)
! filename = 'F.draws' // filext
! CALL savemat(theta, filename)
DEALLOCATE(theta)
WRITE (*,*) 'STORED F'
ALLOCATE(theta(Nshockslopes,Ndraws))
filename = 'SHOCKSLOPES' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWshockslopes(:,k,j)
! CALL storeEstimatesOMP(theta,Nshockslopes,Ndraws,filename)
! filename = 'F.draws' // filext
CALL savemat(transpose(theta), filename)
DEALLOCATE(theta)
WRITE (*,*) 'STORED SHOCKSLOPES'
ALLOCATE(theta(NhSigma,Ndraws))
filename = 'HSIGMA.DRAWS' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWhSigma(:,k,j)
CALL savemat(transpose(theta), filename)
filename = 'HSIGMA' // filext
CALL storeEstimates(theta,NhSigma,Ndraws,filename)
DEALLOCATE(theta)
WRITE (*,*) 'STORED HSIGMA'
ALLOCATE(theta(Nsv,Ndraws))
filename = 'HBAR' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWhbar(:,k,j)
CALL savemat(transpose(theta), filename)
DEALLOCATE(theta)
WRITE (*,*) 'STORED HBAR'
ALLOCATE(theta(Nsv,Ndraws))
filename = 'HRHO' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWhrho(:,k,j)
CALL savemat(transpose(theta), filename)
DEALLOCATE(theta)
WRITE (*,*) 'STORED HRHO'
ALLOCATE(theta(Nsvorth,Ndraws))
filename = 'HORTHVAR' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWhorthvar(:,k,j)
CALL savemat(transpose(theta), filename)
DEALLOCATE(theta)
WRITE (*,*) 'STORED HORTHVAR'
ALLOCATE(theta(Nsvorth,Ndraws))
filename = 'HORTHBAR' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWhorthbar(:,k,j)
CALL savemat(transpose(theta), filename)
DEALLOCATE(theta)
WRITE (*,*) 'STORED HORTHBAR'
ALLOCATE(theta(Nsvorth,Ndraws))
filename = 'HORTHRHO' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWhorthrho(:,k,j)
CALL savemat(transpose(theta), filename)
DEALLOCATE(theta)
WRITE (*,*) 'STORED HORTHRHO'
ALLOCATE(theta(1,Ndraws))
filename = 'MAXLAMBDA' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWmaxlambda(:,k,j)
! CALL storeEstimates(theta,1,Ndraws,filename)
CALL savevec(theta(1,:), filename)
DEALLOCATE(theta)
WRITE (*,*) 'STORED MAXLAMBDA'
! STORE DRAWS OF AVG TERM PREMIA
ALLOCATE(theta(Nyield,Ndraws))
filename = 'AVGTERMPREMIA' // filext
FORALL (k=1:Nsim,j=1:Nstreams) theta(:,(j-1) * Nsim + k) = DRAWavgtermpremia(:,k,j)
CALL savemat(theta, filename)
DEALLOCATE(theta)
WRITE (*,*) 'STORED AVG TERM PREMIA'
if (doPDF) then
! collect
call hrulefill
WRITE (*,*) 'COLLECTING PREDICTIVE DENSITY'
call hrulefill
filename = 'YPRED' // filext
call savemat(ypred(:,horizons), filename)
filename = 'YNANPRED' // filext
call savemat(dble(yNaNpred(:,horizons)), filename)
filename = 'YHORIZONS' // filext
call savevec(dble(horizons), filename)
! DRAWY
Ndraws = Nsim * Nstreams * Nforecastdraws
ALLOCATE(theta(maxhorizons,Ndraws))
ALLOCATE(yhatmedian(NNyy,maxhorizons))
! WRITE OUT YDRAW
DO i=1,NNyy
FORALL (h=1:maxhorizons,k=1:Nsim,j=1:Nstreams,n=1:Nforecastdraws) theta(h,(j-1) * (Nsim * Nforecastdraws) + (k - 1) * Nforecastdraws + n) = DRAWy(i,h,n,k,j)
filename = 'YDRAW' // trim(int2str(i)) // filext
CALL storeEstimatesOMP(theta,maxhorizons,Ndraws,filename)
WRITE (*,*) 'STORED YDRAW', i
! note: theta is returned in sorted state
yhatmedian(i,:) = theta(:,floor(real(Ndraws) * 0.5))
END DO
DEALLOCATE(theta)
! STORE MEDIAN FORECAST
filename = 'YHATMEDIAN' // filext
CALL savemat(yhatmedian, filename)
WRITE (*,*) 'STORED YHATMEDIAN'
filename = 'YHATMEDIANERROR' // filext
yhatmedian = ypred - yhatmedian
where (yNaNpred) yhatmedian = -999.0d0
CALL savemat(yhatmedian, filename)
WRITE (*,*) 'STORED YHATMEDIANERROR'
DEALLOCATE(yhatmedian)
! STORE MEAN FORECAST
ALLOCATE(yhatmean(NNyy,maxhorizons))
forall (h=1:maxhorizons,i=1:NNyy) yhatmean(i,h) = sum(DRAWy(i,h,:,:,:)) / dble(Ndraws)
filename = 'YHATMEAN' // filext
CALL savemat(yhatmean, filename)
WRITE (*,*) 'STORED YHATMEAN'
filename = 'YHATMEANERROR' // filext
yhatmean = ypred - yhatmean
where (yNaNpred) yhatmean = -999.0d0
CALL savemat(yhatmean, filename)
WRITE (*,*) 'STORED YHATMEANERROR'
DEALLOCATE(yhatmean)
! write out the scores in a separate loop
WRITE (*,*) 'COMPUTING SCORES ... '
ALLOCATE(crpsScore(NNyy,maxhorizons))
ALLOCATE(logScore(NNyy,maxhorizons))
!$OMP PARALLEL DO SHARED(theta, DRAWy, ypred, crpsScore, logScore, Nstreams, Nsim, Ndraws, NNyy) PRIVATE(theta1,h,k,j,n) DEFAULT(NONE) SCHEDULE(STATIC)
DO i=1,NNyy
ALLOCATE(theta1(Ndraws))
do h = 1,maxhorizons
FORALL (k=1:Nsim,j=1:Nstreams,n=1:Nforecastdraws) theta1((j-1) * (Nsim * Nforecastdraws) + (k - 1) * Nforecastdraws + n) = DRAWy(i,h,n,k,j)
crpsScore(i,h) = crps(ypred(i,h), theta1, Ndraws)
logScore(i,h) = logGaussianScore(ypred(i,h), theta1, Ndraws)
end do
DEALLOCATE(theta1)
END DO
!$OMP END PARALLEL DO
! DEALLOCATE(theta1)
filename = 'CRPS' // filext
CALL savemat(crpsScore, filename)
WRITE (*,*) 'STORE CRPSSCORE'
filename = 'LOGSCORE' // filext
CALL savemat(logScore, filename)
WRITE (*,*) 'STORE LOGSCORE'
deallocate(crpsScore)
deallocate(logScore)
! MV logGaussianScore
ALLOCATE(logScoreMV(maxhorizons))
ALLOCATE(theta(Ny,Ndraws))
do h = 1,maxhorizons
FORALL (i=1:Ny,k=1:Nsim,j=1:Nstreams,n=1:Nforecastdraws) theta(i,(j-1) * (Nsim * Nforecastdraws) + (k - 1) * Nforecastdraws + n) = DRAWy(i,h,n,k,j)
logScoreMV(h) = logGaussianScoreMV(ypred(:,h), theta, Ny, Ndraws)
end do
filename = 'MVLOGSCORE' // filext
CALL savevec(logScoreMV, filename)
WRITE (*,*) 'STORE MVLOGSCORE'
DEALLOCATE(theta)
DEALLOCATE(logScoreMV)
end if
! ----------------------------------------------------------------------------
! FINISHED: STORE
! ----------------------------------------------------------------------------
! ----------------------------------------------------------------------------
! GELMAN
! ----------------------------------------------------------------------------
ALLOCATE (GELMANstates(Nstates,T), GELMANf(Nf), GELMANshockslopes(Nshockslopes), STAT=status)
ALLOCATE (GELMANsvol(Nsv,T), GELMANhbar(Nsv), GELMANhsigma(NhSigma), STAT=status)
ALLOCATE (GELMANhrho(Nsv), STAT=status)
ALLOCATE (GELMANsvolorth(Nsvorth,T), GELMANhorthbar(Nsvorth), GELMANhorthvar(Nsvorth), STAT=status)
ALLOCATE (GELMANhorthrho(Nsvorth), STAT=status)
! IF (status /= 0) THEN
! WRITE (*,*) 'Allocation problem (Gelman statistics)'
! END IF
CALL HRULEFILL
WRITE (*,*) 'GELMAN STORAGE ALLOCATED'
CALL HRULEFILL
!$OMP PARALLEL SHARED(DRAWstates,GELMANstates,DRAWf,GELMANF,GELMANshockslopes, DRAWshockslopes, DRAWsvol,GELMANsvol,DRAWsvolorth,GELMANsvolorth, DRAWhorthvar, GELMANhorthvar, DRAWhSigma, GELMANhSigma, DRAWhbar, GELMANhbar, DRAWhorthbar, GELMANhorthbar, DRAWhorthrho, GELMANhorthrho, DRAWhrho, GELMANhrho)
!$OMP DO
DO j = 1, Nstates
if (j == ndxUgap) then
GELMANstates(j,:) = 1.0d0
forall (i=1:Nstreams,k=1:Nsim) DRAWstates(j,1:T,k,i) = DRAWstates(j,1:T,k,i) - y(1,:)
print *,'max ugap delta:', maxval(abs(DRAWstates(j,1:T,:,:)))
else
DO k = 1,T
call GelmanTest1(GELMANstates(j,k), Drawstates(j,k,:,:), Nsim, Nstreams)
END DO
end if
END DO
!$OMP END DO
if (.not. doPInoise) GELMANstates(ndxPInoise,:) = 1.0d0
!$OMP DO
DO k = 1,T
DO j = 1, Nsv
call GelmanTest1(GELMANsvol(j,k), DRAWsvol(j,k,:,:), Nsim, Nstreams)
END DO
END DO
!$OMP END DO
!$OMP DO
DO k = 1,T
DO j = 1, Nsvorth
call GelmanTest1(GELMANsvolorth(j,k), DRAWsvolorth(j,k,:,:), Nsim, Nstreams)
END DO
END DO
!$OMP END DO
if (.not. doPInoise) GELMANsvolorth(ndxSVpinoise,:) = 1.0d0
!$OMP DO
DO j = 1, Nsvorth
call GelmanTest1(GELMANhorthvar(j), DRAWhorthvar(j,:,:), Nsim, Nstreams)
END DO
!$OMP END DO
if (.not. doPInoise) GELMANhorthvar(ndxSVpinoise) = 1.0d0
!$OMP DO
DO j = 1, Nsvorth
call GelmanTest1(GELMANhorthbar(j), DRAWhorthbar(j,:,:), Nsim, Nstreams)
END DO
!$OMP END DO
if (.not. doPInoise) GELMANhorthbar(ndxSVpinoise) = 1.0d0
!$OMP DO
DO j = 1, NhSigma
call GelmanTest1(GELMANhSigma(j), DRAWhSigma(j,:,:), Nsim, Nstreams)
END DO
!$OMP END DO
!$OMP DO
DO j = 1, Nsv
call GelmanTest1(GELMANhbar(j), DRAWhbar(j,:,:), Nsim, Nstreams)
END DO
!$OMP END DO
!$OMP DO
DO j = 1, Nsv
call GelmanTest1(GELMANhrho(j), DRAWhrho(j,:,:), Nsim, Nstreams)
END DO
!$OMP END DO
!$OMP DO
DO j = 1, Nsvorth
call GelmanTest1(GELMANhorthrho(j), DRAWhorthrho(j,:,:), Nsim, Nstreams)
END DO
!$OMP END DO
if (.not. doPInoise) GELMANhorthrho(ndxSVpinoise) = 1.0d0
!$OMP DO
DO j = 1, Nf
call GelmanTest1(GELMANf(j), DRAWf(j,:,:), Nsim, Nstreams)
END DO
!$OMP END DO
!$OMP DO
DO j = 1, Nshockslopes
call GelmanTest1(GELMANshockslopes(j), DRAWshockslopes(j,:,:), Nsim, Nstreams)
END DO
!$OMP END DO
!$OMP END PARALLEL
CALL HRULEFILL
WRITE (*,*) 'GELMAN STATISTICS ARE DONE!'
CALL HRULEFILL
IF (ALL(ABS(GELMANstates - 1) < 0.2)) THEN
WRITE(*,*) 'Gelman found decent convergence for the STATES'
ELSE
WRITE(*,*) 'STATES: GELMAN FAILURE, Max SRstat=', maxval(GELMANstates)
END IF
filename = 'GELMAN.states' // filext
call savemat(GELMANstates, filename)
IF (ALL(ABS(GELMANsvol - 1) < 0.2)) THEN
WRITE(*,*) 'Gelman found decent convergence for the SVOL'
ELSE
WRITE(*,*) 'SVOL: GELMAN FAILURE, Max SRstat=', maxval(GELMANsvol)
END IF
filename = 'GELMAN.svol' // filext
call savemat(GELMANsvol, filename)
IF (ALL(ABS(GELMANsvolorth - 1) < 0.2)) THEN
WRITE(*,*) 'Gelman found decent convergence for the SVOLORTH'
ELSE
WRITE(*,*) 'SVOLORTH: GELMAN FAILURE, Max SRstat=', maxval(GELMANsvolorth)
END IF
filename = 'GELMAN.svolorth' // filext
call savemat(GELMANsvolorth, filename)
IF (ALL(ABS(GELMANhSigma - 1) < 0.2)) THEN
WRITE(*,*) 'Gelman found decent convergence for HSIGMA'
ELSE
WRITE(*,*) 'HSIGMA: GELMAN FAILURE, Max SRstat=', maxval(GELMANhsigma)
END IF
filename = 'GELMAN.hsigma' // filext