Video: Introduction to Dynamic Conditional Correlation (DCC)

Hi Tino,

for the optimizer, i am using scipy optimize with default method SLSQP (as constraints and bounds are present). I checked the documentation but it seems to lack a stat. significance output.

do you mean a machine learning algorithm for (ML)? Regarding the MCMC, how would you use this approach to test the significance?

As mentioned in my other post today, i am not seeking to do something very elaborated, perhaps a simple comparison of the forecasted var-covar matrix of t-1 with the realised var-covar matrix of t-0 is enough…

Regarding the intraday topic,

I have kept 5min return as they are but removed the seasonality via ‘first differencing’ . Hence, my returns represent a smooth picture throughout the day and all days of the series for that matter. I dont see the particular issue, of using this return series for forecast one step ahead (i.e.5min ahead). I have seen a similar approach in this paper: Intraday portfolio risk management using VaR and CVaR:A CGARCH-EVT-Copula approach - ScienceDirect

So to sum up, the way i see it is taking the traditional approach of daily rets for a daily VaR to a smaller problemset in which I use 5min returns for a 5min ahead VaR

Please let me know what you mean by ‘your mileage may vary’ in this context.

I wish you a good start into the new week!.

Kind regards,

Toni

No worries Toni! Hope these would be of help!

Thanks for sharing your approach. So by skimming through the code I see that after estimating univariate GARCH models, you’ve used 1-step ahead conditional volatility forecast to derive the forecasted Dt matrix containing diagonal conditional volatility entries. Next, you used the estimated DCC parameters alongside with the most recent Qt matrix to calculate forecasted Rt and lastly apply Ht = Dt x Rt x Dt to obtain the DCC covariance forecast. I will try to implement these calculations as well, hopefully later this week.

Have a nice evening!

Sincerely,

Nikola

Good evening,

yes thats what i have done. I have done this a while ago. Coming back to it now, i do spot a mistake in the way Dt is calculated. My methodology works for T0 but not the rest of the dcc process.

The easiest way to explain it is with this file originally sourced from NEDL: Loading Google Sheets

See tab DCC_estimation: I calculated Dt as in cell P17. although i need to incorporate the previous dt value aswell as is the case for p19 onwards.

I need to get back to the code and incorporate a forloop that calculates dt for the dcc garch process too and then use the last dt for the forecast appropriatly.

If i find a solution I will share it with you again.

Hello Tino!

Thank you for your reply and kind words! Understood, so indeed after estimating the parameters, a sample covariance estimate can be used to kick things off and then apply step-by-step updating from 0 to T periods, using DCC GARCH estimated parameters. As Toni kindly suggested here the dcceq function can be re-used with some changes.

Regarding library/package use, indeed I fully agree. In my work, I am relying on using just a few packages as there when building proprietary libraries (using only standard, basic modules) and in that way you can reduce a lot of dependencies and as you pointed out - have more clarity on what is going on, especially if you re-visit your script after some time! Indeed python makes implementing formulas and equations pretty straightforward. I was just happy to confirm my the calculation from another angle, that’s all (perhaps a habit from work :slight_smile: ).

Regarding univariate CDF transforms - well here I was puzzled as well. I did inspect the univariate GARCH fit, for these 5 securities, and all of the model parameters had t-values (well) above 2 and resulting low p-values (<5%). I’ve used a constant mean parameter for all univariate fits. Indeed, GARCH is an volatility updating formulae with its own limits, could be that the outlier returns are indeed not helping. Perhaps some trimming of returns before fitting, but I would like to avoid that route.
Interestingly, once I’ve ran your univariate CDF transform script, where a square root is taken from conditional volatility (below):

def garch_t_to_unif(rets, res):
    nu = res.params['nu']
    #mu = res.params['mu']
    #est_r = rets - mu
    #print(sum(res.resid - est_r))
    h = res.conditional_volatility
    std_res = res.resid / np.sqrt(h)
    udata = stats.t.cdf(std_res, nu)
    return udata

things looked better (at least for the first few tickers):

Could be that the model spec would need altering. In any case I would need to check my code implementation again and look for potential issues or bugs.
Anyhow thank you for your time and answers provided. Looking forward to some new videos on the topic!

Have a nice evening! Cheers!

N.

Ha, no, ML = Maximum Likelihood.
With MCMC you can see the full distribution around the parameter, rather than a single point value.

So think of 10000 data points around the value 8. Some might go down to 6.8 and some might go up to 8.7. From there you can take confidence intervals by seeing there the 250th lowest value or highest 9750th, take the average for a point value, or anything else you want.

I find it super useful as you can see the whole distribution around a value, very visual, and if it starts to flip between +ve and -ve, you know the value is meaningless.

The downside is that MCMC is slow, and takes a bit of knowledge etc to get going.

Have a look at this chart for apple below:

The bars at the bottom are the volume. As you can see it’s very very flat during the day (no many trades happening), and then all the action happens at the close. A lot of the action would happen at the auction pre-open too.

What I am saying is that GARCH effects at those intervals might be spurious, but you might find some datasets which work.
Might be worth looking at VWAP (Volume Weighted Average Price) which does exactly what it says on the tin. Uses volume as a weighting parameter.

Anyway, it’s cool to experiment with these things.
Would love to see the output

Things do indeed look better, BUT, I had a good dive into this and:

res.std_resid is the same as:

(rets[‘Returns’] - res.params[‘mu’]) / res.conditional_volatility

So we don’t need to sqrt the last parameter.
This is rather confusing and quite embarrassing. :roll_eyes:

Thanks for spotting that!

Wonder why your results look better like that?

Will update my code on github accordingly.

So we might as well use res.std_resid directly.
I think the reason I did it manually was to show the steps for everyone else and my future self. Way easier to debug later on.

1 Like

Hey Tino!

Thanks for coming back on this one! No worries, I was also checking this in the arch package source code, and this indeed is the case, as you mentioned. About the univariate, post-GARCH fit CDF transforms no idea to be honest. Would need to think on that a bit and have a look at the dataset, but it has been a rather busy week on my end.

See below the data I’ve used:

I can also post the dataset I’ve used but these can be easily downloaded from yfinance. I’ve calculated the log-returns (cleared any NA’s) and then performed the univariate GARCH fitting. Will try to spend some time on the multivariate GARCH forecasting topic and have a good understanding of that one!

For the last 6 months, using a small trading account, I was experimenting with several option trading setups (focusing on US equity markets), mostly based on technical analysis, used for entry/exit signals and I did find that some setups work more often than not. These are not setups for day trading, as most of the signals are obtained from the daily chart, using 2-D, 3-D, Weekly and Monthly charts for analysis. As implied volatility is mean-reverting I wanted to introduce a quantitative aspect to these setups, which would provide an additional edge. I know that the GARCH produces estimates of historical volatility (compared to forward looking IV figures), but I was curious whether with univariate/multivariate GARCH setups one can have an idea where volatility would go and bake that in with an appropriate options trading setup. Or just use as another indicator to complement for example 52 W IV rank and IV percentile values. Let me know if this sparks your interest!

Have a nice weekend!

N.

Sounds like you have a lot on your plate!
But good for you for putting your money where you mouth it!

I have actually never tried to put GARCH and options trading together. That world can be quite wild to be fair! :slight_smile:

Hi Tino,

thank you making me aware of these volume considerations and further ideas on how to account intraday patterns in the model design. i went back to the drawing board and implemented a 1hVWAP that resets every day. Unfortunatly, i was only able to get my hands on hourly volume data so i averaged those out over 5min periods. It seems to do a good enough job as you can see in the plots below with AAPL as an example. My old approach of first differencing (2.) was alright but this (3.) is even better! Combining both methods, i.e. VWAP and deseasonalizing does not improve the picture…

Regarding an MCMC approach for dcc parameters a+b, would this approach include having historical data of a and b values from past simulation in order to have a mean and sigma estimate for the MCMC.
The same with respect to data needed for an ML approach?

Thank you as always for your time and effort!

Kind regards,

Toni

Hi Nikola,

i finally had time to go back and look at my forecasting code. After reasessing, i am know confident the way i forecasted the HT(var-covar) matrix is in fact correct.

The crucial step that confused me was the forecasted val of DT, the matrix of standard deviations. Something started to stick to my head that this requires some multivariate inputs from the dcc modelling process.

As however, DT calculations stem purely from the univariate Garch model,(DT of t-1 and immediate disturbances) it is safe to use the Garch forecast method i applied. With forecasted variances from the garch function (in my code: fcastvariance_list), it is as simple as casting them into a diagonal matrix and taking the square root.

Thanks a lot again for the sources you posted regarding univariate and multivariate signficicance testing. finally got around to reading it more thoroughly. I will see what i can implement in the scope of my project!

Good to see you overcame your issues with the univariate fits! Nice to see you have skin in the game with some options trades. My thought on this is that this trade would only pan out if your modelled volatility is more accurate and superior than that of the optionsdealer and opportunities arise from that. If not volatiltiy it is already priced into the option.

Kind regards,

Toni

Maybe a small followup question on that.

When using rets based of vwap prices, the returns in the beginning of the day have a rather high magnitude and end up mostly flat for the rest of the day due to the limited volume. Therefore, a kind of seasonality remains in the data.

As I interpret this, this is good if you want to forecast in the short term. i.e. 5, 15 or 30min.

However, this is worse for an end of day VaR as end of day volatility is overstated in the model if it is calculated off of a ‘higher volatility’ at the beginning of the day.

What do you think about this?

I am also curious where the idea of using vwap for deseasonalizing comes from? I havent come across this approach in the literature yet. It is usually using square returns, log square returns, fast fourier transforms or periodic garch although the latter is computationally heavy.

hmm…thinking about it, yes, it would behave exactly like that. Ok, back to the drawing board.

As i mentioned before, when I used intraday data, it was to calculate a single value per day, rather than using each period in the model.

It comes a silly idea I had, so you won’t find any literature on it :wink:

Hi Tino,

no worries at all. It was still worth a try. It did remove the intraday seasonality of the whole day except the open and close so it did around 90% of the work. :wink:

I have incorporated the methodology used by Xu& Taylor 1997 which uses a seasonality term determined by averaging out squared returns for every period of the day over the sample space. Then the original returns of the series are divided by the square root of the seasonality term. This does a good job. See outcome below.

Using this for the DCC model leads to expected outcomes of parameters a and b. i.e. a around 0.01 as expected in a quiet market. The vwap approach led ot a value of 0.05 which is more common in a time of market stress.

The seasonality term approach can also be extended and further dissected to weekday as volatility varies throughout the week. i.e. you would have a ‘first 5min monday average’ and so on…

Kind regards,

Toni

Hello Tino,

I am struggling to beautify or make the DCC Conditional Plot beautiful.

Is there a way to bold or increase the size of the legends?

I am also trying to only focus on certain variables instead of all the different combinations of correlation in the graph. For example, instead of having consumer-REITs, I just want everything to be consistently TSLA related. Is there also a way to code this out?

Thank you,

Rotty Cotty
![Screen Shot 2022-03-09 at 10.54.54 PM|690x334](upload://6Ot


7ujKJn2MIKjXfiWOwMTvBZHV.png)

Hi mate,

For the legend I am not sure. Internet is your friend.
For the second part, I think you want to create a corr_name_list where name_b is TSLA, so just put an if filter and it will exclude everything else.
Something as simple as

for name_b in stock_names[:i] if name_b == 'TSLA' :
     corr_name_list.append(name_a + "-" + name_b)

Hope that helps

Hi Tino,

I already posted here in November about my bachelor’s thesis, for which I am using DCC GARCH. Now further questions have arisen during the application.

With regard to the stationarity problems you mentioned, my stationarity test showed that both time series (European stock market, cryptocurrencies) are stationary. I also checked the ARCH effect, which is present in both time series.

Until now, I estimated the parameters with Excel, but I recently switched to RStudio. The output of R shows that some P-values of the T-statistics are not significant. Therefore I tried the following distributions for the GARCH model: the normal distibution, the skew-normal distribution, the student-t and the skew of student-t. The student-t gave me the most significant results.
results: DCC GARCH.xlsx
Hence the questions:

  1. does it matter which distribution I use?
  2. does it cause problems if values are not significant?
  3. can the DCC model be used despite non-significant parameters?
  4. what significance tests are normally carried out for DCC GARCH or are no tests carried out here as these are estimated values?

For the GARCH coefficients, I also performed a likelihood ratio (LR) test for both time series.
LR = 2*(likelihood(GARCH)-likelihood(ARCH))
Both values were above the critical value for a chi-square. However, if I understood correctly, the test does not do anything because even if H0 is not discarded GARCH is used to use DCC.

I hope you can help me further.

I wish you a good start into the week.
Sebastian

Hi mate,

I am very surprised crypto is both stationary and has ARCH effects. If you look at the z-score of returns there should be some pretty big numbers. But anyway, to answer your questions:

  1. Distribution makes a massive difference. It allows the errors term to be far more flexible, and especially in finance, stuff is never normal.
  2. It not a ‘problem’, but it means the model isn’t suitable really. so that’s the problem I guess
  3. Same as above. it;s telling you it’s not the right model
  4. I would just look at the parameter a and b and their significance, but also look how well it does at forecasting. That’s all you got!

The last test I am not sure what you are trying to look for.

With these types of models I would say experience comes into play. You should be able to spot right away if something is off. there is 0 chance this stuff is going to work with crypto. These gaussian distributions simply cannot accommodate a 30% drop in a day.

Hope this helps,

Tino

1 Like

Hi Tino,

some time has passed since my first post regarding the use of DCC for my bachelor thesis. In this post I want to share my findings.

First of all, I want to thank you immensely for your accounts on YouTube and especially the construction of this forum! Your answers regarding my but also other members’ questions has contributed greatly to my understanding of time series analysis and especially the use of DCC. This helped me to pass my bachelor thesis with a very good grade.

Now, however, a brief introduction to the content I studied. The focus was, as already described, a correlation analysis between cryptocurrencies and the European stock market. The European stock market was represented here by the STOXX Europe 600 indices. Once as a whole market together and differentiated into the sectors Food&Beverage, Financial Services, Health Care, Real Estate and Technology. Cryptocurrencies were mapped by the S&P Cryptocurrency Broad Digital Market Index.

The investigation was carried out using 3 GARCH models, respectively mapping the observation periods A from 01/01/2018 to 12/31/2021, B from 01/01/2018 to 12/31/2019 and C from 01/01/2020 to 12/31/2021 for each European index on cryptocurrencies. The focus of the study was mainly on the characteristics of cryptocurrencies as a safe haven, hedge and diversifier (definitions were taken from Baur and Lucey (2010)).

The results have shown that in none of the observation periods safe haven properties are exhibited and especially in period C an increased downside risk exists. For period B, strong diversifier properties can be identified. The values of the sector real easted to cryptos were particularly good. In period C, the property clearly deteriorated. It is also found that the dynamic correlation before the pandemic shows very strong regular fluctuations. However, during the pandemic, the outliers occur less intensely and no longer regularly. Moreover, it can be deduced that different sectors behave differently in times of crisis and therefore need to be considered individually.

Many greetings and thanks again!

Sebastian

1 Like

Hey Sebastian,

very happy to hear you got a great grade in your Bachelors. That is a great achievement that you should be proud of.

Thanks for sharing your findings. They insightful and I like the approach of splitting the analysis into different time periods.

Have a good one
Tino