The SMC Procedure

Autoregressive Stochastic Volatility Model

This example illustrates how to define an autoregressive stochastic volatility model in the SMC procedure and then estimate the parameters by using the particle Markov chain Monte Carlo (PMCMC) method.

The stochastic volatility model assumes that the volatility is a latent variable with unexpected innovation terms (Shephard 2005). The discrete-time autoregressive stochastic volatility (ARSV) model proposed by Taylor (1982) is one of the simplest stochastic volatility models. The ARSV model, in which the log variance follows a linear Gaussian process, is given as

StartLayout 1st Row  StartLayout 1st Row 1st Column y Subscript t 2nd Column equals beta exp left-parenthesis StartFraction x Subscript t Baseline Over 2 EndFraction right-parenthesis xi Subscript t Baseline comma xi Subscript t Baseline tilde Overscript iid Endscripts upper N left-parenthesis 0 comma 1 right-parenthesis 2nd Row 1st Column x Subscript t 2nd Column equals phi x Subscript t minus 1 Baseline plus gamma eta Subscript t Baseline comma eta Subscript t Baseline tilde Overscript iid Endscripts upper N left-parenthesis 0 comma 1 right-parenthesis comma xi Subscript t Baseline up-tack eta Subscript t Baseline EndLayout EndLayout

where left-brace y Subscript t Baseline right-brace Subscript t greater-than-or-equal-to 1 denotes the log daily return series and left-brace beta exp left-parenthesis StartFraction x Subscript t Baseline Over 2 EndFraction right-parenthesis right-brace Subscript t greater-than-or-equal-to 1 denotes the daily volatility series. Suppose that the true parameter values are phi equals 0.9, gamma equals 0.4, beta equals 1, and x 0 equals 0.45. In order to bring these initial settings in line with the real data, here the left-brace y Subscript t Baseline right-brace Subscript t greater-than-or-equal-to 1 denotes the 100-times-magnified log daily return series; that is, y Subscript t Baseline equals 100 ln StartFraction upper S Subscript t Baseline Over upper S Subscript t Baseline minus 1 EndFraction, where upper S Subscript t is the asset price at day t (t greater-than-or-equal-to 1).

The following statements simulate 280 observations by using the given stochastic volatility model:

/*--- parameter values ---*/
%let phi = 0.9;
%let gamma = 0.4;
%let beta = 1;

/*--- Simulate a sample for the stochastic volatility model ---*/
data asv_all;
   xlag = 0.45;
   do t = 1 to 280;
      eps = normal(1);
      x = &phi*xlag + &gamma*eps;
      eta = normal(1);
      y = &beta*exp(x/2)*eta;
      output;
      xlag = x;
   end;
run;

The following DATA steps load the data set asv_all into a data table in your CAS session that is associated with the mycas CAS engine libref. The DATA step assumes that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref. The data set asv_all is split such that the first 275 observations are used as the training set and the last 5 observations are used as the test set:

data asv_train;
   set asv_all;
   if (t le 275) then output;
run;

data asv_test;
   set asv_all;
   if (t > 275) then output;
run;

data mycas.asv_train;
   set asv_train;
run;

The model specification defines the transition and measurement distributions. For the initialization distribution of the state variable, the normal distribution whose mean is 0 and variance is 4 is used. Moreover, the prior distributions for the parameters are defined as

StartLayout 1st Row 1st Column phi 2nd Column tilde UNIFORM left-parenthesis 0 comma 1 right-parenthesis 2nd Row 1st Column gamma squared 2nd Column tilde IGAMMA left-parenthesis 0.01 comma 0.01 right-parenthesis 3rd Row 1st Column beta squared 2nd Column tilde IGAMMA left-parenthesis 0.01 comma 0.01 right-parenthesis EndLayout

The following statements use PROC SMC to define the preceding ARSV model and then use the PMCMC method to estimate the three parameters for the simulated data set:

proc smc data=mycas.asv_train seed=1234;
   id time = t;
   var y;
   statevar x;
   prior phi~uniform(0,1);
   prior gamma_sq beta_sq~igamma(0.01,0.01);
   parm phi=0.6 gamma_sq=0.9 beta_sq=1.5;
   initstate x~normal(0,2);
   state x~normal(x.l1*phi, sqrt(gamma_sq));
   model y~normal(0, sqrt(beta_sq)*exp(x/2));
   auxmodel y~normal(0, sqrt(beta_sq)*exp(phi*x.l1/2));
   learn nparticle=256 algorithm=apf method=PMCMC(nsample=25000
      nchain=8 nbi=5000 thin=4 seed=1
      outpost=mycas.out samset samsum
      sampler=rwm(ntu=250)
      statistics=all diagnostics=all);
   score outmodel=mycas.asvmodel;
run;

For the three parameters, phi is represented by phi, gamma squared is represented by gamma_sq, and beta squared is represented by beta_sq. A state variable, x, an a dependent (observation) variable, y, are also specified according to the model specification.

The model information and parameter learning results are stored in the mycas.asvmodel. As for the PMCMC, the likelihood is estimated by the particle filter and the prior density is specified in the PRIOR statement.

The summary tables of the model information are shown in Figure 1.

Figure 1: Model Information Summary

The SMC Procedure

State Space Model Information
Number of Parameters3
Number of State Variables1
Number of Dependent Variables1
Number of Independent Variables0
Seed Value1234

Number of Observations275
Number of Missing Observations0

Initial Parameters Information
ParameterInitial
Value
Lower
Bound
Upper
Bound
phi0.6000001.00000
gamma_sq0.900000Infty
beta_sq1.500000Infty


The summary tables of the posterior samples are shown in Figure 2.

Figure 2: Posterior Summary

MCMC Sampler Settings
MCMC Sampling MethodRWM
Random Seed1
Transformed SamplingFalse
Number of Chains8
Number of Sampling Iterations25000
Number of Burn-in Iterations5000
Thinning Interval4
Number of Tuning Iterations per Tuning Stage250
Number of Tuning Stages24
Target Metropolis Acceptance Rate0.234
Initial RWM Proposal Scale2.38
Tuning Weight0.75
Acceptance Tolerance0.075

The SMC Procedure

Posterior Summaries
ParameterNMeanStandard
Deviation
Percentiles
2.5%25%50%75%97.5%
phi500000.83960.07870.65530.78320.85050.89680.9584
gamma_sq500000.32440.16320.09430.20210.29730.44040.6874
beta_sq500000.86430.27250.49390.72050.81200.97341.4939

Posterior Intervals
Parameter95% Equal-Tail Interval95% HPD Interval
phi0.65530.95840.69790.9785
gamma_sq0.09430.68740.06430.6186
beta_sq0.49391.49390.42931.3778


The correlation and covariance matrices of the parameter samples that are generated by the PMCMC method are shown in Figure 3.

Figure 3: Correlation and Covariance Matrices

Posterior Covariance Matrix
Parameterphigamma_sqbeta_sq
phi0.006192-0.009850.004117
gamma_sq-0.009850.026624-0.00822
beta_sq0.004117-0.008220.074281

Posterior Correlation Matrix
Parameterphigamma_sqbeta_sq
phi1.0000-0.76720.1920
gamma_sq-0.76721.0000-0.1849
beta_sq0.1920-0.18491.0000


The autocorrelation statistics, Heidelberger-Welch diagnostics, effective sample size (ESS) diagnostics, and Monte Carlo Standard Error (MCSE) diagnostics for each parameter are shown in Figure 4.

Figure 4: Other Bayesian Analysis Tables

The SMC Procedure

MCMC Diagnostic Summaries
ParameterMCSEMCSE/SDESSAutocorrelation
Time
ESS/N
phi*0.001540.01962607.919.17240.0522
gamma_sq*0.005170.0317998.050.10100.0200
beta_sq*0.009400.0345841.059.45250.0168
 *Autocorrelation Remains

Autocorrelation Diagnostics
ParameterLag 1Lag 5Lag 10Lag 50
phi0.73870.31280.16040.0146
gamma_sq0.76330.41150.28260.1005
beta_sq0.76110.40610.26660.1165

Heidelberger-Welch Diagnostics
ParameterStationarity TestHalf-Width Test
Chains
Tested
Tests
Passed
Largest
Iterations
Discarded
Chains
Tested
Tests
Passed
phi88187588
gamma_sq87250077
beta_sq88125088


The following statements draw the histogram of the posterior samples of phi, which is shown in Figure 5:

proc sgplot data=mycas.out;
   histogram phi;
   refline 0.9 /axis=x lineattrs=(thickness=5 color=red) label="True Value";
run;

Figure 5: Histogram of Posterior Samples of phi

Histogram of Posterior Samples of


The following statements draw the histogram of the posterior samples of gamma_sq, which is shown in Figure 6:

proc sgplot data=mycas.out;
   histogram gamma_sq;
   refline 0.16 /axis=x lineattrs=(thickness=5 color=red) label="True Value";
run;

Figure 6: Histogram of Posterior Samples of gamma_sq

Histogram of Posterior Samples of


The following statements draw the histogram of the posterior samples of beta_sq, which is shown in Figure 7:

proc sgplot data=mycas.out;
   histogram beta_sq;
   refline 1 /axis=x lineattrs=(thickness=5 color=red) label="True Value";
run;

Figure 7: Histogram of Posterior Samples of beta_sq

Histogram of Posterior Samples of


You can apply the model information and parameter estimates from the data table mycas.asvmodel to the original data set by specifying the INMODEL= option in the SCORE statement. The posterior mean acquired by the PMCMC method are used as the parameters in the smoothing and forecasting process. The following statements generate the smoothing and forecasting estimates:

proc smc data=mycas.asv_train seed=1 nthreads=32;
   smooth nparticle=10240 parm=median alg=sir method=fixedlag(25)
      out(pct=2.5,97.5)=mycas.asvsm;
   forecast nparticle=10240 parm=median alg=sir lead=5
      out(pct=2.5,97.5)=mycas.asvfc;
   score inmodel=mycas.asvmodel;
run;

The following statements sort the summary table of the smoothing estimates of the state variable, x, in the CAS session and create a relevant data table, smoothRes, in the Work library to record the smoothing estimates and actual values:

data asvsm; set mycas.asvsm(where=(VariableID=1 and TimeID>=1)); run;
proc sort data=asvsm; by timeId; run;

data smoothRes;
   set asvsm (keep=timeId Q2 P_1 P_2);
   set asv_train (keep=x t);
run;

The following statements draw the plot of the smoothing median estimates and the actual values of x. The output is shown in Figure 8, where the shadow band indicates the range between the 2.5th and 97.5th percentiles of the smoothing estimates.

proc sgplot data=smoothRes;
   band x=TimeID upper=P_2 lower=P_1 / transparency=.3 legendlabel='95% CI';
   series x=TimeId y=Q2 /legendlabel='Smoothing Median'
      markers markerattrs=(color=blue size=5 symbol=triangle)
      lineattrs=(color=blue pattern=solid);
   series x=TimeId y=x /legendlabel='Actual Value'
      markers markerattrs=(color=red size=5 symbol=circlefilled)
      lineattrs=(color=red pattern=shortdash);
   yaxis label='x, Smoothing';
   xaxis label='Time';
run;

Figure 8: Smoothing Estimates vs. Actual Values, x

Smoothing Estimates vs. Actual Values, x


The following statements sort the summary table of the forecasting estimates of x in the CAS session and create a relevant data table, forecastRes_x, in the Work library to record the forecasting estimates and actual values in the forecasting stage:

data asvfc_x; set mycas.asvfc(where=(VariableID=1)); run;
proc sort data=asvfc_x; by _t; run;

data forecastRes_x;
   set asvfc_x (keep=Q2 P_1 P_2 _t);
   set asv_test (keep=x t);
run;

The following statements draw the plot of the forecasting median estimates and the actual values of x. The output is shown in Figure 9, where the shadow band indicates the range between the 2.5th and 97.5th percentiles of the forecasting estimates.

proc sgplot data=forecastRes_x;
   band x=t upper=P_2 lower=P_1 /transparency=.3 legendlabel='95% CI';
   series x=t y=Q2 /legendlabel='Forecasting Median'
      markers markerattrs=(color=blue size=5 symbol=triangle)
      lineattrs=(color=blue pattern=solid);
   scatter x=t y=x /legendlabel='Actual Value'
      markerattrs=(color=red size=5 symbol=circlefilled);
   xaxis integer label='Time';
   yaxis label='x, Forecasting';
run;

Figure 9: Forecasting Estimates vs. Actual Values, x

Forecasting Estimates vs. Actual Values, x


The following statements sort the summary table of the forecasting estimates of the dependent variable, y, in the CAS session and create a relevant data table, forecastRes_y, in the Work library to record the forecasting estimates and actual values in the forecasting stage:

data asvfc_y; set mycas.asvfc(where=(VariableID=2)); run;
proc sort data=asvfc_y; by _t; run;

data forecastRes_y;
   set asvfc_y (keep=Q2 P_1 P_2 _t);
   set asv_test (keep=y t);
run;

The following statements draw the plot of the forecasting median estimates and the actual values of y. The output is shown in Figure 10, where the shadow band indicates the range between the 2.5th and 97.5th percentiles of the forecasting estimates.

proc sgplot data=forecastRes_y;
   band x=t upper=P_2 lower=P_1 /transparency=.3 legendlabel='95% CI';
   series x=t y=Q2 /legendlabel='Forecasting Median'
      markers markerattrs=(color=blue size=5 symbol=triangle)
      lineattrs=(color=blue pattern=solid);
   scatter x=t y=y /legendlabel='Actual Value'
      markerattrs=(color=red size=5 symbol=circlefilled);
   xaxis integer label='Time';
   yaxis label='y, Forecasting';
run;

Figure 10: Forecasting Estimates vs. Actual Values, y

Forecasting Estimates vs. Actual Values, y


Last updated: September 15, 2022