Original link:tecdat.cn/?p=19118

Original source:Tuo End number according to the tribe public number

 

This analysis will be used to develop strategic guidelines for managing customer and supplier relationships. Assumptions:

  • Your company has facilities for the production and distribution of polyglutaric acid, a compound used in a number of industries.
  • Inputs to the manufacturing and distribution process include various petroleum products and natural gas. Price fluctuations can be very volatile.
  • Working capital management has been a challenge, with recent movements in exchange rates having a significant impact on funds.
  • Your CFO hedges price risk using futures and over-the-counter (OTC) instruments.

The Board is concerned that the Company has missed earnings expectations for the fifth consecutive quarter. Shareholders are not happy. The culprit appears to be fluctuations in the cost of goods sold.

The sample

  1. What are the key business questions you should ask about energy pricing models?
  2. What method can you use to manage volatility?

Here are some ideas. Key business issues may be:

  • Which input prices and exchange rates are more volatile than others? When?
  • Are price movements related?
  • How volatile are they during periods of market stress?
  • Are there hedging instruments that we can deploy or use to mitigate pricing risk?

Management of volatility

  • Establish an input monitoring system to understand which inputs affect which costs of running manufacturing and distribution processes.
  • Monitor price movements and characteristics and measure the severity of the impact on key revenue components by process.
  • Built-in price is not affordable for early warning indicators.

 

In this article, we will

  • Use volatility clustering
  • Fitting AR-GARCH model
  • Simulation of volatility from AR-GARCH model
  • Measure risk

The ARCH model

We have studied volatility clustering. ARCH model is a method to model this problem.

These models are particularly useful for financial time series, which show periods of large yield changes and interludes of relatively smooth price changes.

The AR + ARCH model σ (t) 2 = z (t) 2 can be specified starting with the z (t) standard normal variable and the initial standard volatility. We then adjust these variables with the variance ε (t) = (sigma2) 1/2 z (t) ε squared. Then we first calculate t = 1 for each date… N,

Using this conditional error term, we calculate autoregressions

Now we’re ready to compute our new variance term.

N < -10500 z < -rnorm (n) ## Sample standard normal distribution variable SIG2 < -z ^2 ## Create volatility sequence Omega < -1 ## variance mu < -0.1 ## average return omega/(1-alpha) sqrt(omega/(1-alpha))Copy the code
# # 2.222222 [1]Copy the code
# # 1.490712 [1]Copy the code
For (t in 2:n) ## lag the start of the second date {y[t] < -mu + phi*(y[t-1-mu) + e[t] ## Yield sig2[t+1] < -omega + alpha * e[t ^2 ## I'm going to make a new sigma squared.Copy the code

The results are not instructive.

 

We can see that

  1. Large isolated peak in conditional standard deviation
  2. Also shown in the ARCH diagram

 

estimated

We have several methods to estimate the parameters of AR-ARCH process. First, let’s load some data.

1 < -nA. omit(EUR_USD, GBP_USD, OIL_Brent) P < -nA. omit(diff(log(P)) * 100)Copy the code

Then, we plot the data autocorrelation.

 

## ## box-ljung test ## ## data: Brent. R ## x-squared = 32.272, df = 14, p-value = 0.003664Copy the code

Pure randomness test, p value is less than 5%, the sequence is non-white noise

fitting

Our first task was the Arma-Garch model.

  1. Specify the ordinarysGarchModel.
  2. GarchOrder = c (1, 1)Denotes the one-stage lag we use for the square and variance of residuals:
  3. useArmaOrder = c (1, 0)Specify a long-term average return model
  4. meanAs included in the equation above.
  5. In accordance with thenormNormal distribution. We will also compare the fit with the student T-distribution using the Akechi information criterion (AIC).
  6. Use to fit the data into the modelugarchfit.
ugarchspec(variance.model = list(model = "sGARCH", 
    garchOrder = c(1, 1)), mean.model = list(armaOrder = c(1, 
    0), include.mean = TRUE), distribution.model = "norm")
Copy the code

Let’s look at the conditional quantile in this model, also known as VaR, set to 99%.

Plot (fit, which = 2)Copy the code

 

 

Now, let’s generate a drawing panel.

## QQ plot of data - showing kurtosis of normalized residues - does not support normal assumption ## AcF of normalized residues ## square acF of standard residuesCopy the code

 

example

Let’s redo the GARCH estimation and now use the Student T distribution.

Ar.garch. Spec < -ugarchspec (variance. Model = list(model = "sGARCH", garchOrder = c(1, 1)) 1)), mean.model = list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "std")Copy the code

The results of

  1. The ACF of absolute observations indicates a large volatility cluster.
  2. Ar-arch estimates have bounded normalized residuals (residuals/standard errors), thus greatly reducing these errors.
  3. It appears that the T-distribution AR-GARCH explains most of the trend in crude oil volatility.

Which model? The information in the model was measured using the Akaike Information Criterion (AIC).

AIC = 4.2471 using the normal distribution model. Using the student T-distribution model, AIC = 4.2062. Student t distribution model is better.

Here are some common results we can derive from fitting models:

##         mu        ar1      omega     alpha1      beta1      shape 
## 0.04018002 0.01727725 0.01087721 0.03816097 0.96074399 7.03778415
Copy the code

The coefficients include:

  • muIt’s the long-term average return on crude oil.
  • ar1It’s the effect of earnings one day later on earnings today.
  • omegaIt’s the long run variance.
  • alpha1Lagging square variance on today’s returns.
  • beta1The effect of lagging square residuals on today’s yield.
  • shapeIs the degree of freedom of student t distribution.

Let’s plot the volatility over time.

##         mu        ar1      omega     alpha1      beta1      shape 
## 0.04018002 0.01727725 0.01087721 0.03816097 0.96074399 7.03778415
Copy the code

 

 

Next, we plot and test the residuals:

 

 

hist(z.hat)
Copy the code

 

mean(z.hat)
Copy the code
# # [1] - 0.0181139Copy the code
var(z.hat)
Copy the code
##          [,1]
## [1,] 1.000682
Copy the code
# # # # [1] 0.3207327 attr (, "method") # # [1] ""Copy the code
kurtosis(z.hat)
Copy the code
# # # # 2.048561 [1] attr (, "method") # # [1] "excess"Copy the code
## ## Shapiro-Wilk Normality Test ## ## data: As.numeric (z.hat) ## W = 0.98439, p-value < 2.2E-16Copy the code
## ## Jarque-Bera Normality Test ## ## data: As. Numeric (Z.hash) ## JB = 780.73, p-value < 2.2E-16 ## alternative hypothesis: greaterCopy the code

What do we see?

  • Left.
  • Thick tail.
  • Both standard tests reject the null hypothesis that the sequence is normally distributed.

simulation

  1. Specify ar-GARCH using the parameters in the FIT results.
  2. Generate 2000 simulated paths.

GARCHspec
Copy the code
## ## *---------------------------------* ## * GARCH Model Spec * ## *---------------------------------* ## ## Conditional Variance Dynamics ## ------------------------------------ ## GARCH Model : SGARCH (1,1) ## Variance Targeting: FALSE ## ## Conditional Mean Dynamics ## ------------------------------------ ## Mean Model : ARFIMA(1,0,0) ## Include Mean: TRUE ## garch-in-mean: FALSE ## ## Conditional Distribution ## ------------------------------------ ## Distribution : std ## Includes Skew : FALSE ## Includes Shape : TRUE ## Includes Lambda : FALSECopy the code
# create two paths with length 2000 (GARCHspec, n.start = 2000, n.start = 50, m.start = 2)Copy the code

Extraction volatility

 head(vol)
Copy the code
## T+2 2.893878 4.927087 ## T+3 2.848404 4.849797 ## T+4 2.802098 4.819258 ## T+5 2.880778 4.768916 ## T+6 2.826746 4.675612Copy the code

 

 

 

 

-series $seriesSim head(X)Copy the code
# # [1], [2] 0.1509418 1.4608335 # # # # [1] [2] 1.2644849 2.1509425 # 1.0397785 4.0248510 # # # [3] - [4] of 4.4369130 ## [6,] 0.4798977 2.7440751 ## [6,] 0.4798977 2.7440751Copy the code

The sample

Does the simulated sequence fit the facts?

X1 <- X[, 1]
acf(X1)
acf(abs(X1))
qqnorm(X1)
qqline(X1, col = 2)
shapiro.test(X1)
Copy the code

 

This is the result

## 
##  Shapiro-Wilk normality test
## 
## data:  X1
## W = 0.97164, p-value < 2.2e-16
Copy the code

Shapiro-wilk test – Null hypothesis: Normal distribution. If the p value is small enough, the null hypothesis is rejected. – QQ map must be used for verification.

Multivariate GARCH

From univariate GARCH to multivariate GARCH

  • Dynamic condition dependence.
  • It has volatility over time.
  • The correlation between asset returns also changes over time.

Why is that? – What if we have a portfolio (e.g., accounts receivable, which may be exposed to changes in exchange rates and crude oil prices)? – We need to understand the combined volatility and dependence of these three factors, as they affect the overall volatility of accounts receivable. We will use these conditional variances to model option prices for instruments that manage currency and commodity risk.

 

dcc.garch11.spec
Copy the code
## ## *------------------------------* ## * DCC GARCH Spec * ## *------------------------------* ## Model : DCC(1,1) ## Estimation: 2-step ## Distribution: MVT ## no.parameters: 21 ## no.series: 3Copy the code

Now let’s fit it

Now let’s get some results:

## ## *---------------------------------* ## * DCC GARCH Fit * ## *---------------------------------* ## ## Distribution : MVT ## Model: DCC(1,1) ## # Parameters: 21 ## [VAR GARCH DCC UncQ] : [0+15+3+3] ## # 4057 ## log-likelihood: -12820.82 ## av. log-likelihood: 3.16 # # # # Optimal Parameters # # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # # Estimate Std. Error t value Pr (> | | t) # # [EUR.USD].mu 0.006996 0.007195 0.97238 0.330861 ## [EUR.USD].omega 0.000540 0.000288 1.87540 0.060738 ## [EUR.USD].alpha1 0.036643 0.001590 23.04978 0.000000 ## [EUR.USD].beta1 0.962357 0.000397 2426.49736 0.000000 ## [EUR.USD].shape 9.344066 1.192132 7.83811 0.000000 ## [GBP.usd].mu 0.006424 0.006386 1.00594 0.314447 ## [GBp.usd].omega USD. Alpha1 0.038292 0.002217 17.27004 0.000000 ## [gbP.usd].beta1 0.958481 Shape 10.481272 1.534457 6.83061 0.000000 ## [oil.brent].mu 0.040479 0.026696 [oil.brent]. Omega 0.010779 0.004342 2.48228 0.013055 ## [oil.brent]. Alpha1 0.037986 0.001941 19.57467 0.000000 ## [oil.brent].beta1 0.960927 0.000454 2118.80489 0.000000 ## [oil.brent].shape 7.040287 0.729837 9.64639 0.000000 ## [Joint] dCCB1 0.987616 0.004386 225.15202 0.000000 ## [Joint] dCCB1 0.987616 0.004386 225.15202 0.000000 # # 9.732509 0.652707 14.91100 0.000000 [to be] mshape # # # # # # Information Criteria -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # # # # Akaike 6.3307 ## Bayes 6.3633 ## Shibata 6.3306 ## hannan-quinn 6.3423 ## ## ## Elapsed time: 11.89964Copy the code
  • The joint conditional covariance parameter is significantly different from zero.

Now, using all the information from the fit, we make a prediction. We use to model hedging instruments or portfolios VaR or ES, so let’s first plot sigma over time.

The sample

Given conditional volatility and correlation, look at the three risk factors for VaR and ES.

Here are some of the results. First, calculate, then plot.

## 6.137269958-3.677130793-0.004439644 3.391312753 5.896992710 ## 6.137269958-3.677130793-0.004439644 3.391312753 5.896992710Copy the code
## -1.3393119939-0.8235076255-0.0003271163 0.7659725631 1.2465945013Copy the code
## -1.520666396-0.980794376 0.006889539 0.904772045 1.493169076Copy the code

We see:

  1. More weight on the negative part of the distribution.
  2. The exchange rate is about the same.
  3. If you use Brent for customers and distribution, you may suffer losses of more than 600% in about 1% of the time.

Let’s use new volatility models and distributions to adjust to fit asymmetries and thick tails.

Here we try to use a new GARCH model: GJR stands for a wave model proposed by Glosten, Jagannathan and Runkle (1993) :

Sigma 2 t = 2 t – 1 + + alpha omega sigma beta 1 epsilon 2 t – 1 + beta 2 epsilon it 2 t – 1-1

 

Fit the model.

## ## *---------------------------------* ## * GARCH Model Fit * ## *---------------------------------* ## ## Conditional Variance Dynamics # # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # # GARCH Model: gjrGARCH # # scheme (1, 1) Model: ARFIMA (1, 1) # # Distribution: nig ## ## Optimal Parameters ## ------------------------------------ ## Estimate Std. Error t value Pr(>|t|) ## mu 0.040275 0.027883 1.4445 0.148608 # # ar1 e+00 0.996072 0.001900 5.2430 0.000000 # # e+02 ma1-0.989719-0.000005 1.8786 e+05 0.000000 # # # # e+00 omega 0.006346 0.003427 1.8517 0.064071 1 0.009670 0.003841 2.5178 e+00 # # 0.011808 Beta1 0.968206 0.001237 7.8286e+02 + 0.000000 ## gamma1 0.042773 0.007183 5.9547 +00 ## skew -0.120184 0.032059 ## shape 2.362890 0.351494 6.7224e+00 0.000000 ## ## Robust Standard Errors: # # Estimate Std. Error t value (Pr > | | t) # # mu - 0.040275 0.996072 0.002107 0.030871 1.3046 0.192023 # # ar1 e+00 4.7283 0.000000 # # e+02 ma1-0.989719-0.000005-1.8363 e+05 0.000000 0.061086 # # # # 0.006346 0.003388 1.8729 e+00 omega Alpha1 0.009670 0.004565 2.1184e+00 + 0.034143 ## + gamma1 0.042773 0.008503 ## shape 2.362890 0.405910 5.8212e+00 0.000000 ## ##  LogLikelihood : 8508.439 # # # # # # Information Criteria -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - 4.1989 # # # # # # Akaike Bayes theorem 4.2129 # # Shibata 4.1989 ## Hannan-Quinn 4.2038 ## ## Weighted Ljung-box Test on Standardized Residuals ## -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # # statistic value # # p - Lag [1] 1.856 0.1730 # # Lag (2 * (p + q) + (p + q) 1] [5], 2.196 0.9090 # # Lag [4 * (p + q) + (p + q) 1] [9] 2.659 0.9354 # # # # D.O.F = 2 H0: No serial correlation ## ## Weighted Ljung-Box Test on Standardized Squared Residuals ## -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # # statistic value # # p - Lag [1] 0.5109 0.474739 # # Lag (2 * (p + q) + (p + q) 1] [5] of 9.3918 0.013167 # # Lag [4 * (p + q) + (p + q) 1] [9] 13.2753 0.009209 # # # # # # D.O.F = 2 Weighted ARCH LM Tests # # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # # Statistic Shape Scale P - Value # # ARCH Lag [3] 10.26 0.500 2.000 0.001360 # # ARCH Lag[5] 10.41 1.440 1.667 0.005216 ## ARCH Lag[7] 11.06 2.315 1.543 0.010371 ## ## Nyblom Stability Test ## -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # # to be Statistic: 2.5309 # # Individual Statistics: ## mu 0.91051 ## ar1 0.07050 ## ma1 0.06321 ## omega 0.70755 ## alpha 0.22126 ## gamma1 0.17746 ## Skew 0.25115 ## shape 0.16545 ## ## discontinuous Critical Values (10% 5% 1%) ## Joint Statistic: ## Individual Statistic: 0.35 0.47 0.75 # # # # Sign Bias Test # # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - value prob sig # # # # t - Sign by 1.1836 0.23663 ## Negative Sign Bias 0.7703 0.44119 ## Positive Sign Bias 1.8249 0.06809 * ## Joint Effect 9.8802 0.01961 ** ##  ## ## Adjusted Pearson Goodness-of-Fit Test: # # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # # group statistic value (g - 1) # # p - 1 20 30 46.32 0.02183 27.42 0.09520 # # 2 # # 3 Elapsed time: Elapsed time: Elapsed time: Elapsed time: Elapsed time: Elapsed time: Elapsed time: Elapsed time: Elapsed timeCopy the code

We can interpret the results using the tailplot() function.

##          p  quantile     sfall
## [1,] 0.900  3.478474  5.110320
## [2,] 0.950  4.509217  6.293461
## [3,] 0.975  5.636221  7.587096
## [4,] 0.990  7.289163  9.484430
## [5,] 0.999 12.415553 15.368772
Copy the code

Quantile gives us our value at risk (VaR) and expected loss (ES)

You can see the tail diagram.

 

  • The results show that the tail is thicker after ar-GARCH treatment.
  • We can go back to the markets and risk section to see the average excess value and the confidence intervals for VaR and ES.
  • For accounts receivable, mitigation strategies may be through reinsurance andTotal return swapProvide excess risk hedging.
  • Credit risk analysis for customers is critical: frequent customer updates will help identify problems with certain solutions early.

Most welcome insight

1. Machine learning to identify changing stock market conditions — the application of hidden Markov model (HMM)

2. Garch-dcc model and DCC (MVT) modeling estimation in R language

3.R language implementation Copula algorithm modeling dependency case analysis report

4.R language COPULAS and VaR analysis of financial time series data

5.R language multivariate COPULA GARCH model time series prediction

6. Use R language to realize neural network to predict stock cases

7. Realization of R language volatility prediction: ARCH model and HAR-RV model

8.R language how to do Markov switching model

9. Matlab uses Copula simulation to optimize market risks