forked from englianhu/binary.com-interview-question
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary-Q1Inter-HFT-RV2.Rmd
4361 lines (3478 loc) · 159 KB
/
binary-Q1Inter-HFT-RV2.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "<img src='www/deriv.jpg' width='240'>"
subtitle: "[<span style='color:#DE5D83; background-color:black;'>Deriv.com</span> - Interday & Intraday High Frequency Trading Models Comparison <span style='color:#4E79A7'>**Review (Part II)**</span>](https://github.com/englianhu/binary.com-interview-question)"
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'>"
date: "`r lubridate::today('Asia/Tokyo')`"
output:
html_document:
mathjax: https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
number_sections: yes
toc: yes
toc_depth: 4
toc_float:
collapsed: yes
smooth_scroll: yes
code_folding: hide
css: CSSBackgrounds.css
---
<br>
<span style='color:green'>**Theme Song**</span>
<br>
<audio src="music/Mika - Elle me dit (happy song to be millionaire).mp3" controls></audio>
<br>
------
<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>
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>她对我说</span>
<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>
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>彼女は私に言う</span>
<span style='color:green'>**G**</span><span style='color:white'>**R**</span><span style='color:red'>**E**</span> : <span style='color:white'>Μου λέει</span>
<span style='color:red'>**S**</span><span style='color:yellow'>**P**</span><span style='color:red'>**N**</span> : <span style='color:white'>Ella me dijo</span>
<span style='color:black'>**G**</span><span style='color:red'>**E**</span><span style='color:yellow'>**R**</span> : <span style='color:white'>Sie sagte mir</span>
<span style='color:green'>**I**</span><span style='color:white'>**T**</span><span style='color:red'>**A**</span> : <span style='color:white'>Lei mi dice</span>
<span style='color:white'>**K**</span><span style='color:blue'>**R**</span><span style='color:red'>**O**</span> : <span style='color:white'>그녀는 나에게 말한다</span>
------
<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>
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>写一首欢快的歌</span>
<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>
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>幸せな歌を書く</span>
<span style='color:green'>**G**</span><span style='color:white'>**R**</span><span style='color:red'>**E**</span> : <span style='color:white'>Γράψτε ένα χαρούμενο τραγούδι</span>
<span style='color:red'>**S**</span><span style='color:yellow'>**P**</span><span style='color:red'>**N**</span> : <span style='color:white'>Escribe una canción alegre</span>
<span style='color:black'>**G**</span><span style='color:red'>**E**</span><span style='color:yellow'>**R**</span> : <span style='color:white'>Schreibe ein fröhliches Lied</span>
<span style='color:green'>**I**</span><span style='color:white'>**T**</span><span style='color:red'>**A**</span> : <span style='color:white'>Scrivi una canzone allegra</span>
<span style='color:white'>**K**</span><span style='color:blue'>**R**</span><span style='color:red'>**O**</span> : <span style='color:white'>쾌활한 노래 쓰기</span>
------
<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>
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>而不是悲伤的歌</span>
<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>
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>気のめいるような歌ではない</span>
<span style='color:green'>**G**</span><span style='color:white'>**R**</span><span style='color:red'>**E**</span> : <span style='color:white'>Όχι θλιβερό τραγούδι</span>
<span style='color:red'>**S**</span><span style='color:yellow'>**P**</span><span style='color:red'>**N**</span> : <span style='color:white'>No es una canción triste</span>
<span style='color:black'>**G**</span><span style='color:red'>**E**</span><span style='color:yellow'>**R**</span> : <span style='color:white'>Kein trauriges Lied</span>
<span style='color:green'>**I**</span><span style='color:white'>**T**</span><span style='color:red'>**A**</span> : <span style='color:white'>Canzone non triste</span>
<span style='color:white'>**K**</span><span style='color:blue'>**R**</span><span style='color:red'>**O**</span> : <span style='color:white'>슬픈 노래가 아님</span>
------
<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>
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>一首让所有人都喜欢的歌</span>
<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>
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>みんなが大好きな曲</span>
<span style='color:green'>**G**</span><span style='color:white'>**R**</span><span style='color:red'>**E**</span> : <span style='color:white'>Ένα τραγούδι που αρέσει σε όλους</span>
<span style='color:red'>**S**</span><span style='color:yellow'>**P**</span><span style='color:red'>**N**</span> : <span style='color:white'>Una cancion que a todos les gusta</span>
<span style='color:black'>**G**</span><span style='color:red'>**E**</span><span style='color:yellow'>**R**</span> : <span style='color:white'>Ein Lied, das jeder mag</span>
<span style='color:green'>**I**</span><span style='color:white'>**T**</span><span style='color:red'>**A**</span> : <span style='color:white'>Una canzone che piace a tutti</span>
<span style='color:white'>**K**</span><span style='color:blue'>**R**</span><span style='color:red'>**O**</span> : <span style='color:white'>모두가 좋아하는 노래</span>
------
<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>
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>她对我说</span>
<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>
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>彼女は私に言う</span>
<span style='color:green'>**G**</span><span style='color:white'>**R**</span><span style='color:red'>**E**</span> : <span style='color:white'>Μου λέει</span>
<span style='color:red'>**S**</span><span style='color:yellow'>**P**</span><span style='color:red'>**N**</span> : <span style='color:white'>Ella me dijo</span>
<span style='color:black'>**G**</span><span style='color:red'>**E**</span><span style='color:yellow'>**R**</span> : <span style='color:white'>Sie sagte mir</span>
<span style='color:green'>**I**</span><span style='color:white'>**T**</span><span style='color:red'>**A**</span> : <span style='color:white'>Lei mi dice</span>
<span style='color:white'>**K**</span><span style='color:blue'>**R**</span><span style='color:red'>**O**</span> : <span style='color:white'>그녀는 나에게 말한다</span>
------
<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>
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>你将成为亿万富翁</span>
<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>
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>あなたは億万長者になります</span>
<span style='color:green'>**G**</span><span style='color:white'>**R**</span><span style='color:red'>**E**</span> : <span style='color:white'>Θα γίνετε δισεκατομμυριούχος</span>
<span style='color:red'>**S**</span><span style='color:yellow'>**P**</span><span style='color:red'>**N**</span> : <span style='color:white'>Te convertirás en multimillonario</span>
<span style='color:black'>**G**</span><span style='color:red'>**E**</span><span style='color:yellow'>**R**</span> : <span style='color:white'>Sie werden Milliardär</span>
<span style='color:green'>**I**</span><span style='color:white'>**T**</span><span style='color:red'>**A**</span> : <span style='color:white'>Diventerai un miliardario</span>
<span style='color:white'>**K**</span><span style='color:blue'>**R**</span><span style='color:red'>**O**</span> : <span style='color:white'>당신은 억만 장자가 될 것입니다</span>
------
<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>
<span style='color:red'>**C**</span><span style='color:yellow'>**H**</span><span style='color:red'>**N**</span> : <span style='color:white'>你将为此感到骄傲</span>
<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>
<span style='color:white'>**J**</span><span style='color:red'>**P**</span><span style='color:white'>**N**</span> : <span style='color:white'>あなたは誇りに思うでしょう</span>
<span style='color:green'>**G**</span><span style='color:white'>**R**</span><span style='color:red'>**E**</span> : <span style='color:white'>Θα είσαι περήφανος για αυτό</span>
<span style='color:red'>**S**</span><span style='color:yellow'>**P**</span><span style='color:red'>**N**</span> : <span style='color:white'>Estarás orgulloso de ello</span>
<span style='color:black'>**G**</span><span style='color:red'>**E**</span><span style='color:yellow'>**R**</span> : <span style='color:white'>Sie werden stolz darauf sein</span>
<span style='color:green'>**I**</span><span style='color:white'>**T**</span><span style='color:red'>**A**</span> : <span style='color:white'>Ne sarai orgoglioso/span>
<span style='color:white'>**K**</span><span style='color:blue'>**R**</span><span style='color:red'>**O**</span> : <span style='color:white'>당신은 그것을 자랑스러워 할 것입니다</span>
------
<br>
# Introduction
Due to below issues from [<span style='color:#DE5D83; background-color:black;'>*Deriv.com*</span> - *Interday High Frequency Trading Models Comparison* <span style='color:red'>*Blooper*</span>](https://rpubs.com/englianhu/binary-Q1Inter-HFT), here I review the research by using same dataset as we can know from below **Part I**.
- [<span style='color:#DE5D83; background-color:black;'>*Deriv.com*</span> - *Interday High Frequency Trading Models Comparison* <span style='color:RoyalBlue'>*Review (Part I)*</span>](https://rpubs.com/englianhu/binary-Q1Inter-HFT-RV1) (in RPubs.com)
- [<span style='color:#DE5D83; background-color:black;'>*Deriv.com*</span> - *Interday High Frequency Trading Models Comparison* <span style='color:RoyalBlue'>*Review (Part I)*</span>](https://beta.rstudioconnect.com/content/16240/binary-Q1Inter-HFT-RV1.html) (in RStudioConnect.com)
Here I use the <span style='color:white; background-color:#DE5D83;'>**β**est model</span> (ETS `MNZ` & `MNZ`) from above study but adjust the data size as we can know from next section.
The purpose of adjust the data size to be intraday :
- compare if improve the accuracy.
- easier the workload for other models comparison (use minimum data size to get optimal model).
<span style='color:green'>**Load Packages**</span>
```{r setup, warning = FALSE, message = FALSE}
if(!suppressPackageStartupMessages(require('BBmisc'))) {
install.packages('BBmisc', dependencies = TRUE, INSTALL_opts = '--no-lock')
}
suppressPackageStartupMessages(require('BBmisc'))
# suppressPackageStartupMessages(require('rmsfuns'))
pkgs <- c('devtools', 'knitr', 'kableExtra', 'tint', 'furrr', 'tidyr',
'devtools','readr', 'lubridate', 'data.table', 'reprex',
'feather', 'purrr', 'quantmod', 'tidyquant', 'tibbletime',
'timetk', 'plyr', 'dplyr', 'stringr', 'magrittr', 'tdplyr',
'tidyverse', 'memoise', 'htmltools', 'formattable', 'dtplyr',
'zoo', 'forecast', 'seasonal', 'seasonalview', 'rjson',
'rugarch', 'rmgarch', 'mfGARCH', 'sparklyr', 'jcolors',
'microbenchmark', 'dendextend', 'lhmetools', 'ggthemr',
'stringr', 'pacman', 'profmem', 'ggthemes', 'flyingfox',
'htmltools', 'echarts4r', 'viridis', 'hrbrthemes', 'gtools',
'fable', 'fabletools', 'Rfast', 'Metrics', 'MLmetrics')
suppressAll(lib(pkgs))
# load_pkg(pkgs)
.dtr <- 'C:/Users/User/Documents/GitHub/binary.com-interview-question-data/'
## Set the timezone but not change the datetime
Sys.setenv(TZ = 'Asia/Tokyo')
## options(knitr.table.format = 'html') will set all kableExtra tables to be 'html', otherwise need to set the parameter on every single table.
options(warn = -1, knitr.table.format = 'html')#, digits.secs = 6)
## https://stackoverflow.com/questions/39417003/long-vectors-not-supported-yet-abnor-in-rmd-but-not-in-r-script
knitr::opts_chunk$set(warning = FALSE, #cache = TRUE,
message = FALSE, cache.lazy = FALSE)
rm(pkgs)
```
# Data
## Read Data
```{r read-data, warning = FALSE, message = FALSE}
## check if data path set
if(!exists('dtr')) {
dtr <- 'C:/Users/User/Documents/GitHub/binary.com-interview-question-data/'}
## save files if not exists
if(!file.exists(paste0(dtr, 'data/fx/USDJPY/dsmp.rds')) & exists('dsmp')) {
saveRDS(dsmp, paste0(dtr, 'data/fx/USDJPY/dsmp.rds'))}
## read files if not exists
if(!exists('dsmp')) {
dsmp <- readRDS(paste0(dtr, 'data/fx/USDJPY/dsmp.rds'))}
```
```{r smp-data, warning = FALSE, message = FALSE, results = 'asis'}
## plot sample data
dsmp[c(1:3, (nrow(dsmp)-3):nrow(dsmp)),] %>%
kbl(caption = '1 min Close Price Dataset', escape = FALSE) %>%
## https://www.w3schools.com/cssref/css_colors.asp
## https://public.tableau.com/en-us/gallery/100-color-palettes?gallery=votd
row_spec(0, background = 'DimGrey', color = 'gold', bold = TRUE) %>%
column_spec(1, background = 'CornflowerBlue') %>%
column_spec(2, background = 'Gray') %>%
column_spec(3, background = 'DarkGrey') %>%
column_spec(4, background = 'Gray') %>%
column_spec(5, background = 'DarkGrey') %>%
column_spec(6, background = '#4897D8') %>%
column_spec(7, background = '#556DAC') %>%
column_spec(8, background = '#92AAC7') %>%
column_spec(9, background = '#556DAC') %>%
column_spec(10, background = '#375E97') %>%
column_spec(11, background = 'CornflowerBlue') %>%
column_spec(12, background = 'LightGray', color = 'goldenrod') %>%
kable_styling(bootstrap_options = c('striped', 'hover', 'condensed', 'responsive')) %>%
kable_material(full_width = FALSE) %>% ##`full_width = FALSE` will auto adjust every single columns width to fit the table full width.
scroll_box(width = '100%', fixed_thead = TRUE, height = '400px')
```
*source : `r paste0(dim(dsmp), collapse = ' x ')`*
From above table, we can know the dataset gather from `r paste(range(dsmp$date), collapse = ' to ')` which is used in [<span style='color:#DE5D83; background-color:black;'>*Deriv.com*</span> - *Interday High Frequency Trading Models Comparison* <span style='color:RoyalBlue'>*Review (Part I)*</span>](https://rpubs.com/englianhu/binary-Q1Inter-HFT-RV1).
# `ETS` Modelling
## Seasonal Data Modeling
Here I start my 1st forecast date from 1st trading datetime of 2016 (`r dsmp[year == 2016]$date[1]` which is 2nd year in dataset) which is used in [<span style='color:#DE5D83; background-color:black;'>*Deriv.com*</span> - *Interday High Frequency Trading Models Comparison* <span style='color:RoyalBlue'>*Review (Part I)*</span>](https://rpubs.com/englianhu/binary-Q1Inter-HFT-RV1).
The default data size `7200` to forecast `1440` as we can know that's the optimal volume of observation data as we know from [<span style='color:#DE5D83; background-color:black;'>*Deriv.com*</span> - *Interday High Frequency Trading Models Comparison* <span style='color:RoyalBlue'>*Review (Part I)*</span>](https://rpubs.com/englianhu/binary-Q1Inter-HFT-RV1) to compare with below seasonality.
## Daily Seasonal Data
### Modelling
I set the length of data as Daily (`1440 mins` which is 1 trading days) to forecast `1440` minutes (`1440` minutes is a trading day).
- [<span style='color:white; background-color:LightSlateGrey;'>*8.7 ARIMA modelling in R*</span> in **Forecasting: Principles and Practice (2nd Edition)**](https://otexts.com/fpp2/arima-r.html)
- [<span style='color:white; background-color:LightSlateGrey;'>*8.9 Seasonal ARIMA models*</span> in **Forecasting: Principles and Practice (2nd Edition)**](https://otexts.com/fpp2/seasonal-arima.html)
- [Seasonality in `auto.arima()` from `forecast` package](https://stackoverflow.com/a/37400899/3806250)
Refer to above function or load below r function.
### Dy >> Dy
I set the length of data as Daily (`1440 mins` which is 1 trading days) to forecast `1440 mins` (`24 hrs * 60 mins = 1440 mins` is a trading day).
```{r tseas, eval = FALSE}
tseas <- function(timeID, data = dsmp, data_len,
hrz1 = c(1440, 7200), hrz2 = 1440, .model) {
if(hrz1 == 1440) {
tmp <- llply(1:length(timeID), function(i) {
if(i == 1) {
cat('\n===========================================\n')
cat('train[', i, ']\n')
print(train <- dsmp[date < timeID[i]][(.N - (data_len - 1)):.N])
ctr <- train$sq[1]:(range(train$sq)[2] + hrz1)
cat('\n-------------------------------------------\n')
cat('train_test[', i, ']\n')
print(train_test <- dsmp[sq %in% ctr])
sets <- train[, .(index, close)] %>%
as_tibble %>%
tk_ts(frequency = hrz1) %>%
ets(model = .model) %>%
forecast(h = hrz1) %>%
tk_tbl %>%
dplyr::mutate(index = train_test[(.N - hrz1 + 1):.N,]$index,
mk.price = train_test[(.N - hrz1 + 1):.N,]$close) %>%
dplyr::rename(fc.price = `Point Forecast`) %>%
dplyr::select(index, mk.price, fc.price)
cat('\n-------------------------------------------\n')
cat('forecast[', i, ']\n')
print(sets %>% as.data.table)
fl_pth <- paste0(.dtr, 'data/fx/USDJPY/ts_ets_', data_len,
'_', hrz1, '.', as_date(sets$index[1]), '.rds')
saveRDS(sets, fl_pth)
cat('\n', i, '=', paste0('~/data/fx/USDJPY/ts_ets_', .model, '_',
data_len, '_', hrz1, '.',
as_date(sets$index[1]), '.rds saved!'))
cat('\n\n')
rm(sets)
} else if(i %in% seq(1, length(timeID), by = 6)[-1]) {
} else if(i == length(timeID)) {
} else {
lst_sq <- dsmp[date < timeID[i],][.N]$sq + 1
cat('\n===========================================\n')
cat('train[', i, ']\n')
print(train <- dsmp[(lst_sq - data_len + 1):lst_sq])
ctr <- train$sq[1]:(range(train$sq)[2] + hrz1)
cat('\n-------------------------------------------\n')
cat('train_test[', i, ']\n')
print(train_test <- dsmp[sq %in% ctr])
sets <- train[, .(index, close)] %>%
as_tibble %>%
tk_ts(frequency = hrz1) %>%
ets(model = .model) %>%
forecast(h = hrz1) %>%
tk_tbl %>%
dplyr::mutate(index = train_test[(.N - hrz1 + 1):.N,]$index,
mk.price = train_test[(.N - hrz1 + 1):.N,]$close) %>%
dplyr::rename(fc.price = `Point Forecast`) %>%
dplyr::select(index, mk.price, fc.price)
cat('\n-------------------------------------------\n')
cat('forecast[', i, ']\n')
print(sets %>% as.data.table)
fl_pth <- paste0(.dtr, 'data/fx/USDJPY/ts_ets_', data_len,
'_', hrz1, '.', as_date(sets$index[1]), '.rds')
saveRDS(sets, fl_pth)
cat('\n', i, '=', paste0('~/data/fx/USDJPY/ts_ets_', .model, '_',
data_len, '_', hrz1, '.',
as_date(sets$index[1]), '.rds saved!'))
cat('\n\n')
rm(sets)
}
})
} else if(hrz1 == 7200) {
tmp <- llply(1:length(timeID), function(i) {
if(i == 1) {
cat('\n===========================================\n')
cat('train[', i, ']\n')
print(train <- dsmp[date < timeID[i]][(.N - (data_len - 1)):.N])
ctr <- train$sq[1]:(range(train$sq)[2] + hrz1)
cat('\n-------------------------------------------\n')
cat('train_test[', i, ']\n')
print(train_test <- dsmp[sq %in% ctr])
sets <- train[, .(index, close)] %>%
as_tibble %>%
tk_ts(frequency = hrz1) %>%
ets(model = .model) %>%
forecast(h = hrz1) %>%
tk_tbl %>%
dplyr::mutate(index = train_test[(.N - hrz1 + 1):.N,]$index,
mk.price = train_test[(.N - hrz1 + 1):.N,]$close) %>%
dplyr::rename(fc.price = `Point Forecast`) %>%
dplyr::select(index, mk.price, fc.price)
cat('\n-------------------------------------------\n')
cat('forecast[', i, ']\n')
print(sets %>% as.data.table)
fl_pth <- paste0(.dtr, 'data/fx/USDJPY/ts_ets_', data_len,
'_', hrz1, '.', as_date(sets$index[1]), '.rds')
saveRDS(sets, fl_pth)
cat('\n', i, '=', paste0('~/data/fx/USDJPY/ts_ets_', .model, '_',
data_len, '_', hrz1, '.',
as_date(sets$index[1]), '.rds saved!'))
cat('\n\n')
rm(sets)
} else if(i > (length(timeID) - hrz1/hrz2) & i != length(timeID)) {
lst_sq <- dsmp[date < timeID[i],][.N]$sq + 1
## filter the length of forecasted data to fit with train_test data
## when the length of forecasted data more then length of test data.
#lst_date <- timeID[(length(timeID) - (hrz1/hrz2)):length(timeID)]
lst_date <- timeID[timeID >= timeID[i]]
lst_date_sq <- grep(
timeID[i], timeID[
(length(timeID) - (hrz1/hrz2 - 1)):length(timeID)])
cat('\n===========================================\n')
cat('train[', i, ']\n')
print(train <- dsmp[(lst_sq - data_len + 1):lst_sq])
ctr <- train$sq[1]:(range(train$sq)[2] + hrz1)
cat('\n-------------------------------------------\n')
cat('train_test[', i, ']\n')
print(train_test <- dsmp[sq %in% ctr])
sets <- train[, .(index, close)] %>%
as_tibble %>%
tk_ts(frequency = hrz1) %>%
ets(model = .model) %>%
forecast(h = hrz1) %>%
tk_tbl
sets <- sets[1:(hrz1 - (hrz2 * lst_date_sq)),] %>%
dplyr::mutate(index = train_test[
(.N - (hrz1 - (hrz2 * lst_date_sq)) + 1):.N, ]$index,
mk.price = train_test[
(.N - (hrz1 - (hrz2 * lst_date_sq)) + 1):.N, ]$close) %>%
dplyr::rename(fc.price = `Point Forecast`) %>%
dplyr::select(index, mk.price, fc.price)
cat('\n-------------------------------------------\n')
cat('forecast[', i, ']\n')
print(sets %>% as.data.table)
fl_pth <- paste0(.dtr, 'data/fx/USDJPY/ts_ets_', data_len,
'_', hrz1, '.', as_date(sets$index[1]), '.rds')
saveRDS(sets, fl_pth)
cat('\n', i, '=', paste0('~/data/fx/USDJPY/ts_ets_', .model, '_',
data_len, '_', hrz1, '.',
as_date(sets$index[1]), '.rds saved!'))
cat('\n\n')
rm(sets)
} else if(i %in% seq(1, length(timeID), by = 6)[-1]) {
} else if(i == length(timeID)) {
} else {
lst_sq <- dsmp[date < timeID[i],][.N]$sq + 1
cat('\n===========================================\n')
cat('train[', i, ']\n')
print(train <- dsmp[(lst_sq - data_len + 1):lst_sq])
ctr <- train$sq[1]:(range(train$sq)[2] + hrz1)
cat('\n-------------------------------------------\n')
cat('train_test[', i, ']\n')
print(train_test <- dsmp[sq %in% ctr])
sets <- train[, .(index, close)] %>%
as_tibble %>%
tk_ts(frequency = hrz1) %>%
ets(model = .model) %>%
forecast(h = hrz1) %>%
tk_tbl %>%
dplyr::mutate(index = train_test[(.N - hrz1 + 1):.N,]$index,
mk.price = train_test[(.N - hrz1 + 1):.N,]$close) %>%
dplyr::rename(fc.price = `Point Forecast`) %>%
dplyr::select(index, mk.price, fc.price)
cat('\n-------------------------------------------\n')
cat('forecast[', i, ']\n')
print(sets %>% as.data.table)
fl_pth <- paste0(.dtr, 'data/fx/USDJPY/ts_ets_', data_len,
'_', hrz1, '.', as_date(sets$index[1]), '.rds')
saveRDS(sets, fl_pth)
cat('\n', i, '=', paste0('~/data/fx/USDJPY/ts_ets_', .model, '_',
data_len, '_', hrz1, '.',
as_date(sets$index[1]), '.rds saved!'))
cat('\n\n')
rm(sets)
}
})
} else {
}
return(tmp)
}
```
```{r intra_1440, eval = FALSE}
intra_1440 <- function(timeID, data = dsmp, data_len,
hrz1 = 60, .model, vb = TRUE) {
## data_len 1440; hrz1 = 60
intr <- data_len/hrz1
tmp <- llply(1:length(timeID), function(i) {
if(i == 1) {
tmp2 <-llply(1:intr, function(j) {
if(j == 1) {
train <- dsmp[date < timeID[i]][(.N - (data_len - 1)):.N]
} else {
lst_sq <- dsmp[date < timeID[i]][(.N - (hrz1 * (intr - j + 1) - 1))]$sq
train <- dsmp[lst_sq:(lst_sq + data_len - 1)]
}
ctr <- train$sq[1]:(range(train$sq)[2] + hrz1)
if(vb == TRUE) {
cat('\n===========================================\n')
cat('train[', i, '-', j, ']\n')
print(train)
}
train_test <- dsmp[sq %in% ctr]
if(vb == TRUE) {
cat('\n-------------------------------------------\n')
cat('train_test[', i, '-', j, ']\n')
print(train_test)
}
sets <- train[, .(index, close)] %>%
as_tibble %>%
tk_ts(frequency = hrz1) %>%
ets(model = .model) %>%
forecast(h = hrz1) %>%
tk_tbl %>%
dplyr::mutate(index = train_test[(.N - hrz1 + 1):.N,]$index,
mk.price = train_test[(.N - hrz1 + 1):.N,]$close) %>%
dplyr::rename(fc.price = `Point Forecast`) %>%
dplyr::select(index, mk.price, fc.price)
if(vb == TRUE) {
cat('\n-------------------------------------------\n')
cat('forecast[', i, '-', j, ']\n')
print(sets %>% as.data.table)
}
fl_pth <- paste0(
.dtr, 'data/fx/USDJPY/intraday/ts_ets_', .model, '_', data_len,
'_', hrz1, '.p', j, '.', as_date(sets$index[1]), '.rds')
saveRDS(sets, fl_pth)
cat('\n', i, '-', j, '=',
paste0('~/data/fx/USDJPY/intraday/ts_ets_', .model, '_',
data_len, '_', hrz1, '.p', j, '.',
as_date(sets$index[1]), '.rds saved!'))
cat('\n\n')
rm(sets)
})
return(tmp2)
} else if(i %in% seq(1, length(timeID), by = 6)[-1]) {
} else if(i == length(timeID)) {
} else {
tmp2 <-llply(1:intr, function(j) {
if(j == 1) {
lst_sq <- dsmp[date < timeID[i],][.N]$sq + 1
} else {
lst_sq <- dsmp[date < timeID[i],][.N]$sq + 1 + hrz1 * (j - 1)
}
train <- dsmp[(lst_sq - data_len + 1):lst_sq]
ctr <- train$sq[1]:(range(train$sq)[2] + hrz1)
if(vb == TRUE) {
cat('\n===========================================\n')
cat('train[', i, '-', j, ']\n')
print(train)
}
train_test <- dsmp[sq %in% ctr]
if(vb == TRUE) {
cat('\n-------------------------------------------\n')
cat('train_test[', i, '-', j, ']\n')
print(train_test)
}
sets <- train[, .(index, close)] %>%
as_tibble %>%
tk_ts(frequency = hrz1) %>%
ets(model = .model) %>%
forecast(h = hrz1) %>%
tk_tbl %>%
dplyr::mutate(index = train_test[(.N - hrz1 + 1):.N,]$index,
mk.price = train_test[(.N - hrz1 + 1):.N,]$close) %>%
dplyr::rename(fc.price = `Point Forecast`) %>%
dplyr::select(index, mk.price, fc.price)
if(vb == TRUE) {
cat('\n-------------------------------------------\n')
cat('forecast[', i, '-', j, ']\n')
print(sets %>% as.data.table)
}
fl_pth <- paste0(
.dtr, 'data/fx/USDJPY/intraday/ts_ets_', .model, '_', data_len,
'_', hrz1, '.p', j, '.', as_date(sets$index[1]), '.rds')
saveRDS(sets, fl_pth)
cat('\n', i, '-', j, '=',
paste0('~/data/fx/USDJPY/intraday/ts_ets_', .model, '_',
data_len, '_', hrz1, '.p', j, '.',
as_date(sets$index[1]), '.rds saved!'))
cat('\n\n')
rm(sets)
})
return(tmp2)
}
})
return(tmp)
}
```
```{r, eval = FALSE}
# --------- eval=FALSE ---------
ets.m <- 'MNN'
source('function/tseas.R')
source('function/intra_1440.R')
timeID <- unique(dsmp$date)
bse <- dsmp[year == 2016]$date[1] #"2016-01-04" #1st trading date in 2nd year
timeID %<>% .[. >= bse]
#timeID %<>% .[. >= as_date('2016-01-04')]
data_len <- 1440
hrz1 <- 1440
hrz2 <- 1440
llply(ets.m, function(md) {
tseas(timeID = timeID, dsmp,
data_len = data_len, hrz1 = hrz1,
hrz2 = hrz2, .model = md)
})
```
```{r dy-dy, warning = FALSE, message = FALSE, results = 'asis'}
fl <- list.files(paste0(.dtr, 'data/fx/USDJPY/'), pattern = '^ts_ets_MNN_1440_1440.[0-9]{4}')[1]
if(all(is.na(fl))){
smp <- NA
} else {
smp <- readRDS(paste0(.dtr, 'data/fx/USDJPY/', fl))
data.frame(smp)[
c(1:3, (nrow(smp)-2):nrow(smp)),] %>%
kbl(caption = 'Data Sample (ETS MNN 1440 forecast 1440)', escape = FALSE) %>%
row_spec(0, background = 'DimGrey', color = 'yellow') %>%
column_spec(1, background = 'CornflowerBlue') %>%
column_spec(2, background = '#556DAC') %>%
#column_spec(3, background = 'LightSlateGrey') %>%
#column_spec(3, background = '#556DAC') %>%
column_spec(3, background = 'Gainsboro', color = 'goldenrod') %>%
column_spec(4, background = 'LightGray', color = 'goldenrod') %>%
kable_styling(bootstrap_options = c('striped', 'hover', 'condensed', 'responsive')) %>%
kable_material(full_width = FALSE) %>%
scroll_box(width = '100%', fixed_thead = TRUE)
}
```
*source : `r paste0(dim(smp), collapse = ' x ')`*
```{r include = FALSE}
if(exists('smp')) rm(smp)
if(exists('fl')) rm(fl)
```
### Dy >> 12Hr
I set the length of data as Daily (`1440 mins` which is 1 trading days) to forecast `720 mins` (`12 hrs * 60 mins = 720 mins` is half trading day).
```{r, eval = FALSE}
# --------- eval=FALSE ---------
ets.m <- 'MNN'
source('function/intra_1440.R')
timeID <- unique(dsmp$date)
bse <- dsmp[year == 2016]$date[1] #"2016-01-04" #1st trading date in 2nd year
timeID %<>% .[. >= bse]
#timeID %<>% .[. >= as_date('2016-01-04')]
data_len <- 1440
hrz1 <- 720
llply(ets.m, function(md) {
intra_1440(timeID = timeID, dsmp,
data_len = data_len, hrz1 = hrz1,
.model = md)
})
```
```{r dy-12hr, warning = FALSE, message = FALSE, results = 'asis'}
fl <- list.files(paste0(.dtr, 'data/fx/USDJPY/intraday/'), pattern = '^ts_ets_MNN_1440_720.p_[0-9]{0,}.[0-9]{4}')[1]
if(all(is.na(fl))){
smp <- NA
} else {
smp <- readRDS(paste0(.dtr, 'data/fx/USDJPY/intraday/', fl))
data.frame(smp)[
c(1:3, (nrow(smp)-2):nrow(smp)),] %>%
kbl(caption = 'Data Sample (ETS MNN 1440 forecast 720)', escape = FALSE) %>%
row_spec(0, background = 'DimGrey', color = 'yellow') %>%
column_spec(1, background = 'CornflowerBlue') %>%
column_spec(2, background = '#556DAC') %>%
#column_spec(3, background = 'LightSlateGrey') %>%
#column_spec(3, background = '#556DAC') %>%
column_spec(3, background = 'Gainsboro', color = 'goldenrod') %>%
column_spec(4, background = 'LightGray', color = 'goldenrod') %>%
kable_styling(bootstrap_options = c('striped', 'hover', 'condensed', 'responsive')) %>%
kable_material(full_width = FALSE) %>%
scroll_box(width = '100%', fixed_thead = TRUE)
}
```
*source : `r paste0(dim(smp), collapse = ' x ')`*
```{r include = FALSE}
if(exists('smp')) rm(smp)
if(exists('fl')) rm(fl)
```
### Dy >> 8Hr
I set the length of data as Daily (`1440 mins` which is 1 trading days) to forecast `480 mins` (`8 hrs * 60 mins = 480 mins` is 8 hours in a trading day).
```{r, eval = FALSE}
# --------- eval=FALSE ---------
ets.m <- 'MNN'
source('function/intra_1440.R')
timeID <- unique(dsmp$date)
bse <- dsmp[year == 2016]$date[1] #"2016-01-04" #1st trading date in 2nd year
timeID %<>% .[. >= bse]
#timeID %<>% .[. >= as_date('2016-01-04')]
data_len <- 1440
hrz1 <- 480
llply(ets.m, function(md) {
intra_1440(timeID = timeID, dsmp,
data_len = data_len, hrz1 = hrz1,
.model = md)
})
```
```{r dy-8hr, warning = FALSE, message = FALSE, results = 'asis'}
fl <- list.files(paste0(.dtr, 'data/fx/USDJPY/intraday/'), pattern = '^ts_ets_MNN_1440_480.p_[0-9]{0,}.[0-9]{4}')[1]
if(all(is.na(fl))){
smp <- NA
} else {
smp <- readRDS(paste0(.dtr, 'data/fx/USDJPY/intraday/', fl))
data.frame(smp)[
c(1:3, (nrow(smp)-2):nrow(smp)),] %>%
kbl(caption = 'Data Sample (ETS MNN 1440 forecast 480)', escape = FALSE) %>%
row_spec(0, background = 'DimGrey', color = 'yellow') %>%
column_spec(1, background = 'CornflowerBlue') %>%
column_spec(2, background = '#556DAC') %>%
#column_spec(3, background = 'LightSlateGrey') %>%
#column_spec(3, background = '#556DAC') %>%
column_spec(3, background = 'Gainsboro', color = 'goldenrod') %>%
column_spec(4, background = 'LightGray', color = 'goldenrod') %>%
kable_styling(bootstrap_options = c('striped', 'hover', 'condensed', 'responsive')) %>%
kable_material(full_width = FALSE) %>%
scroll_box(width = '100%', fixed_thead = TRUE)
}
```
*source : `r paste0(dim(smp), collapse = ' x ')`*
```{r include = FALSE}
if(exists('smp')) rm(smp)
if(exists('fl')) rm(fl)
```
### Dy >> 6Hr
I set the length of data as Daily (`1440 mins` which is 1 trading days) to forecast `360 mins` (`6 hrs * 60 mins = 360 mins` is 6 hours in a trading day).
```{r, eval = FALSE}
# --------- eval=FALSE ---------
ets.m <- 'MNN'
source('function/intra_1440.R')
timeID <- unique(dsmp$date)
bse <- dsmp[year == 2016]$date[1] #"2016-01-04" #1st trading date in 2nd year
timeID %<>% .[. >= bse]
#timeID %<>% .[. >= as_date('2016-01-04')]
data_len <- 1440
hrz1 <- 360
llply(ets.m, function(md) {
intra_1440(timeID = timeID, dsmp,
data_len = data_len, hrz1 = hrz1,
.model = md)
})
```
```{r dy-6hr, warning = FALSE, message = FALSE, results = 'asis'}
fl <- list.files(paste0(.dtr, 'data/fx/USDJPY/intraday/'), pattern = '^ts_ets_MNN_1440_360.p_[0-9]{0,}.[0-9]{4}')[1]
if(all(is.na(fl))){
smp <- NA
} else {
smp <- readRDS(paste0(.dtr, 'data/fx/USDJPY/intraday/', fl))
data.frame(smp)[
c(1:3, (nrow(smp)-2):nrow(smp)),] %>%
kbl(caption = 'Data Sample (ETS MNN 1440 forecast 360)', escape = FALSE) %>%
row_spec(0, background = 'DimGrey', color = 'yellow') %>%
column_spec(1, background = 'CornflowerBlue') %>%
column_spec(2, background = '#556DAC') %>%
#column_spec(3, background = 'LightSlateGrey') %>%
#column_spec(3, background = '#556DAC') %>%
column_spec(3, background = 'Gainsboro', color = 'goldenrod') %>%
column_spec(4, background = 'LightGray', color = 'goldenrod') %>%
kable_styling(bootstrap_options = c('striped', 'hover', 'condensed', 'responsive')) %>%
kable_material(full_width = FALSE) %>%
scroll_box(width = '100%', fixed_thead = TRUE)
}
```
*source : `r paste0(dim(smp), collapse = ' x ')`*
```{r include = FALSE}
if(exists('smp')) rm(smp)
if(exists('fl')) rm(fl)
```
### Dy >> 4Hr
I set the length of data as Daily (`1440 mins` which is 1 trading days) to forecast `240 mins` (`4 hrs * 60 mins = 240 mins` is 4 hours in a trading day).
```{r, eval = FALSE}
# --------- eval=FALSE ---------
ets.m <- 'MNN'
source('function/intra_1440.R')
timeID <- unique(dsmp$date)
bse <- dsmp[year == 2016]$date[1] #"2016-01-04" #1st trading date in 2nd year
timeID %<>% .[. >= bse]
#timeID %<>% .[. >= as_date('2016-01-04')]
data_len <- 1440
hrz1 <- 240
llply(ets.m, function(md) {
intra_1440(timeID = timeID, dsmp,
data_len = data_len, hrz1 = hrz1,
.model = md)
})
```
```{r dy-4hr, warning = FALSE, message = FALSE, results = 'asis'}
fl <- list.files(paste0(.dtr, 'data/fx/USDJPY/intraday/'), pattern = '^ts_ets_MNN_1440_240.p_[0-9]{0,}.[0-9]{4}')[1]
if(all(is.na(fl))){
smp <- NA
} else {
smp <- readRDS(paste0(.dtr, 'data/fx/USDJPY/intraday/', fl))
data.frame(smp)[
c(1:3, (nrow(smp)-2):nrow(smp)),] %>%
kbl(caption = 'Data Sample (ETS MNN 1440 forecast 240)', escape = FALSE) %>%
row_spec(0, background = 'DimGrey', color = 'yellow') %>%
column_spec(1, background = 'CornflowerBlue') %>%
column_spec(2, background = '#556DAC') %>%
#column_spec(3, background = 'LightSlateGrey') %>%
#column_spec(3, background = '#556DAC') %>%
column_spec(3, background = 'Gainsboro', color = 'goldenrod') %>%
column_spec(4, background = 'LightGray', color = 'goldenrod') %>%
kable_styling(bootstrap_options = c('striped', 'hover', 'condensed', 'responsive')) %>%
kable_material(full_width = FALSE) %>%
scroll_box(width = '100%', fixed_thead = TRUE)
}
```
*source : `r paste0(dim(smp), collapse = ' x ')`*
```{r include = FALSE}
if(exists('smp')) rm(smp)
if(exists('fl')) rm(fl)
```
### Dy >> 3Hr
I set the length of data as Daily (`1440 mins` which is 1 trading days) to forecast `180 mins` (`3 hrs * 60 mins = 180 mins` is 3 hours in a trading day).
```{r, eval = FALSE}
# --------- eval=FALSE ---------
ets.m <- 'MNN'
source('function/intra_1440.R')
timeID <- unique(dsmp$date)
bse <- dsmp[year == 2016]$date[1] #"2016-01-04" #1st trading date in 2nd year
timeID %<>% .[. >= bse]
#timeID %<>% .[. >= as_date('2016-01-04')]
data_len <- 1440
hrz1 <- 180
llply(ets.m, function(md) {
intra_1440(timeID = timeID, dsmp,
data_len = data_len, hrz1 = hrz1,
.model = md)
})
```
```{r dy-3hr, warning = FALSE, message = FALSE, results = 'asis'}
fl <- list.files(paste0(.dtr, 'data/fx/USDJPY/intraday/'), pattern = '^ts_ets_MNN_1440_180.p_[0-9]{0,}.[0-9]{4}')[1]
if(all(is.na(fl))){
smp <- NA
} else {
smp <- readRDS(paste0(.dtr, 'data/fx/USDJPY/intraday/', fl))
data.frame(smp)[
c(1:3, (nrow(smp)-2):nrow(smp)),] %>%
kbl(caption = 'Data Sample (ETS MNN 1440 forecast 180)', escape = FALSE) %>%
row_spec(0, background = 'DimGrey', color = 'yellow') %>%
column_spec(1, background = 'CornflowerBlue') %>%
column_spec(2, background = '#556DAC') %>%
#column_spec(3, background = 'LightSlateGrey') %>%
#column_spec(3, background = '#556DAC') %>%
column_spec(3, background = 'Gainsboro', color = 'goldenrod') %>%
column_spec(4, background = 'LightGray', color = 'goldenrod') %>%
kable_styling(bootstrap_options = c('striped', 'hover', 'condensed', 'responsive')) %>%
kable_material(full_width = FALSE) %>%
scroll_box(width = '100%', fixed_thead = TRUE)
}
```
*source : `r paste0(dim(smp), collapse = ' x ')`*
```{r include = FALSE}
if(exists('smp')) rm(smp)
if(exists('fl')) rm(fl)
```
### Dy >> 2Hr
I set the length of data as Daily (`1440 mins` which is 1 trading days) to forecast `120 mins` (`2 hrs * 60 mins = 120 mins` is 2 hours in a trading day).
```{r, eval = FALSE}
# --------- eval=FALSE ---------
ets.m <- 'MNN'
source('function/intra_1440.R')
timeID <- unique(dsmp$date)
bse <- dsmp[year == 2016]$date[1] #"2016-01-04" #1st trading date in 2nd year
timeID %<>% .[. >= bse]
#timeID %<>% .[. >= as_date('2016-01-04')]
data_len <- 1440
hrz1 <- 120
llply(ets.m, function(md) {