Skip to content

Commit 5537acc

Browse files
committed
update
1 parent d43916f commit 5537acc

8 files changed

+126
-163
lines changed

.RDataTmp

30.7 MB
Binary file not shown.

.Rprofile

+36-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## Emacs please make this -*- R -*-
2+
## empty Rprofile.site for R on Debian
3+
##
4+
## Copyright (C) 2008 - 2018 Dirk Eddelbuettel and GPL'ed
5+
##
6+
## see help(Startup) for documentation on ~/.Rprofile and Rprofile.site
7+
8+
# ## Example of .Rprofile
9+
# options(width=65, digits=5)
10+
# options(show.signif.stars=FALSE)
11+
# setHook(packageEvent('grDevices', 'onLoad'),
12+
# function(...) grDevices::ps.options(horizontal=FALSE))
13+
# set.seed(1234)
14+
# .First <- function() cat("\n Welcome to R!\n\n")
15+
116
## ======================== Micro Editor ===================================
217

318
## https://www.tecmint.com/micro-linuxtext-editor-with-syntax-highlighting/
@@ -9,26 +24,26 @@
924
.pth <- .libPaths(c('/usr/lib/R/library', '/usr/lib/R/site-library'))
1025
.libPaths(.pth)
1126

12-
#dir(paste0(R.home(component = "home"), '/etc'))
27+
#dir(paste0(R.home(component = 'home'), '/etc'))
1328
## https://www.jumpingrivers.com/blog/customising-your-rprofile/
1429

1530
## -------------------------------------------------------------------------
1631

1732
## https://stackoverflow.com/a/13736073/3806250
18-
# candidates <- c( Sys.getenv("R_PROFILE"),
19-
# file.path(Sys.getenv("R_HOME"), "etc", "Rprofile.site"),
20-
# Sys.getenv("R_PROFILE_USER"),
21-
#file.path(getwd(), ".Rprofile") )
33+
# candidates <- c(Sys.getenv('R_PROFILE'),
34+
# file.path(Sys.getenv('R_HOME'), 'etc', 'Rprofile.site'),
35+
# Sys.getenv('R_PROFILE_USER'),
36+
#file.path(getwd(), '.Rprofile') )
2237
#
2338
# Filter(file.exists, candidates)
2439

2540
## https://github.com/rstudio/reticulate/issues/496#issuecomment-601446838
2641
#Sys.setenv(RETICULATE_PYTHON = '/usr/bin/python3')
27-
#Sys.setenv(RETICULATE_PYTHON = '~/anaconda3/bin/python')
42+
#Sys.setenv(RETICULATE_PYTHON = '/home/englianhu/anaconda3/bin/python')
2843
## https://d.cosx.org/d/422269-r-410/11
29-
Sys.setenv(RETICULATE_PYTHON = '~/anaconda3/bin/python3',
44+
Sys.setenv(RETICULATE_PYTHON = '/home/englianhu/anaconda3/bin/python3',
3045
'_R_USE_PIPEBIND_' = 'true')
31-
46+
#Sys.setenv(RETICULATE_PYTHON = '/home/englianhu/anaconda3/envs/py38/bin/python')
3247
## -------------------------------------------------------------------------
3348

3449
## We set the cloud mirror, which is 'network-close' to everybody, as default
@@ -87,25 +102,30 @@ if(!suppressAll(require('lubridate'))) {
87102
}
88103

89104
pkgs <- c('MASS', 'devtools', 'lubridate', 'tidyverse', 'rprofile', 'prompt',
90-
'colorout', 'Rdym', 'startup')
105+
'prettycode', 'colorout', 'Rdym', 'startup', 'conflicted')
91106
suppressAll(lib(pkgs))
92107
rm(pkgs)
93108

109+
conflicted::conflict_prefer('print', 'base', quiet=TRUE)
110+
94111
## -------------------------------------------------------------------------
95112

96113
## https://stackoverflow.com/a/17486231/3806250
97114
#.First()
98115
.First <- function() {
99116
Rdym::RdymEnable()
100-
BBmisc::suppressAll(startup::install())
101-
BBmisc::suppressAll(startup::startup())
117+
BBmisc::suppressAll(startup::install(path = '/home/englianhu'))
118+
BBmisc::suppressAll(startup::startup(all = TRUE))
102119
}
103120

104121
## ======================== Start Up =====================================
105122

106123
## https://www.jumpingrivers.com/blog/customising-your-rprofile/
107124
if (interactive() && suppressAll(requireNamespace('rprofile'))) {
108125

126+
# A powerline clone, that also shows the system load average and the current working directory.
127+
prompt::set_prompt(prompt::new_prompt_powerline())
128+
109129
# Only useful if you use Makefiles
110130
rprofile::create_make_functions()
111131

@@ -114,6 +134,7 @@ if (interactive() && suppressAll(requireNamespace('rprofile'))) {
114134

115135
# Not RStudio console
116136
if (rprofile::is_terminal()) {
137+
# https://github.com/csgillespie/rprofile/blob/master/R/set-terminal.R
117138
rprofile::set_terminal()
118139
} else {
119140
rprofile::set_rstudio()
@@ -123,7 +144,7 @@ if (interactive() && suppressAll(requireNamespace('rprofile'))) {
123144
suppressAll(attach(.env))
124145
# Display wifi and no of R sessions
125146
# Linux only
126-
rprofile::set_startup_info()
147+
suppressWarnings(rprofile::set_startup_info())
127148
}
128149

129150
## -------------------------------------------------------------------------
@@ -132,10 +153,11 @@ if (interactive() && suppressAll(requireNamespace('rprofile'))) {
132153
setHook('rstudio.sessionInit', function(newSession) {
133154
active_rproj = rprofile::get_active_rproj()
134155
if (!is.null(active_rproj)) {
135-
message(glue::glue("{crayon::yellow('R-project:')} {active_rproj}"))
156+
base::message(glue::glue("{crayon::yellow('R-project:')} {active_rproj}"))
136157
}
137158
}, action = 'append')
138159

139160
#BBmisc::suppressAll(.First())
140161
tryCatch(suppressWarnings(startup::startup(all = TRUE)), error=function(ex)
141-
message('.Rprofile error: ', conditionMessage(ex)))
162+
base::message('.Rprofile error: ', base::conditionMessage(ex)))
163+

Compare few time series models.Rmd Compare-few-time-series-models.Rmd

+59-89
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "[Deriv.com](https://github.com/englianhu/binary.com-interview-question) - Interday High Frequency Trading Models Comparison <span style='color:#4E79A7'>**Review**"
3-
subtitle: "Compare few time series models with Performance"
4-
author: "[®γσ, Lian Hu](https://englianhu.github.io/) <img src='www/quantitative trader 1.jpg' width='13'> <img src='www/RYU.jpg' width='15'> <img src='www/ENG.jpg' width='24'> ® <img src='www/xueba1.jpg' width='14'>"
2+
title: "[Deriv.com](https://github.com/englianhu/binary.com-interview-question) - Intraday High Frequency Trading Models Comparison <span style='color:#4E79A7'>"
3+
subtitle: "Introduce [`tidyverts`](https://github.com/tidyverts) for HFT"
4+
author: "[®γσ, Lian Hu ξηg](https://englianhu.github.io/) <img src='www/quantitative trader 1.jpg' width='13'> <img src='www/xueba4.jpg' width='11'>®"
55
date: "`r lubridate::today('Asia/Tokyo')`"
66
output:
77
html_document:
@@ -20,81 +20,11 @@ output:
2020
<span style='color:green'>**Theme Song**</span>
2121
<br>
2222

23-
<audio src="music/Mika - Elle me dit (happy song to be millionaire).mp3" controls></audio>
23+
<audio controls loop autoplay src="music/F4 - Can't Help Falling In Love With You (chorus).mp3" controls></audio>
2424
<br>
2525

2626
------
2727

28-
<span style='color:blue'>**F**</span><span style='color:white'>**R**</span><span style='color:red'>**A**</span> : <span style='color:white'>Elle me dit</span>
29-
30-
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>她对我说</span>
31-
32-
<span style='color:blue'>**E**</span><span style='color:red'>**N**</span><span style='color:blue'>**G**</span> : <span style='color:white'>She told me</span>
33-
34-
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>彼女は私に言う</span>
35-
36-
------
37-
38-
<span style='color:blue'>**F**</span><span style='color:white'>**R**</span><span style='color:red'>**A**</span> : <span style='color:white'>écris une chanson contente</span>
39-
40-
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>写一首欢快的歌</span>
41-
42-
<span style='color:blue'>**E**</span><span style='color:red'>**N**</span><span style='color:blue'>**G**</span> : <span style='color:white'>Write a happy song</span>
43-
44-
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>幸せな歌を書く</span>
45-
46-
------
47-
48-
<span style='color:blue'>**F**</span><span style='color:white'>**R**</span><span style='color:red'>**A**</span> : <span style='color:white'>Pas une chanson déprimante</span>
49-
50-
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>而不是悲伤的歌</span>
51-
52-
<span style='color:blue'>**E**</span><span style='color:red'>**N**</span><span style='color:blue'>**G**</span> : <span style='color:white'>Not a depressing song</span>
53-
54-
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>気のめいるような歌ではない</span>
55-
56-
------
57-
58-
<span style='color:blue'>**F**</span><span style='color:white'>**R**</span><span style='color:red'>**A**</span> : <span style='color:white'>Une chanson que tout le monde aime</span>
59-
60-
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>一首让所有人都喜欢的歌</span>
61-
62-
<span style='color:blue'>**E**</span><span style='color:red'>**N**</span><span style='color:blue'>**G**</span> : <span style='color:white'>A song that everyone loves</span>
63-
64-
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>みんなが大好きな曲</span>
65-
66-
------
67-
68-
<span style='color:blue'>**F**</span><span style='color:white'>**R**</span><span style='color:red'>**A**</span> : <span style='color:white'>Elle me dit</span>
69-
70-
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>她对我说</span>
71-
72-
<span style='color:blue'>**E**</span><span style='color:red'>**N**</span><span style='color:blue'>**G**</span> : <span style='color:white'>She told me</span>
73-
74-
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>彼女は私に言う</span>
75-
76-
------
77-
78-
<span style='color:blue'>**F**</span><span style='color:white'>**R**</span><span style='color:red'>**A**</span> : <span style='color:azure'>Tu deviendras milliardaire</span>
79-
80-
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>你将成为亿万富翁</span>
81-
82-
<span style='color:blue'>**E**</span><span style='color:red'>**N**</span><span style='color:blue'>**G**</span> : <span style='color:white'>You will become a millionaire</span>
83-
84-
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>あなたは億万長者になります</span>
85-
86-
------
87-
88-
<span style='color:blue'>**F**</span><span style='color:white'>**R**</span><span style='color:red'>**A**</span> : <span style='color:white'>Tu auras de quoi être fier</span>
89-
90-
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>你将为此感到骄傲</span>
91-
92-
<span style='color:blue'>**E**</span><span style='color:red'>**N**</span><span style='color:blue'>**G**</span> : <span style='color:white'>You will be proud</span>
93-
94-
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>あなたは誇りに思うでしょう</span>
95-
96-
------
97-
9828
# Setting
9929

10030
## SCSS Setup
@@ -390,28 +320,59 @@ frb <- 1
390320
i <- 1
391321
```
392322

323+
### Model 1
324+
393325
```{r, error=TRUE, results='asis'}
394326
train1A <- ts1_ddsmp |>
395-
{\(.) filter(., date < timeID[i]) |>
396-
tail(vrb)}()
327+
filter(as_date(index) <= timeID[i]) |>
328+
tail(vrb)
397329
398330
fit1A <- train1A |>
399331
model(
400332
ets = ETS(close ~ error('M') + trend('N') + season('N')),
401-
ets_bc = ETS(box_cox(close, 0.3) ~ error('A') + trend('N') + season('N')),
402-
arima = ARIMA(close),
333+
ets_bc = ETS(box_cox(close, 0.3) ~ error('A') + trend('N') + season('N')),
334+
arima = ARIMA(close ~ 0 + pdq(0, 1, 0) + PDQ(0, 1, 0)),
335+
theta = THETA(close),
336+
theta_mul = THETA(close ~ season(method = 'multiplicative')),
403337
rw = RW(close),
404338
rw_df = RW(close ~ drift()),
405339
naive = NAIVE(close),
406-
snaive = SNAIVE(close))
340+
snaive = SNAIVE(close),
341+
prophet = prophet(close ~ season(period = 4, order = 2,
342+
type = 'multiplicative')))
343+
344+
fit1A |>
345+
accuracy()
346+
```
347+
348+
```{r, error=TRUE, results='asis'}
349+
train_test <- ts1_ddsmp |>
350+
filter(index >= train1A$index[1])
351+
352+
test <- train_test |>
353+
filter(index > train1A$index[length(train1A$index)])
354+
355+
train_test |>
356+
features(hr_1m, feat_acf)
407357
408358
fc1A <- fit1A |>
409-
{\(.) forecast(.$close, h = frb)}()
359+
forecast(h = frb)
410360
411361
fc1A |>
412-
accuracy(ts1_ddsmp)
362+
accuracy(train_test)
363+
```
364+
365+
```{r, error=TRUE, results='asis'}
366+
fit1A |>
367+
forecast(h = 365) %>%
368+
autoplot(train_test[1:1565,], level = NULL) +
369+
labs(y = 'USD/JPY',
370+
title = "Forecasts price") +
371+
guides(colour = guide_legend(title = 'Forecast'))
413372
```
414373

374+
### Model 2
375+
415376
```{r, error=TRUE, results='asis'}
416377
train1B <- ddsmp |>
417378
{\(.) filter(., date < timeID[i]) |>
@@ -421,20 +382,24 @@ train1B <- ddsmp |>
421382
fit1B <- train1B |>
422383
model(
423384
ets = ETS(close ~ error('M') + trend('N') + season('N')),
424-
ets_bc = ETS(box_cox(close, 0.3) ~ error('A') + trend('N') + season('N')),
425-
arima = ARIMA(close),
385+
ets_bc = ETS(box_cox(close, 0.3) ~ error('A') + trend('N') + season('N')),
386+
arima = ARIMA(close ~ 0 + pdq(0, 1, 0) + PDQ(0, 1, 0)),
387+
theta = THETA(close),
388+
theta_mul = THETA(close ~ season(method = 'multiplicative')),
426389
rw = RW(close),
427390
rw_df = RW(close ~ drift()),
428391
naive = NAIVE(close),
429392
snaive = SNAIVE(close))
430393
431394
fc1B <- fit1B |>
432-
{\(.) forecast(.$close, h = frb)}()
395+
forecast(h = frb)
433396
434397
fc1B |>
435398
accuracy(ts1_ddsmp)
436399
```
437400

401+
### Model 3
402+
438403
```{r, error=TRUE, results='asis'}
439404
train1C <- ts2_ddsmp |>
440405
{\(.) filter(., date < timeID[i]) |>
@@ -444,19 +409,22 @@ fit1C <- train1C |>
444409
model(
445410
ets = ETS(close ~ error('M') + trend('N') + season('N')),
446411
ets_bc = ETS(box_cox(close, 0.3) ~ error('A') + trend('N') + season('N')),
447-
arima = ARIMA(close),
412+
arima = ARIMA(close ~ 0 + pdq(0, 1, 0) + PDQ(0, 1, 0)),
413+
theta = THETA(close),
448414
rw = RW(close),
449415
rw_df = RW(close ~ drift()),
450416
naive = NAIVE(close),
451417
snaive = SNAIVE(close))
452418
453419
fc1C <- fit1C |>
454-
{\(.) forecast(.$close, h = frb)}()
420+
forecast(h = frb)
455421
456422
fc1C |>
457423
accuracy(ts2_ddsmp)
458424
```
459425

426+
### Model 4
427+
460428
```{r, error=TRUE, results='asis'}
461429
train1D <- ts2_ddsmp |>
462430
{\(.) filter(., date < timeID[i]) |>
@@ -467,14 +435,15 @@ fit1D <- train1D |>
467435
model(
468436
ets = ETS(close ~ error('M') + trend('N') + season('N')),
469437
ets_bc = ETS(box_cox(close, 0.3) ~ error('A') + trend('N') + season('N')),
470-
arima = ARIMA(close),
438+
arima = ARIMA(close ~ 0 + pdq(0, 1, 0) + PDQ(0, 1, 0)),
439+
theta = THETA(close),
471440
rw = RW(close),
472441
rw_df = RW(close ~ drift()),
473442
naive = NAIVE(close),
474443
snaive = SNAIVE(close))
475444
476445
fc1D <- fit1D |>
477-
{\(.) forecast(.$close, h = frb)}()
446+
forecast(h = frb)
478447
479448
fc1D |>
480449
accuracy(ts2_ddsmp)
@@ -518,7 +487,8 @@ fc <- fit |>
518487
forecast(h = frb)
519488
520489
## accuracy
521-
fc |> fabletools::accuracy(train_test)
490+
fc |>
491+
accuracy(train_test)
522492
```
523493

524494
## `timetk::tk_ts()`

Compare-few-time-series-models.html

+11-46
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)