Skip to content

Commit 1af1c1d

Browse files
committed
update
1 parent 1fdfa0b commit 1af1c1d

File tree

5 files changed

+472
-365
lines changed

5 files changed

+472
-365
lines changed

binary-Q1Inter-HFT-RV2.Rmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,6 +3575,8 @@ mds_ets_MNN_intraday3_1min_1y <- rbind(mds_ets_MNN_intraday_1min_1y, mds_ets_MNN
35753575
35763576
saveRDS(mds_ets_MNN_intraday3_1min_1y, paste0(.dtr, 'data/fx/USDJPY/mds_ets_MNN_intraday3_1min_1y.rds'))
35773577
3578+
mds_ets_MNN_intraday3_1min_1y <- readRDS(paste0(.dtr, 'data/fx/USDJPY/mds_ets_MNN_intraday3_1min_1y.rds'))
3579+
35783580
mds_ets_MNN_intraday3_1min_1y_cmp <- mds_ets_MNN_intraday3_1min_1y %>%
35793581
#tidyr::unite(model, t_series:part) %>%
35803582
tidyr::unite(model, t_series:fc_min) %>%

binary-Q1Inter-HFT-RV2.html

Lines changed: 332 additions & 306 deletions
Large diffs are not rendered by default.

intra_600.720.840.960.r

Lines changed: 135 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pth <- 'C:/Users/User/Documents/GitHub/binary.com-interview-question-data/data/fx/USDJPY/intraday'
2-
pth <- 'C:/Users/User/Desktop/intraday'
2+
pth <- 'C:/Users/User/Desktop/intraday_refill'
33
fls <- list.files(pth, pattern = '^ts_ets_MNN_960_1.p_[0-9]{0,}.[0-9]{4}|^ts_ets_MNN_840_1.p_[0-9]{0,}.[0-9]{4}|^ts_ets_MNN_720_1.p_[0-9]{0,}.[0-9]{4}|^ts_ets_MNN_600_1.p_[0-9]{0,}.[0-9]{4}')
44
fls <- sort(fls)
55
#ts_ets_MNN_960_1.p_504.2017-01-03
@@ -54,73 +54,152 @@ mds_ets_MNN_intraday2_1min <- ldply(1:length(fls), function(i) {
5454
saveRDS(mds_ets_MNN_intraday2_1min, paste0(.dtr, 'intra_600_720_840_960.rds'))
5555

5656

57-
58-
5957
### -------------------------------------------------
6058

6159
require('data.table')
62-
mds_ets_MNN_intraday2_1min <- readRDS(paste0(.dtr, 'data/fx/USDJPY/mds_ets_MNN_intraday2_1min.rds')) %>% as.data.table
63-
mds_ets_MNN_intraday2_1min <- mds_ets_MNN_intraday2_1min[order(index)]
60+
require('dplyr')
61+
require('magrittr')
62+
63+
mds_ets_MNN_intraday3_1min_1y <- readRDS(paste0(.dtr, 'data/fx/USDJPY/mds_ets_MNN_intraday3_1min_1y.rds'))
64+
mds_ets_MNN_intraday3_1min_1y %<>% as.data.table
65+
mds_ets_MNN_intraday3_1min_1y <- mds_ets_MNN_intraday3_1min_1y[order(index)]
66+
mds_ets_MNN_intraday3_1min_1y %>% unique
67+
68+
llply(split(mds_ets_MNN_intraday3_1min_1y, mds_ets_MNN_intraday3_1min_1y$data_min), function(x) { as.data.table(x) })
69+
70+
mds_ets_MNN_intraday3_1min_1y <- ldply(split(mds_ets_MNN_intraday3_1min_1y, mds_ets_MNN_intraday3_1min_1y$data_min), function(x) {
71+
unique(as.data.table(x), by = c('index')) }) %>% as.data.table
72+
#mds_ets_MNN_intraday3_1min_1y <- mds_ets_MNN_intraday3_1min_1y[date <= as_date('2017-01-01')]
73+
#saveRDS(mds_ets_MNN_intraday3_1min_1y, paste0(.dtr, 'data/fx/USDJPY/mds_ets_MNN_intraday3_1min_1y.rds'))
6474

65-
llply(split(mds_ets_MNN_intraday2_1min, mds_ets_MNN_intraday2_1min$data_min), function(x) { as.data.table(x) })
75+
smmp <- dsmp[374401:748800]
76+
77+
llply(split(mds_ets_MNN_intraday3_1min_1y, mds_ets_MNN_intraday3_1min_1y$data_min), function(x) {
78+
x <- as.data.table(x)
79+
y <- smmp$index[!unique(smmp$index) %in% unique(x$index)]
80+
#c(head(y), tail(y))
81+
length(y)
82+
})
83+
$`180`
84+
[1] 105
85+
86+
$`240`
87+
[1] 105
88+
89+
$`360`
90+
[1] 133
91+
92+
$`480`
93+
[1] 125
6694

6795
$`600`
68-
index t_series model sub_model data_min fc_min part date mk.price fc.price
69-
1: 2016-01-04 00:02:00 ts ets MNN 600 1 1 2016-01-04 120.2200 120.2104
70-
2: 2016-01-04 00:03:00 ts ets MNN 600 1 2 2016-01-04 120.2200 120.2200
71-
3: 2016-01-04 00:04:00 ts ets MNN 600 1 3 2016-01-04 120.2185 120.2200
72-
4: 2016-01-04 00:05:00 ts ets MNN 600 1 4 2016-01-04 120.2195 120.2185
73-
5: 2016-01-04 00:06:00 ts ets MNN 600 1 5 2016-01-04 120.2250 120.2195
74-
---
75-
44634: 2016-02-15 23:56:00 ts ets MNN 600 1 1436 2016-02-15 114.6015 114.5930
76-
44635: 2016-02-15 23:57:00 ts ets MNN 600 1 1437 2016-02-15 114.5940 114.6015
77-
44636: 2016-02-15 23:58:00 ts ets MNN 600 1 1438 2016-02-15 114.6050 114.5940
78-
44637: 2016-02-15 23:59:00 ts ets MNN 600 1 1439 2016-02-15 114.5950 114.6050
79-
44638: 2016-02-16 00:00:00 ts ets MNN 600 1 1440 2016-02-16 114.5960 114.5950
96+
[1] 13063
8097

8198
$`720`
82-
index t_series model sub_model data_min fc_min part date mk.price fc.price
83-
1: 2016-01-04 00:02:00 ts ets MNN 720 1 1 2016-01-04 120.2200 120.2104
84-
2: 2016-01-04 00:03:00 ts ets MNN 720 1 2 2016-01-04 120.2200 120.2200
85-
3: 2016-01-04 00:04:00 ts ets MNN 720 1 3 2016-01-04 120.2185 120.2200
86-
4: 2016-01-04 00:05:00 ts ets MNN 720 1 4 2016-01-04 120.2195 120.2185
87-
5: 2016-01-04 00:06:00 ts ets MNN 720 1 5 2016-01-04 120.2250 120.2195
88-
---
89-
68128: 2016-04-04 21:49:00 ts ets MNN 720 1 1309 2016-04-04 111.2390 111.2450
90-
68129: 2016-04-04 21:50:00 ts ets MNN 720 1 1310 2016-04-04 111.2455 111.2390
91-
68130: 2016-04-04 21:51:00 ts ets MNN 720 1 1311 2016-04-04 111.2510 111.2455
92-
68131: 2016-04-04 21:52:00 ts ets MNN 720 1 1312 2016-04-04 111.2435 111.2510
93-
68132: 2016-04-04 21:53:00 ts ets MNN 720 1 1313 2016-04-04 111.2505 111.2435
99+
[1] 26876
94100

95101
$`840`
96-
index t_series model sub_model data_min fc_min part date mk.price fc.price
97-
1: 2016-01-04 00:02:00 ts ets MNN 840 1 1 2016-01-04 120.2200 120.2104
98-
2: 2016-01-04 00:03:00 ts ets MNN 840 1 2 2016-01-04 120.2200 120.2200
99-
3: 2016-01-04 00:04:00 ts ets MNN 840 1 3 2016-01-04 120.2185 120.2200
100-
4: 2016-01-04 00:05:00 ts ets MNN 840 1 4 2016-01-04 120.2195 120.2185
101-
5: 2016-01-04 00:06:00 ts ets MNN 840 1 5 2016-01-04 120.2250 120.2195
102-
---
103-
45802: 2016-02-15 19:25:00 ts ets MNN 840 1 1164 2016-02-15 114.6500 114.6445
104-
45803: 2016-02-15 19:26:00 ts ets MNN 840 1 1165 2016-02-15 114.6515 114.6500
105-
45804: 2016-02-15 19:27:00 ts ets MNN 840 1 1166 2016-02-15 114.6575 114.6515
106-
45805: 2016-02-15 19:28:00 ts ets MNN 840 1 1167 2016-02-15 114.6675 114.6575
107-
45806: 2016-02-15 19:29:00 ts ets MNN 840 1 1168 2016-02-15 114.6675 114.6675
102+
[1] 53639
108103

109104
$`960`
110-
index t_series model sub_model data_min fc_min part date mk.price fc.price
111-
1: 2016-01-04 00:02:00 ts ets MNN 960 1 1 2016-01-04 120.2200 120.2104
112-
2: 2016-01-04 00:03:00 ts ets MNN 960 1 2 2016-01-04 120.2200 120.2200
113-
3: 2016-01-04 00:04:00 ts ets MNN 960 1 3 2016-01-04 120.2185 120.2200
114-
4: 2016-01-04 00:05:00 ts ets MNN 960 1 4 2016-01-04 120.2195 120.2185
115-
5: 2016-01-04 00:06:00 ts ets MNN 960 1 5 2016-01-04 120.2250 120.2195
116-
---
117-
44634: 2016-02-15 23:57:00 ts ets MNN 960 1 1436 2016-02-15 114.5940 114.6015
118-
44635: 2016-02-15 23:58:00 ts ets MNN 960 1 1437 2016-02-15 114.6050 114.5940
119-
44636: 2016-02-15 23:59:00 ts ets MNN 960 1 1438 2016-02-15 114.5950 114.6050
120-
44637: 2016-02-15 23:59:00 ts ets MNN 960 1 1439 2016-02-15 114.5950 114.6050
121-
44638: 2016-02-16 00:01:00 ts ets MNN 960 1 1440 2016-02-16 114.6040 114.5960
122-
123-
ldply(split(mds_ets_MNN_intraday2_1min_1y, mds_ets_MNN_intraday2_1min_1y$data_min), function(x) { unique(as.data.table(x), by = c('index')) }) %>% as.data.table
105+
[1] 51930
106+
107+
refill <- llply(split(mds_ets_MNN_intraday3_1min_1y, mds_ets_MNN_intraday3_1min_1y$data_min), function(x) {
108+
x <- as.data.table(x)
109+
y <- smmp$index[!unique(smmp$index) %in% unique(x$index)]
110+
y
111+
})
112+
113+
dte <- refill %>% llply(., function(x) unique(as_date(x)))
114+
#ts_ets_MNN_960_1.p_124.2016-12-28
115+
#ts_ets_MNN_840_1.p_473.2016-12-20
116+
#ts_ets_MNN_720_1.p_716.2016-15-05
117+
#ts_ets_MNN_600_1.p_791.2016-11-29
118+
119+
#########################################################################
120+
# --------- eval=FALSE ---------
121+
source('function/intra_min.R')
122+
123+
smmp <- dsmp[374401:748800]
124+
timeID <- unique(smmp$date)
125+
bse <- smmp[year == 2016]$date[1] #"2016-01-04" #1st trading date in 2nd year
126+
timeID %<>% .[. >= bse]
127+
#timeID %<>% .[. >= as_date('2016-12-12')]
128+
#timeID %<>% .[. <= as_date('2016-01-31')]
129+
timeID <- dte$`600`
130+
data_len <- 600
131+
hrz1 <- 1
132+
intr <- data_len/hrz1
133+
134+
llply(ets.m, function(md) {
135+
intra_min(timeID = timeID, smmp, fl_pth = 'C:/Users/User/Desktop/intraday_refill',
136+
data_len = data_len, hrz1 = hrz1,
137+
.model = md, vb = FALSE)
138+
})
139+
140+
#########################################################################
141+
# --------- eval=FALSE ---------
142+
source('function/intra_min.R')
143+
144+
smmp <- dsmp[374401:748800]
145+
timeID <- unique(smmp$date)
146+
bse <- smmp[year == 2016]$date[1] #"2016-01-04" #1st trading date in 2nd year
147+
timeID %<>% .[. >= bse]
148+
#timeID %<>% .[. >= as_date('2016-12-12')]
149+
#timeID %<>% .[. <= as_date('2016-01-31')]
150+
timeID <- dte$`720`
151+
data_len <- 720
152+
hrz1 <- 1
153+
intr <- data_len/hrz1
154+
155+
llply(ets.m, function(md) {
156+
intra_min(timeID = timeID, smmp, fl_pth = 'C:/Users/User/Desktop/intraday_refill',
157+
data_len = data_len, hrz1 = hrz1,
158+
.model = md, vb = FALSE)
159+
})
160+
161+
#########################################################################
162+
# --------- eval=FALSE ---------
163+
source('function/intra_min.R')
164+
165+
smmp <- dsmp[374401:748800]
166+
timeID <- unique(smmp$date)
167+
bse <- smmp[year == 2016]$date[1] #"2016-01-04" #1st trading date in 2nd year
168+
timeID %<>% .[. >= bse]
169+
#timeID %<>% .[. >= as_date('2016-12-12')]
170+
#timeID %<>% .[. <= as_date('2016-01-31')]
171+
timeID <- dte$`840`
172+
data_len <- 840
173+
hrz1 <- 1
174+
intr <- data_len/hrz1
175+
176+
llply(ets.m, function(md) {
177+
intra_min(timeID = timeID, smmp, fl_pth = 'C:/Users/User/Desktop/intraday_refill',
178+
data_len = data_len, hrz1 = hrz1,
179+
.model = md, vb = FALSE)
180+
})
181+
182+
#########################################################################
183+
# --------- eval=FALSE ---------
184+
source('function/intra_min.R')
185+
186+
smmp <- dsmp[374401:748800]
187+
timeID <- unique(smmp$date)
188+
bse <- smmp[year == 2016]$date[1] #"2016-01-04" #1st trading date in 2nd year
189+
timeID %<>% .[. >= bse]
190+
#timeID %<>% .[. >= as_date('2016-12-12')]
191+
#timeID %<>% .[. <= as_date('2016-01-31')]
192+
timeID <- dte$`960`
193+
data_len <- 960
194+
hrz1 <- 1
195+
intr <- data_len/hrz1
196+
197+
llply(ets.m, function(md) {
198+
intra_min(timeID = timeID, smmp, fl_pth = 'C:/Users/User/Desktop/intraday_refill',
199+
data_len = data_len, hrz1 = hrz1,
200+
.model = md, vb = FALSE)
201+
})
202+
124203

125204

126205

rsconnect/documents/binary-Q1Inter-HFT-RV2.Rmd/beta.rstudioconnect.com/englianhu/binary-q1inter-hft-rv2.dcf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ account: englianhu
55
server: beta.rstudioconnect.com
66
hostUrl: https://beta.rstudioconnect.com/__api__
77
appId: 16442
8-
bundleId: 47079
8+
bundleId: 47425
99
url: https://beta.rstudioconnect.com/content/8a7cbdce-6fc5-409b-8072-9ff21dbd32eb/
10-
when: 1618478460.35509
10+
when: 1618839369.33503
1111
asMultiple: FALSE
1212
asStatic: TRUE

rsconnect/documents/binary-Q1Inter-HFT-RV2.Rmd/rpubs.com/rpubs/Publish Document.dcf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ hostUrl: rpubs.com
77
appId: https://api.rpubs.com/api/v1/document/742275/86dad6194f1648c5b88552c75a2c1d15
88
bundleId: https://api.rpubs.com/api/v1/document/742275/86dad6194f1648c5b88552c75a2c1d15
99
url: http://rpubs.com/englianhu/742275
10-
when: 1618478378.89744
10+
when: 1618839327.48489

0 commit comments

Comments
 (0)