Skip to content

Commit aba66bf

Browse files
committed
corrected ARMA(p,q) to ARIMA(p,d,q)
1 parent ed4ea42 commit aba66bf

12 files changed

+7064
-5474
lines changed

Q1App2/app.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ ui <- shinyUI(fluidPage(
199199
tags$a(href='https://github.com/scibrokes/owner', target='_blank',
200200
tags$img(height = '20px', alt='hot', #align='right',
201201
src='https://raw.githubusercontent.com/englianhu/binary.com-interview-question/master/www/hot.jpg'))),
202-
p('02. ', HTML("<a href='https://raw.githubusercontent.com/englianhu/binary.com-interview-question/master/reference/Successful%20Algorithmic%20Trading.pdf'>A Step-by-Step Guide to Quantitative Strategies - SUCCESSFUL ALGORITHMIC TRADING</a>"),
202+
p('02. ', HTML("<a href='https://systematicinvestor.wordpress.com/shiny/'>Shiny App in Systematic Investor Toolbox (SIT)</a>"),
203+
tags$a(href='https://github.com/scibrokes/owner', target='_blank',
204+
tags$img(height = '20px', alt='hot', #align='right',
205+
src='https://raw.githubusercontent.com/englianhu/binary.com-interview-question/master/www/hot.jpg'))),
206+
p('03. ', HTML("<a href='https://raw.githubusercontent.com/englianhu/binary.com-interview-question/master/reference/Successful%20Algorithmic%20Trading.pdf'>A Step-by-Step Guide to Quantitative Strategies - SUCCESSFUL ALGORITHMIC TRADING</a>"),
203207
tags$a(href='https://github.com/scibrokes/owner', target='_blank',
204208
tags$img(height = '20px', alt='hot', #align='right',
205209
src='https://raw.githubusercontent.com/englianhu/binary.com-interview-question/master/www/hot.jpg')))),

README.html

+539-297
Large diffs are not rendered by default.

README.md

+132-132
Large diffs are not rendered by default.

binary-Q1BET.Rmd

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ In order to test the timeline of daily highest and lowest price, here I created
5555

5656
*binary.com Interview Question I - Tick-Data-HiLo For Daily Trading (Blooper)* descript that the VaR figure required in order to place orders. [What is the difference between Sharpe ratio and value at risk?](https://www.quora.com/What-is-the-difference-between-Sharpe-ratio-and-value-at-risk) states the difference between VaR and shape ratio where the shape ratio will be use in the future research.
5757

58+
[ARIMA+GARCH Trading Strategy on the S&P500 Stock Market Index Using R](https://www.quantstart.com/articles/ARIMA-GARCH-Trading-Strategy-on-the-SP500-Stock-Market-Index-Using-R) compares the ROI of buy and hold and application of ARIMA + GARCH model.
59+
60+
[Systematic Investor Blog : Trading Strategies](https://systematicinvestor.wordpress.com/category/trading-strategies/) introduce various trading strategies.
61+
5862
## Intro Reference
5963

6064
*Currency Hedging Strategies Using Dynamic Multivariate GARCH* compares DCC, BEKK, CCC and VARMA-AGARCH models to examine the conditional volatilities among the spot and two distint futures maturities, namely near-month and next-to-near-month contracts. The estimated conditionl covariances matrices from these models were used to calculate the optimal portfolios weights and optimal hedge ratios. The empirical results in the paper reveal that there are not big differences either the near-month or next-to-near-month contract is used for hedge spot position on currencies. They also reveal that hedging ratios are lower for near-month contract when the USD/EUR and USD/JPY exchange rates are anlyzed. This result is explained in terms of the higher correlation between spot prices and the next-to-near-month future prices than that with near-month contract and additionally because of the lower volatility of the long maturity futures. Finally across all currencies and error densities, the CCC and VARMA-AGARCH models provide similar results in terms of hedging ratios, portfolio variance reduction and hedging effectiveness. Some difference might appear when the DCC and BEKK models are used. Below is the table summary of the paper.

binary-Q1FiGJRGARCH.Rmd

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "<img src='www/binary-logo-resize.jpg' width='240'>"
3-
subtitle: "[binary.com](https://github.com/englianhu/binary.com-interview-question) 面试试题 I - GARCH模型中的`ARMA(p,d,q)`参数最优化"
3+
subtitle: "[binary.com](https://github.com/englianhu/binary.com-interview-question) 面试试题 I - GARCH模型中的`ARIMA(p,d,q)`参数最优化"
44
author: "[<span style='color:blue'>®γσ, Lian Hu</span>](https://englianhu.github.io/) <img src='www/ENG.jpg' width='24'> <img src='www/RYO.jpg' width='24'>®"
55
date: "`r lubridate::today('Asia/Tokyo')`"
66
output:
@@ -724,6 +724,15 @@ acc %>%
724724

725725
结果新的Fi-gjrGARCH函数pred2胜出,比旧的gjrGARCH的pred1更优秀,证明`p`值、`d`值与`q`值仨都可以优化。目前正在编写着[Q1App2](https://beta.rstudioconnect.com/content/3138/)自动交易应用。“商场如战场”,除了模式最优化以外,程序运作上分秒必争... `microbenchmark`测试效率,之前编写了个[DataCollection](https://beta.rstudioconnect.com/content/3153/)应用采集实时数据以方便之后的高频率交易自动化建模^[不过数据量多就会当机,得继续提升才行。]。欲知更多详情,请参阅[Real Time FXCM](https://github.com/scibrokes/real-time-fxcm)
726726

727+
[Generalised Autoregressive Conditional Heteroskedasticity GARCH(p, q) Models for Time Series Analysis](https://www.quantstart.com/articles/Generalised-Autoregressive-Conditional-Heteroskedasticity-GARCH-p-q-Models-for-Time-Series-Analysis):
728+
729+
- [Discrete White Noise and Random Walks](https://www.quantstart.com/articles/White-Noise-and-Random-Walks-in-Time-Series-Analysis)
730+
- [AR(p)](https://www.quantstart.com/articles/Autoregressive-Moving-Average-ARMA-p-q-Models-for-Time-Series-Analysis-Part-1)
731+
- [MA(q)](https://www.quantstart.com/articles/Autoregressive-Moving-Average-ARMA-p-q-Models-for-Time-Series-Analysis-Part-2)
732+
- [ARMA(p,q)](https://www.quantstart.com/articles/Autoregressive-Moving-Average-ARMA-p-q-Models-for-Time-Series-Analysis-Part-3)
733+
- [ARIMA(p,d,q)](https://www.quantstart.com/articles/Autoregressive-Integrated-Moving-Average-ARIMA-p-d-q-Models-for-Time-Series-Analysis)
734+
735+
727736
**投注模式**
728737

729738
![](www/fractional-kelly.jpg)

binary-Q1FiGJRGARCH.html

+1,372-50
Large diffs are not rendered by default.

binary-Q1Multi-GARCH.Rmd

+35-37
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ rm(pkgs)
3131

3232
# Introduction
3333

34-
From previous papers, I tried to apply few models for FOREX price forecasting and eventually got to know <span style='color:red'>Fractional Intergrated GJR-GARCH</span> is the best fit model as we can refer to [GARCH模型中的ARMA(p,d,q)参数最优化](http://rpubs.com/englianhu/binary-Q1FiGJRGARCH). Today I am zooming into the multivariate GARCH models.
34+
From previous papers, I tried to apply few models for FOREX price forecasting and eventually got to know <span style='color:red'>Fractional Intergrated GJR-GARCH</span> is the best fit model as we can refer to [GARCH模型中的ARIMA(p,d,q)参数最优化](http://rpubs.com/englianhu/binary-Q1FiGJRGARCH). **The standalone ARFIMAX model and methods** in the [A short introduction to the rugarch package](http://www.unstarched.net/r-examples/rugarch/a-short-introduction-to-the-rugarch-package/) describe the `autoarfima()` function where we can easily get the optimal MA and AR figure. [](https://stats.stackexchange.com/questions/176550/fitting-arima-garch-model-using-rugarch-package?answertab=votes#tab-top).
35+
36+
Today I am zooming into the multivariate GARCH models.
3537

3638
# Data
3739

3840
## Read Data
3941

40-
Similar with *GARCH模型中的ARMA(p,d,q)参数最优化*, I use the dataset from [Binary-Q1 (Extention)](http://rpubs.com/englianhu/binary-Q1E).
42+
Similar with *GARCH模型中的ARIMA(p,d,q)参数最优化*, I use the dataset from [Binary-Q1 (Extention)](http://rpubs.com/englianhu/binary-Q1E).
4143

4244
```{r read-data, warning=FALSE}
4345
cr_code <- c('AUDUSD=X', 'EURUSD=X', 'GBPUSD=X', 'CHF=X', 'CAD=X',
@@ -482,6 +484,11 @@ Above models set `VAR=TRUE` and `robust=FALSE`, now I based on above best fitted
482484
483485
```
484486

487+
### Hi-Lo
488+
489+
### Hi-Lo-Cl
490+
491+
### Cl
485492

486493
## GO-GARCH
487494

@@ -512,44 +519,34 @@ names(attributes(attributes(attributes(fit)$mfit$ufit)[[1]][[3]])$fit)
512519

513520
## BEKK
514521

515-
[[问答] 向各位朋友求助关于MGARCH-BEKK模型的问题!万分感谢!](http://bbs.pinggu.org/forum.php?mod=viewthread&tid=2263348)
522+
[[问答] 向各位朋友求助关于MGARCH-BEKK模型的问题!万分感谢!](http://bbs.pinggu.org/forum.php?mod=viewthread&tid=2263348) discuss about the BEKK model.
516523

517-
# Model Comparison
524+
```{r}
525+
if (!((method == "Nelder-Mead") || (method == "BFGS") ||
526+
(method == "CG") || (method == "L-BFGS-B") || (method ==
527+
"SANN"))) {
528+
stop("'", method, "' method is not available")
529+
}
530+
```
531+
532+
## mGJR (Bivariate GJR (bivariate asymmetric GARCH model))
518533

519-
```{r tidy-data1}
520-
##数据1
521-
fx1 <- llply(names(cr_code), function(x) {
522-
fls <- list.files(paste0('data/fx/', x), pattern = '^pred1')
523-
dfm <- ldply(fls, function(y) {
524-
readRDS(paste0('data/fx/', x, '/', y))
525-
}) %>% data.frame(Cat = 'pred1', .) %>% tbl_df
526-
names(dfm)[4:5] <- c('Price', 'Price.T1')
527-
dfm
528-
})
529-
names(fx1) <- names(cr_code)
530-
531-
##数据2
532-
fx2 <- llply(names(cr_code), function(x) {
533-
fls <- list.files(paste0('data/fx/', x), pattern = '^pred2')
534-
dfm <- ldply(fls, function(y) {
535-
readRDS(paste0('data/fx/', x, '/', y))
536-
}) %>% data.frame(Cat = 'pred2', .) %>% tbl_df
537-
names(dfm)[4:5] <- c('Price', 'Price.T1')
538-
dfm
539-
})
540-
names(fx2) <- names(cr_code)
541-
542-
## Merge and tidy dataset.
543-
fx1 %<>% ldply %>% tbl_df
544-
fx2 %<>% ldply %>% tbl_df
545-
fx <- suppressAll(
546-
bind_rows(fx1, fx2) %>% arrange(Date) %>%
547-
mutate(.id = factor(.id), Cat = factor(Cat), Price.T1 = lag(Price.T1, 56)) %>%
548-
dplyr::filter(Date >= ymd('2013-01-01') & Date <= ymd('2017-08-30')))
549-
550-
rm(fx1, fx2)
534+
`mGJR(eps1, eps2, order = c(1, 1, 1), params = NULL, fixed = NULL, method = "BFGS")`
535+
536+
```{r, eval=FALSE}
537+
if (!((method == "Nelder-Mead") || (method == "BFGS") ||
538+
(method == "CG") || (method == "L-BFGS-B") || (method ==
539+
"SANN"))) {
540+
stop("'", method, "' method is not available")
541+
}
551542
```
552543

544+
The `mGJR()` function in `mgarchBEKK` use diversified optim function.
545+
546+
547+
548+
# Model Comparison
549+
553550
# Conclusion
554551

555552

@@ -604,7 +601,7 @@ rm(sys1, sys2)
604601

605602
01. [Betting Strategy and Model Validation - Part II](https://englianhu.github.io/2017/10/Betting_Strategy_and_Model_Validation_-_Part_02/)
606603
02. [**binary.com Job Application - Quantitative Analyst** *sample question*](https://github.com/englianhu/binary.com-interview-question)
607-
03. [GARCH模型中的`ARMA(p,d,q)`参数最优化](http://rpubs.com/englianhu/binary-Q1FiGJRGARCH)
604+
03. [GARCH模型中的`ARIMA(p,d,q)`参数最优化](http://rpubs.com/englianhu/binary-Q1FiGJRGARCH)
608605
04. [The `rmgarch` Models - Background and Properties](https://raw.githubusercontent.com/englianhu/binary.com-interview-question/master/reference/The%20rmgarch%20Models%20-%20Background%20and%20Properties.pdf)
609606
05. [Financial Econometrics Practical - Univariate Volatility Modelling](https://raw.githubusercontent.com/englianhu/binary.com-interview-question/master/reference/Financial%20Econometrics%20Practical%20-%20Univariate%20Volatility%20Modelling.pdf)
610607
06. [The GARCH-DCC Model and 2-Stage DCC(MVT) Estimation](http://www.unstarched.net/2013/01/03/the-garch-dcc-model-and-2-stage-dccmvt-estimation/)
@@ -635,6 +632,7 @@ rm(sys1, sys2)
635632
18. [Forecasting the Daily Dynamic Hedge Ratios by GARCH Models - Evidence from the Agricultural Futures Markets](https://github.com/englianhu/binary.com-interview-question/blob/master/reference/Forecasting%20the%20Daily%20Dynamic%20Hedge%20Ratios%20by%20GARCH%20Models%20-%20Evidence%20from%20the%20Agricultural%20Futures%20Markets.pdf)
636633
19. [Currency Hedging Strategies Using Dynamic Multivariate GARCH](https://github.com/englianhu/binary.com-interview-question/blob/master/reference/Currency%20Hedging%20Strategies%20Using%20Dynamic%20Multivariate%20GARCH.pdf)
637634
20. [Multivariate DCC-GARCH Model](https://github.com/englianhu/binary.com-interview-question/blob/master/reference/Multivariate%20DCC-GARCH%20Model.pdf)
635+
21. [Introduction to the `rugarch` Package](https://github.com/englianhu/binary.com-interview-question/blob/master/reference/Introduction%20to%20the%20rugarch%20Package.pdf)
638636

639637
---
640638

binary-Q1Multi-GARCH.html

+20-9
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)