A repository of finance calculating, for research of modeling joint dynamic correlation of 5 factors model. The name of JDFactor is just Joint Dynamic Factors.
It's now a pure R project, but with some early Python codes for the old version. By the definition of command line API, it's easy to build the result using GNU Make by one line of code:
make all
For the result with the robust test, run:
make all_verbose
But there's no original data here, for the copyright reason. And there're some Chinese comments in the code, for the early days of my quick commenting. I'm sorry that now I don't have time to translate it into English for more people.
Frankly speaking, the project is considering the nonlinear joint dynamic correlation of the classic 5 factors investment model. By modeling it, we can get more returns in the historical investing test. And the codes are doing the following work:
- An ARMA model for every factor, and finding the best ARMA order by investigating orders from 1 to 10.
- ARMA-GARCH model fit for every factor, using the ARMA order selected.
- GARCH-Copula model with the norm, t copula, combining DCC and ADCC copula.
- Rolling fit for investment performance test. Refit in expanding window every 30 days, and filter model by new data. Determine weights of factors by optimizing effective functions, and calculating portfolio return.
- Robost test by different risk tolerant coefficients and different data frequencies.
Of course more complicated works in detail. Maybe some are not efficient codes early days, but I'll be happy if I can help others facing the same problems.
Some mathematical Backgrounds for ARMA-GARCH-Copula are here, for more clarity. But it's very annoying that GitHub can't render some LaTeX codes when they are in line. So forgive me if some line breaks seem not needed.
- ARMA model
- NGARCH model using here
For a collection of random variables
A function
For
So the copula function and the joint distribution can be separated. The form of the copula function may differ. For normal copula:
And for t copula:
For example, a normal copula at time
$$ F\left(r_{1, t}, \ldots, r_{5, t} \mid \mathcal{F}{t-1} ; \mathbf{P}\right)=\Phi{\mathbf{P}}\left(\Phi^{-1}\left(u_{1, t}\right), \ldots, \Phi^{-1}\left(u_{5, t}\right)\right) $$
And
$$u_{i, t}=F_{i}\left(r_{i, t} \mid \mathcal{F}{t-1} ;\boldsymbol{\theta{m, i}}\right) $$
And correlation matrix
$$ \mathbf{z}{\mathbf{t}}^{*}=\left(\Phi^{-1}\left(u{1, t}\right), \ldots, \Phi^{-1}\left(u_{5, t}\right)\right)^{\prime} $$
called by copula shocks.
For a collection of variables
$$ \mathbf{R}{\mathbf{t}}=\left(R{1, t}, \ldots, R_{n, t}\right), {t=1,2, \ldots, T} $$
with
$$ \boldsymbol{\mu_{t}}=E\left[\mathbf{y}{\mathrm{t}} \mid \mathcal{F}{t-1}\right] $$
and positive definite conditional variance-covariance matrix:
$$\boldsymbol{\Sigma_{t}}=E\left[\left(\mathbf{r}{\mathrm{t}}-\boldsymbol{\mu{t}}\right)\left(\mathbf{r}{\mathrm{t}}-\boldsymbol{\mu{t}}\right)^{\prime} \mid \mathcal{F}{t-1}\right]=E\left[\boldsymbol{\epsilon{t}} \boldsymbol{\epsilon_{t}}^{\prime} \mid \mathcal{F}_{t-1}\right] $$
An MGARCH model:
with
$$ \mathbf{n}{\mathbf{t}} \sim I I D\left(\mathbf{0}, \mathbf{I}{\mathbf{n}}\right) $$
$$ \boldsymbol{\Sigma_{t}}=\mathbf{V}{\mathbf{t}}^{\frac{1}{2}} \mathbf{P}{\mathbf{t}} \mathbf{V}_{\mathbf{t}}^{\frac{1}{2}} $$
Now define a standard shock,
$$ \mathbf{Q}{\mathrm{t}}=(1-a-b) \bar{\mathbf{Q}}+a \mathbf{z}{\mathrm{t}-1} \mathbf{z}{\mathrm{t}-1}^{\prime}+b \mathbf{Q}{\mathrm{t}-1} $$
Rewrite the process as:
For ADCC, add an asymmetrical parameter:
$$ \mathbf{Q}{\mathbf{t}}=\left(\mathbf{\bar{Q}}-a \mathbf{\bar{Q}}-b \mathbf{\bar{Q}}-g \mathbf{\bar{Q}}^{-}\right)+a \mathbf{z}{\mathbf{t}-1} \mathbf{z}{\mathbf{t}-1}^{\prime}+b \mathbf{Q}{\mathbf{t}-1}+g \mathbf{z}{\mathbf{t}-1}^{-} \mathbf{z}{\mathbf{t}-\mathbf{1}}^{-\prime} $$
with
$$ z^{-}{i,t-1} = min(z{i,t-1}, 0) $$
and
$$ \mathbf{\bar{Q}^{-}} = E[\mathbf{z^{-}{t-1}}\mathbf{z^{-\prime}{t-1}}] $$